All Questions

Tagged with
Filter by
Sorted by
Tagged with
81 votes
9 answers
251k views

How to import keras from tf.keras in Tensorflow?

import tensorflow as tf import tensorflow from tensorflow import keras from keras.layers import Dense I am getting the below error from keras.layers import Input, Dense Traceback (most recent call ...
GeorgeOfTheRF's user avatar
46 votes
4 answers
96k views

Running the Tensorflow 2.0 code gives 'ValueError: tf.function-decorated function tried to create variables on non-first call'. What am I doing wrong?

error_giving_notebook non_problematic_notebook As it can be seen that I have used tf.function decorator in the 'error_giving_notebook' and it throws a ValueError while the same notebook without any ...
Gaurav Singh's user avatar
36 votes
2 answers
6k views

Custom TensorFlow Keras optimizer

Suppose I want to write a custom optimizer class that conforms to the tf.keras API (using TensorFlow version>=2.0). I am confused about the documented way to do this versus what's done in ...
Artem Mavrin's user avatar
28 votes
4 answers
26k views

Save model every 10 epochs tensorflow.keras v2

I'm using keras defined as submodule in tensorflow v2. I'm training my model using fit_generator() method. I want to save my model every 10 epochs. How can I achieve this? In Keras (not as a ...
Nagabhushan S N's user avatar
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 ...
Deshwal's user avatar
  • 3,862
14 votes
2 answers
5k views

Why in Keras subclassing API, the call method is never called and as an alternative the input is passed by calling the object of this class?

When creating a model using Keras subclassing API, we write a custom model class and define a function named call(self, x)(mostly to write the forward pass) which expects an input. However, this ...
Atul's user avatar
  • 648
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 ...
Rahul Anand's user avatar
12 votes
1 answer
13k views

"TypeError: can't pickle weakref objects" when pickling a deep learning model

When I run pickle.dump(model,open('modelDL.pkl','wb')) I get TypeError: can't pickle weakref objects I have a created a deep learning model which I am trying to save. The model: model = Sequential() ...
Dibyaranjan Jena's user avatar
10 votes
1 answer
30k views

ImportError: cannot import name 'keras_tensor' from 'tensorflow.python.keras.engine'

I'm getting this error while loading the tensorflow addons library import tensorflow_addons as tfa ImportError: cannot import name 'keras_tensor' from 'tensorflow.python.keras.engine'
dpacman's user avatar
  • 3,801
9 votes
2 answers
16k views

Decay parameter of Adam optimizer in Keras

I think that Adam optimizer is designed such that it automtically adjusts the learning rate. But there is an option to explicitly mention the decay in the Adam parameter options in Keras. I want to ...
Arjun's user avatar
  • 127
9 votes
1 answer
7k views

How does Tensorflow calculate the accuracy of model?

I am following this tutorial for binary class classification. While defining the model it is defined as follows and quotes: Apply a tf.keras.layers.Dense layer to convert these features into a ...
Gambitier's user avatar
  • 570
8 votes
1 answer
744 views

TF2.1: SegNet model architecture problem. Bug with metric calculation, keeps constant and converge to determined value

I'm building a custom model (SegNet) in Tensorflow 2.1.0. The first problem I'm facing is the reutilization of the indices of the max pooling operation needed as described in the paper. Basically, ...
rpasianotto's user avatar
  • 1,403
7 votes
2 answers
3k views

Weighting samples in multiclass image segmentation using keras

I am using a Unet based model to perform image segmentation on a biomedical image. Each image is 224x224 and I have four classes including the background class. Each mask is sized as (224x224x4) and ...
maracuja's user avatar
  • 427
6 votes
2 answers
9k views

List of metrics that can be passed to tf.keras.model.compile

Based on the tensorflow documentation, when compiling a model, I can specify one or more metrics to use, such as 'accuracy' and 'mse'. However, the documentation doesn't say what metrics are ...
usernumber's user avatar
  • 2,077
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 ...
Darien Schettler's user avatar
6 votes
2 answers
2k views

Keras Autoencoder: Tying Weights from Encoder To Decoder not working

Im creating an Autoencoder as part of my full model for a Kaggle competition. Im trying to tie the weighs of the Encoder, transposed to the Decoder. Before the first Epoch the weights are correctly ...
ElPapi42's user avatar
  • 514
5 votes
3 answers
15k views

Keras: fix "IndexError: list index out of range" error when using model.fit

I'm trying to build a Variational Autoencoder with several Conv2d layers that works with cifar-10. It seems all right, but when I run the training I get this error: Train on 50000 samples, validate ...
Daniele's user avatar
  • 51
5 votes
1 answer
2k views

Keras evaluate the validation data before the epoch ends

I'm want to train my model with Keras. I'm using a huge dataset Where one training epoch has more than 30000 steps. My problem is that I don't want to wait for an epoch before checking the model ...
Jude TCHAYE's user avatar
5 votes
1 answer
1k views

Knowledge Distillation loss with Tensorflow 2 + Keras

I am trying to implement a very simple keras model that uses Knowledge Distillation [1] from another model. Roughly, I need to replace the original loss L(y_true, y_pred) by L(y_true, y_pred)+L(...
ThR37's user avatar
  • 4,015
5 votes
1 answer
3k views

TypeError: 'Not JSON Serializable' while doing tf.keras.Model.save and using keras variable in loss_weights in tf.keras.Model.compile

System information    OS Platform and Distribution: Ubuntu 16.04 LTS   TensorFlow installed from (source or binary): binary   TensorFlow version (use command below): 1.12.0   Python version: 3.5.2 ...
tejal567's user avatar
  • 119
5 votes
0 answers
49 views

Concatenating two saved models in tensorflow 1.13 [duplicate]

I've a pretrained model saved as ckpt files (meta, index ...) and I'm loading the graph using tf.train.import_meta_graph() and tf.train.Saver.restore(). I also have a resnet50 model from tf.keras....
Nagabhushan S N's user avatar
4 votes
2 answers
2k views

How to stack Convolutional Layer and LSTM using Tensorflow2.0 alpha?

I am trying to implement a neural network for an NLP task with a convolutional layer followed up by an LSTM layer. I am currently experimenting with the new Tensorflow 2.0 to do this. However, when ...
Imperator123's user avatar
4 votes
1 answer
5k views

Adding custom metric Keras Subclassing API

I'm following the section "Losses and Metrics Based on Model Internals" on chapter 12 of "Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow, 2nd Edition - Aurélien Geron", in which he ...
PHAN's user avatar
  • 303
4 votes
1 answer
2k views

Validation loss is zero on first epoch only

Problem I am trying to build a regression model in tensorflow using the dataset and keras API's. The target contains quite a lot of zero's and the non-zero values are roughly distributed normally ...
M. Ungheretti's user avatar
4 votes
0 answers
334 views

Reading Validation-Dataset takes indefinitely long

I've got a custom TensorFlow Dataset and my problem is , that my Validation Dataset is loading indefinitely, if i try to access the first item. So next(iter(train_ds.take(1))) returns the first ...
user7354365's user avatar
4 votes
1 answer
1k views

tf.data or tf.keras.utils.Sequence. Improving efficiency of tf.data?

I am trying to develop an image colorizer using autoencoders. There are 13000 training images. Each epoch takes about 45 minutes if I use tf.data and about 25 minutes if I use tf.utils.keras.Sequence. ...
AVN's user avatar
  • 63
4 votes
1 answer
2k views

Elastic Weight Consolidation Algorithm Implementation in Keras

I am working on an LSTM based model to predict logs-anomaly. My model architecture is as given: ______________________Layer (type) Output Shape Param # ================================================...
Sayan Dey's user avatar
  • 807
3 votes
3 answers
19k views

Unknown metric function: Please ensure this object is passed to the `custom_objects` argument

I have trained a model with keras using transfer learning. since the whole code is almost big i only bring important parts. For learning rate I cloned from github some code to be able to use cyclic ...
maryam gh's user avatar
  • 193
3 votes
2 answers
24k views

Got ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor

When I tried to run a colab notebook on 2021 June, which was created on 2020 december and ran fine I got an error. So I changed baseModel = tf.keras.applications.VGG16(weights="imagenet", ...
Ayesh17's user avatar
  • 153
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(...
Artem Mavrin's user avatar
3 votes
2 answers
764 views

How to get rid of the _N for Keras metric names?

I am using the "tensorflow" keras. ie. i did: from tensorflow import keras from tensorflow.keras import layers Not sure if this is different from Keras with TF as backend. I am on TF 1.14.0 and ...
kawingkelvin's user avatar
  • 3,769
3 votes
1 answer
306 views

tensorflow 2.0, when calling the function two variables given, but, when defining the function, there is no variables

I was following the tutorial in tensorflow-2.0. When defining the generator, there were no variables given, but when calling the function, there are two variables are given. def generator_model(): ...
qinlong's user avatar
  • 731
3 votes
2 answers
1k views

Tensorflow 1.15 / Keras 2.3.1 Model.train_on_batch() returns more values than there are outputs/loss functions

I am trying to train a model that has more than one output and as a result, also has more than one loss function attached to it when I compile it. I haven't done something similar in the past (not ...
djvaroli's user avatar
  • 1,283
3 votes
1 answer
1k views

why does tensorboard give this error: InvalidArgumentError: Nan in summary histogram for

I built the model to classification using 1D convolution layers using tf.Keras .this works well if I remove the tensorboard.As I'm a beginner,I can't figure it out what the problem is. Please help %...
Dhanushka Sandaruwan's user avatar
3 votes
1 answer
168 views

Trying to use previously trained tf.keras model as pretraining, but getting "ValueError: Input 0 of layer dense_3 is incompatible with the laye

I created and trained a model to classify beer names from invoice strings encoded as integer sequences from characters. batch_size = 512 # Batch size for training. epochs = 5 # Number of epochs ...
orionthunter's user avatar
3 votes
0 answers
894 views

LSTM for imbalanced time series classification

I wanted to fit simple LSTM model to perform binary classification on multivariate time series data. Since my data is severely imbalanced, I have integrated class_weight argument from sklearn in my ...
ForestGump's user avatar
3 votes
1 answer
485 views

validation and train metrics very low values (images and masks generator)

I have images(X_train) and masks data (y_train). I want to train a unet network. I am currently using iou metric and the validation iou is very low and constant! I am not sure if I can handle right ...
George's user avatar
  • 5,511
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 ...
user avatar
3 votes
0 answers
952 views

In the TensorFlow Keras API, how can I add parameters to the csv file created by CSVLogger callback?

How can I create a TensorFlow Keras API callback that, for every epoch, will add the learning rate value to the csv file created by tf.keras.callbacks.CSVLogger? With the callback below I can print ...
mattroos's user avatar
  • 125
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....
Artem Mavrin's user avatar
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))...
Maurus Kühne's user avatar
3 votes
2 answers
8k views

How to use model.predict for predicting single image in tf.keras

I am trying to predict a single image using the trained model either I am getting an array of 80 values or I am getting this error: dimension Matrix size-incompatible: In[0]: [1,19200], In[1]: [240,...
user1830648's user avatar
2 votes
2 answers
15k views

No module named 'tensorflow.python.keras.engine.base_layer_v1' in python code with tensor flow keras

hi i'm doing this code in google colab and i have this error No module named 'tensorflow.python.keras.engine.base_layer_v1' in python code with tensor flow keras i did use tensorflow.keras instead of ...
FaisalAlsalm's user avatar
2 votes
2 answers
8k views

Good performance with Accuracy but not with Dice loss in Image Segmentation

I'm doing image segmentation with U-Net like architecture on Tensorflow w/Keras but I'm new in Deep Learning. I've got this dataset with the following set shapes: Train : X : (175250, 30, 30, 6) Y: (...
Bruno Miguel Gonçalves's user avatar
2 votes
1 answer
2k views

TensorFlow 2.0 'build' function

I was reading about creating neural networks using TensorFlow 2.0 in conjunction with 'GradientTape' API and came across the following code: model = tf.keras.Sequential(( tf.keras.layers.Reshape(...
Arun's user avatar
  • 2,330
2 votes
1 answer
597 views

keras vs. tensorflow.keras

Inspired by this post. Why is there a difference between the 2 modules? When would I use one over the other? Anything else I should know?
DanielBell99's user avatar
  • 1,301
2 votes
2 answers
1k views

TensorFlow 2.0 - Model subclassing : no input dimension

I was reading the TensorFlow 2.0 Tutorial and I came across model subclassing to create TensorFlow 2.0 models. The code I found was: class MyModel(Model): def __init__(self): super(MyModel, ...
Arun's user avatar
  • 2,330
2 votes
1 answer
2k views

converting tf.data.Dataset.from_tensor_slices to pytorch

I am trying to convert this model from tensorflow to pytorch. Unfortunately, I don't know tensorflow very well. I have a problem transferring ti data_loader from here and in general converting this ...
Dalek's user avatar
  • 4,268
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 ...
sikisis's user avatar
  • 468
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 ...
Artem Mavrin's user avatar

1
2 3 4 5 6