All Questions
Tagged with tf.keras machine-learning
196
questions
26
votes
2
answers
17k
views
Keras - Validation Loss and Accuracy stuck at 0
I am trying to train a simple 2 layer Fully Connected neural net for Binary Classification in Tensorflow keras. I have split my data into Training and Validation sets with a 80-20 split using sklearn'...
15
votes
1
answer
4k
views
Is it meaningless to use ReduceLROnPlateau with Adam optimizer?
This question is basically for the working of Keras or tf.keras for people who have the verty deep knowledge of the framework
According to my knowledge, tf.keras.optimizers.Adam is an optimizer which ...
13
votes
8
answers
14k
views
"UserWarning: An input could not be retrieved. It could be because a worker has died. We do not have any information on the lost sample."
While training model I got this warning "UserWarning: An input could not be retrieved. It could be because a worker has died.We do not have any information on the lost sample.)", after showing this ...
12
votes
1
answer
12k
views
How to use sample weights with tensorflow datasets?
I have been training a unet model for multiclass semantic segmentation in python using Tensorflow and Tensorflow Datasets.
I've noticed that one of my classes seems to be underrepresented in training. ...
8
votes
5
answers
9k
views
How do I calculate the matthews correlation coefficient in tensorflow
So I made a model with tensorflow keras and it seems to work ok. However, my supervisor said it would be useful to calculate the Matthews correlation coefficient, as well as the accuracy and loss it ...
7
votes
1
answer
17k
views
ValueError: No gradients provided for any variable - Tensorflow 2.0/Keras
I am trying to implement a simple sequence-to-sequence model using Keras. However, I keep seeing the following ValueError:
ValueError: No gradients provided for any variable: ['simple_model/...
7
votes
1
answer
21k
views
Unable to train my keras model : (Data cardinality is ambiguous:)
I am using the bert-for-tf2 library to do a Multi-Class Classification problem. I created the model but training throws the following error:
-----------------------------------------------------------...
6
votes
1
answer
6k
views
Tensorflow 2.1.0 - An op outside of the function building code is being passed a "Graph" tensor
I am trying to implement a recent paper. Part of this implementation involves moving from tf 1.14 to tf 2.1.0. The code was working with tf 1.14 but is no longer working.
NOTE: If I disable eager ...
5
votes
1
answer
2k
views
Keras custom metrics self.validation_data is none , when using data generators
I have been trying to train a model and calculate precision and recall at the end of each epoch.
The custom metric
class Metrics(keras.callbacks.Callback):
def on_train_begin(self, logs={}):
...
5
votes
2
answers
217
views
scikeras.wrappers.KerasClassifier returning ValueError: Could not interpret metric identifier: loss
I was looking into KerasClassifier, as I would like to plug it in a scikit-learn pipeline, but I'm getting the aforementioned ValueError.
The following code should be able to reproduce the error I'm ...
4
votes
3
answers
1k
views
Implementing a trainable generalized Bump function layer in Keras/Tensorflow
I'm trying to code the following variant of the Bump function, applied component-wise:
,
where σ is trainable; but it's not working (errors reported below).
My attempt:
Here's what I've coded up ...
4
votes
1
answer
2k
views
Tensorflow saving subclass model which has multiple arguments to call() method
I am following the tensorflow neural machine translation tutorial:
https://www.tensorflow.org/tutorials/text/nmt_with_attention
I am trying to save the Encoder and Decoder models which are subclasses ...
4
votes
2
answers
5k
views
tf.keras loss becomes NaN
I'm programming a neural network in tf.keras, with 3 layers. My dataset is the MNIST dataset. I decreased the number of examples in the dataset, so the runtime is lower. This is my code:
import ...
4
votes
1
answer
195
views
Can I change the statefulness of RNN after training?
If I build and train my RNN based model with stateful=False, can I simply do (e.g.):
model.layers[0].stateful = True
And have it take effect as might be expected for use in prediction? I ask ...
3
votes
1
answer
3k
views
How to make custom validation_step in tensorflow 2 Tensorflow 2 / Keras?
I have a question regarding the validation Data.
I have this neural network and I divided my data into train_generator, val_generator, test_generator.
I made a custom model with a custom fit.
class ...
3
votes
1
answer
2k
views
How to do atrous convolution in tensorflow 2 (tf.keras)
I am trying to convert some code from tensorflow 1.x to tensorflow 2.x.
It's been going well so far, but I'm stuck on atrous convolution. Unlike other layers, there doesn't seem to be a one-to-one ...
3
votes
1
answer
708
views
TensorFlow Keras 'accuracy' metric under the hood implementation
When building a classifier using TensorFlow Keras, one often monitors model accuracy by specifying metrics=['accuracy'] during the compilation step:
model = tf.keras.Model(...)
model.compile(...
3
votes
2
answers
5k
views
How to fix error where a KerasTensor is passed to a TF API?
I've downloaded code for a Wasserstein GAN with Gradient Policy (WGAN-GP) from Keras-GAN (GitHub). Some of the imports appeared to be of outdated syntax, as I was getting errors and they were based on ...
3
votes
1
answer
3k
views
TensorFlow/Keras Using specific class recall as metric for Sparse Categorical Cross Entropy
*Update at bottom
I am trying to use recall on 2 of 3 classes as a metric, so class B and C from classes A,B,C.
(The original nature of this is that my model is highly imbalanced in the classes [~90% ...
3
votes
2
answers
13k
views
Adding a rescaling layer (or any layer for that matter) to a trained tensorflow keras model
I have a tensorflow keras model trained with tensorflow 2.3. The model takes as input an image, however the model was trained with scaled inputs and therefore we have to scale the image by 255 before ...
3
votes
2
answers
3k
views
How to get loss gradient wrt internal layer output in tensorflow 2?
I would like to get gradient of the model's loss function with respect to specific layer's output during training. What I want to do with it next, is using a value of that gradient to modify something ...
3
votes
1
answer
3k
views
Exponential decay learning rate parameters of Adam optimizer in Keras
Consider the following information:
initial learning rate: 0.0002
decay coefficient: 0.7
ephocs: 70
My problem is to choose the decay step in such a way that the decay occurs every two epochs. How ...
3
votes
3
answers
1k
views
How to overfit data with Keras?
I'm trying to build a simple regression model using keras and tensorflow. In my problem I have data in the form (x, y), where x and y are simply numbers. I'd like to build a keras model in order to ...
3
votes
1
answer
634
views
Use generator in TensorFlow/Keras to fit when the model gets 2 inputs
I want to train a model that uses an extra output layer to compute the loss (ArcFace) so the model gets two inputs: the features and the true label: [X, y].
So far I did with the all data loaded at ...
3
votes
0
answers
141
views
Tensorflow Keras with multiple inputs improving accuracy and using estimators?
I'm working on creating a surrogate model for some abaqus models base on Aluminum testing. I have 5 input parameters and 1 output parameter. I have 1000 rows of data for training and 20 rows of data ...
3
votes
0
answers
277
views
Why is my GAN not producing more good images after a certain point?
Question
I was training a gan to generate human faces. Within approximately 500 epochs, it learned to generate images like this:
Well, now this image is not too bad. We can see a face in the center ...
3
votes
0
answers
886
views
tf. keras fit_generator() gets stuck on validation_data
I am using the DataGenerator form tf.keras.Sequence to load my data in batches. The datagenerator returns numpy arrays of images and masks. When I call fit_generator(), it looks like the model fits ...
3
votes
0
answers
191
views
More elegant way of displaying distributions and activations in TensorBoard
Keras's Tensorboard callback has a write_images and a histogram_freq argument that allows the weights and activations to be saved to Tensorboard to visualize during training.
The issue is, this saves ...
3
votes
0
answers
2k
views
Clipping gradients by global norm using the TensorFlow Keras API
Gradient clipping is one solution to the exploding gradient problem in deep learning. The tf.keras API allows users to use a variation of gradient clipping by passing clipnorm or clipvalue to any tf....
3
votes
1
answer
1k
views
"Unknown graph" error when using keras application model with tf.functions
This is my code:
import tensorflow as tf
import tensorflow_datasets as tfds
import tensorflow.keras.applications.vgg16 as vgg16
tf.enable_eager_execution()
def resize_image(image, shape = (224,224))...
3
votes
0
answers
139
views
Learning the loss weights as they were parameters
As far as I can understand, loss_weights parameter on compile function is used to define how much each of the model output loss contributes to the final loss value.
My question is: Is there a way to ...
2
votes
2
answers
5k
views
error Node: 'binary_crossentropy/Cast' Cast string to float is not supported while train model
i want to train my data i already make my data to string with word2vec pretrain model from here https://dl.fbaipublicfiles.com/fasttext/vectors-crawl/cc.id.300.vec.gz and success to make a model, but ...
2
votes
1
answer
1k
views
keras ImageDataGenerator without data augmentation?
My question is how to make a image generator in keras without any augmentation. I would like to create training and validation generator, in order to pass this to model.fit_generator, because the size ...
2
votes
1
answer
745
views
AttributeError: module 'tensorflow_docs' has no attribute 'plots'
I get some errors when I run the code in this tutorial by Google.
when I run the following piece of code:
plotter = tfdocs.plots.HistoryPlotter(metric = 'binary_crossentropy', smoothing_std=10)
...
2
votes
1
answer
152
views
Regularization of over-excited activation values in Tensorflow 2.0 Keras
For a specific problem I want to regularize over-excited activations of a layer in my Keras model. Therefore I created a custom-loss that is based on the amount of activation values that are higher ...
2
votes
2
answers
1k
views
Understanding tf.keras.metrics.Precision and Recall for multiclass classification
I am building a model for a multiclass classification problem. So I want to evaluate the model performance using the Recall and Precision.
I have 4 classes in the dataset and it is provided in one hot ...
2
votes
1
answer
862
views
What is the connections between two stacked LSTM layers?
The question is like this one What's the input of each LSTM layer in a stacked LSTM network?, but more into implementing details.
For simplicity how about 4 units and 2 units structures like the ...
2
votes
2
answers
3k
views
TensorFlow Keras CuDNNGRU to GRU conversion
I have a trained model built in TensorFlow 1.14 using the (now-deprecated) tf.keras.layers.CuDNNGRU layer (available in TensorFlow 2.0 in tf.compat.v1), and I am trying to port the old layer's weights ...
2
votes
1
answer
488
views
Multi input CNN in Tensorflow 2.0 not doing anything
I am trying to develop a multi input CNN, following the architecture I read on Multi-Input Convolutional Neural Network for Flower Grading.
I have a csv file where the value for each data item is ...
2
votes
1
answer
2k
views
Keras SimpleRNN
I'm trying to do Keras classification. I have 1043 words, represented as one-hot encoded matrices (20 letters long by 26 possibilities for each letter). Each one belongs to one of 19 different ...
2
votes
1
answer
250
views
WHY tf.keras.layers.Conv2D gives different results at each run
I am trying to reproduce my code from online Jupyter Notebook (COURSERA) to my own local environment (Anaconda 3 Jupyter with CUDA installed)
All Codes are exactly same, and was working fine online
I ...
2
votes
1
answer
684
views
Espresso exception: "Invalid argument":general shape kernel while loading mlmodel
I converted my mlmodel from tf.keras. The goal is to recognize handwritten text from the image
When I run it using this code:
func performCoreMLImageRecognition(_ image: UIImage) {
let ...
2
votes
1
answer
2k
views
How to save and restore a mode's weights with tf.keras.Model - TensorFlow 2.0 - Subclassing API
In the examples here it mentions that one can subclass the class tf.keras.Model as follows:
class MyModel(tf.keras.Model):
def __init__(self):
super(MyModel, self).__init__()
self....
2
votes
1
answer
179
views
Upon prediction, my loaded model is giving me an AttributeError
I'm fairly new to Tensorflow and Machine Learning in general but I know enough that I've built a small model. Although, when loaded and I use model.predict, I get an attribute error:
import ...
2
votes
1
answer
271
views
My fit function is breaking after running the first epoch [duplicate]
I am new to ML so please go easy on me, I might be missing something simple but such is the case with programming in general.
I did a course on Freecodecamp.com for Machine Learning in Python and I'm ...
2
votes
1
answer
3k
views
ValueError: Dimensions must be equal, but are 68 and 10 for '{{node mean_squared_error/SquaredDifference}} = SquaredDifference[T=DT_FLOAT]
I am using a LSTM and a VNN to convert active text to passive text. I am feeding in tokenized data to the lstm and getting a feature vector of shape (68,1) and I am then using that as input data for a ...
2
votes
1
answer
1k
views
Can't save a keras model after training my model
I'm following a code example from keras.io about A Vision Transformer without Attention, here. I want to save it in the tensorflow/keras after completing training but it generates an error. The last ...
2
votes
1
answer
466
views
Evaluating pairwise distances between the output of a tf.keras.model
I am trying to create a custom loss function in tensorflow. I am using tensorflow v2.0.rc0 for running the code. Following is the code and the function min_dist_loss computes the pairwise loss between ...
2
votes
1
answer
3k
views
tf.keras predictions are bad while evaluation is good
I'm programming a model in tf.keras, and running model.evaluate() on the training set usually yields ~96% accuracy. My evaluation on the test set is usually close, about 93%. However, when I predict ...
2
votes
0
answers
258
views
How to use multiple image datasets as inputs and outputs for the Keras network?
At the moment I'm trying to join a dataset that is scattered through different folders into one, this dataset have no labels as this is an autoencoder-like application. The code at the moment is ...