Questions tagged [tf.keras]

[tf.keras] is TensorFlow's implementation of the Keras API specification. Use the tag for questions specific to this TensorFlow module. You might also add the tag [keras] to your question since it has the same API.

is TensorFlow's implementation of the Keras API specification. Use the tag for questions specific to this TensorFlow module. You might also add the -tag to your question since it has the same API.

gives you the power and flexibility of Keras within TensorFlow (see the docs with a lot of examples). The API of is described here

1494 questions
12
votes
7 answers

"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 warning, model starts training. What does this…
Rahul Anand
  • 369
  • 1
  • 2
  • 14
11
votes
1 answer

How to make custom loss with extra input in tensorflow 2.0

I'm having a lot of trouble getting a custom loss function with an extra argument to work in TF 2.0 using tf.keras and a dataset. In the following case, the extra argument is the input data into the model, which is contained in a Dataset. In 1.14…
Luke
  • 5,052
  • 9
  • 39
  • 68
11
votes
3 answers

What is the difference between keras and tf.keras?

I'm learning TensorFlow and Keras. I'd like to try https://www.amazon.com/Deep-Learning-Python-Francois-Chollet/dp/1617294438/, and it seems to be written in Keras. Would it be fairly straightforward to convert code to tf.keras? I'm not more…
eugene
  • 33,301
  • 47
  • 188
  • 382
10
votes
2 answers

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 method is never called and instead of passing the…
Atul
  • 438
  • 4
  • 9
10
votes
3 answers

Tensorflow 2: how to switch execution from GPU to CPU and back?

In tensorflow 1.X with standalone keras 2.X, I used to switch between training on GPU, and running inference on CPU (much faster for some reason for my RNN models) with the following snippet: keras.backend.clear_session() def set_session(gpus: int…
valend.in
  • 153
  • 1
  • 1
  • 8
10
votes
3 answers

Tensorflow==2.0.0a0 - AttributeError: module 'tensorflow' has no attribute 'global_variables_initializer'

I'm using Tensorflow==2.0.0a0 and want to run the following script: import tensorflow as tf import tensorboard import pandas as pd import matplotlib.pyplot as plt import numpy as np import tensorflow_probability as tfp from…
razimbres
  • 3,430
  • 3
  • 17
  • 37
9
votes
1 answer

Input pipeline w/ keras.utils.Sequence object or tf.data.Dataset?

I am currently using a tf.keras.utils.Sequence object to generate image batches for a CNN. I am using Tensorflow 2.2 and the Model.fit method for the model. When I fit the model, the following warning is thrown in each epoch when I set…
Connor
  • 197
  • 1
  • 8
9
votes
0 answers

Most scalable way for using generators with tf.data ? tf.data guide says `from_generator` has limited scalability

tf.data has a from_generator initializer, it doesn't seem like it's scalable. From the official guide Caution: While this is a convienient approach it has limited portability and scalibility. It must run in the same python process that created…
SantoshGupta7
  • 4,211
  • 4
  • 31
  • 64
9
votes
0 answers

Tensorflow 2.0: Accessing a batch's tensors from a callback

I'm using Tensorflow 2.0 and trying to write a tf.keras.callbacks.Callback that reads both the inputs and outputs of my model for the batch. I expected to be able to override on_batch_end and access model.inputs and model.outputs but they are not…
francoisr
  • 3,812
  • 1
  • 24
  • 44
9
votes
4 answers

In TensorFlow 2.0 with eager-execution, how to compute the gradients of a network output wrt a specific layer?

I have a network made with InceptionNet, and for an input sample bx, I want to compute the gradients of the model output w.r.t. the hidden layer. I have the following code: bx = tf.reshape(x_batch[0, :, :, :], (1, 299, 299, 3)) with…
Vahid Mirjalili
  • 5,363
  • 15
  • 47
  • 73
9
votes
5 answers

How to save/restore large model in tensorflow 2.0 w/ keras?

I have a large custom model made with the new tensorflow 2.0 and mixing keras and tensorflow. I want to save it (architecture and weights). Exact command to reproduce: import tensorflow as tf OUTPUT_CHANNELS = 3 def downsample(filters, size,…
Ridane
  • 91
  • 1
  • 6
9
votes
0 answers

Why does tf.keras model.fit() initialize take so long? How can it be optimized?

Using tensorflow.keras (2.0-alpha0 with GPU support) I have extremely long initialize times with tf.keras.model.fit() on both newly compiled models and models previously saved and reloaded. I believe this is after the tf.data.Datasets() have…
kerasbaz
  • 1,548
  • 1
  • 3
  • 11
8
votes
1 answer

Saving and loading multiple models with the same graph in TensorFlow Functional API

In the TensorFlow Functional API guide, there's an example shown where multiple models are created using the same graph of layers.…
mpotma
  • 243
  • 1
  • 7
8
votes
1 answer

Tensorflow: Modern way to load large data

I want to train a convolutional neural network (using tf.keras from Tensorflow version 1.13) using numpy arrays as input data. The training data (which I currently store in a single >30GB '.npz' file) does not fit in RAM all at once. What is the…
Adomas Baliuka
  • 673
  • 1
  • 7
  • 25
8
votes
1 answer

keras fit_generator: 'zip' object has no attribute 'shape'

as in keras documentation in the (image, mask) data generator, I created data generator to have (input, output) tuple images. When running locally on my laptop (with tensorflow 1.13.1), it runs with no issues, but when running on a server (with…
Yael N
  • 81
  • 8