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 for examples). The API of is described here.

References:

2208 questions
17
votes
1 answer

RNN in Tensorflow vs Keras, depreciation of tf.nn.dynamic_rnn()

My question is: Are the tf.nn.dynamic_rnn and keras.layers.RNN(cell) truly identical as stated in docs? I am planning on building an RNN, however, it seems that tf.nn.dynamic_rnn is depricated in favour of Keras. In particular, it states…
GRS
  • 2,807
  • 4
  • 34
  • 72
16
votes
3 answers

tf.data.Dataset iterator returning Tensor("IteratorGetNext:1", shape=(None, 16), dtype=int32) but cannot get the values of the Tensors

I am trying to write a Custom Model in which I am writing a custom train_step function I am creating a 'tf.data.Dataset` from a Custom Datagenerator like tds = tf.data.Dataset.from_generator(tdg.__iter__,args=None,output_types =…
Siladittya
  • 1,156
  • 2
  • 13
  • 41
14
votes
6 answers

InvalidArgumentError: required broadcastable shapes at loc(unknown)

Background I am totally new to Python and to machine learning. I just tried to set up a UNet from code I found on the internet and wanted to adapt it to the case I'm working on bit for bit. When trying to .fit the UNet to the training data, I…
Manuel Popp
  • 1,003
  • 1
  • 10
  • 33
14
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
  • 598
  • 5
  • 12
14
votes
1 answer

How to perform gradient accumulation WITH distributed training in TF 2.0 / 1.14.0-eager and custom training loop (gradient tape)?

Background: I have a model and I'm trying to port it to TF 2.0 to get some sweet eager execution, but I just can't seem to figure out how to do distributed training (4 GPU's) AND perform gradient accumulation at the same time. Problem: I need to be…
13
votes
1 answer

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
  • 5,607
  • 14
  • 58
  • 116
13
votes
7 answers

Keras that does not support TensorFlow 2.0. We recommend using `tf.keras`, or alternatively, downgrading to TensorFlow 1.14

I am having an error regarding (Keras that does not support TensorFlow 2.0. We recommend using tf.keras, or alternatively, downgrading to TensorFlow 1.14.) any recommendations. thanks import keras #For building the Neural Network layer by…
Dean
  • 199
  • 2
  • 4
  • 14
13
votes
8 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
  • 437
  • 1
  • 4
  • 15
13
votes
1 answer

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,774
  • 1
  • 6
  • 15
12
votes
1 answer

"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() model.add( Dense(30,activation='relu')…
12
votes
2 answers

TypeError: __init__() got an unexpected keyword argument 'name' when loading a model with Custom Layer

I made a custom layer in keras for reshaping the outputs of a CNN before feeding to ConvLSTM2D layer class TemporalReshape(Layer): def __init__(self,batch_size,num_patches): super(TemporalReshape,self).__init__() self.batch_size…
Siladittya
  • 1,156
  • 2
  • 13
  • 41
11
votes
1 answer

How do I save and load BatchNormalization Layer in this Tensorflow model?

I am trying to save a model and then load it later to make some predictions; what happens is that the accuracy of the model after training is 95%+, but when I save it and then load it, the accuracy drops to nearly 10% on the same dataset. To…
Ravish Jha
  • 481
  • 3
  • 25
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
  • 6,699
  • 13
  • 50
  • 88
11
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
  • 4,715
  • 5
  • 23
  • 50
10
votes
1 answer

Convert a KerasTensor object to a numpy array to visualize predictions in Callback

I am writing a custom on_train_end callback function for model.fit() method of tensorflow keras sequential model. The callback function is about plotting the predictions that the model makes, so it involves converting the inputs of the model to a…
Xi Liu
  • 559
  • 9
  • 18