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
79
votes
9 answers

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 last): File "",…
GeorgeOfTheRF
  • 8,244
  • 23
  • 57
  • 80
65
votes
4 answers

WARNING:tensorflow:sample_weight modes were coerced from ... to ['...']

Training an image classifier using .fit_generator() or .fit() and passing a dictionary to class_weight= as an argument. I never got errors in TF1.x but in 2.1 I get the following output when starting training: WARNING:tensorflow:sample_weight modes…
gosuto
  • 5,422
  • 6
  • 36
  • 57
57
votes
19 answers

How to fix "AttributeError: module 'tensorflow' has no attribute 'get_default_graph'"?

I am trying to run some code to create an LSTM model but i get an error: AttributeError: module 'tensorflow' has no attribute 'get_default_graph' My code is as follows: from keras.models import Sequential model = Sequential() model.add(Dense(32,…
Alice
  • 643
  • 1
  • 5
  • 7
43
votes
3 answers

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 changes except for removing the tf.function…
Gaurav Singh
  • 555
  • 1
  • 6
  • 9
36
votes
2 answers

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 implementations. The documentation for…
33
votes
3 answers

Should I use @tf.function for all functions?

An official tutorial on @tf.function says: To get peak performance and to make your model deployable anywhere, use tf.function to make graphs out of your programs. Thanks to AutoGraph, a surprising amount of Python code just works with …
29
votes
8 answers

model.summary() can't print output shape while using subclass model

This is the two methods for creating a keras model, but the output shapes of the summary results of the two methods are different. Obviously, the former prints more information and makes it easier to check the correctness of the network. import…
Gary
  • 823
  • 1
  • 8
  • 14
27
votes
4 answers

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 submodule of tf), I can give…
Nagabhushan S N
  • 6,407
  • 8
  • 44
  • 87
26
votes
2 answers

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's train_test_split(). When I call…
Animesh Sinha
  • 817
  • 2
  • 11
  • 24
24
votes
4 answers

What is meant by sequential model in Keras

I have recently started working Tensorflow for deep learning. I found this statement model = tf.keras.models.Sequential() bit different. I couldn't understand what is actually meant and is there any other models as well for deep learning? I worked …
Aadnan Farooq A
  • 626
  • 4
  • 8
  • 19
20
votes
5 answers

How to graph tf.keras model in Tensorflow-2.0?

I upgraded to Tensorflow 2.0 and there is no tf.summary.FileWriter("tf_graphs", sess.graph). I was looking through some other StackOverflow questions on this and they said to use tf.compat.v1.summary etc. Surely there must be a way to graph and…
19
votes
2 answers

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
  • 397
  • 2
  • 10
19
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
  • 383
  • 1
  • 2
  • 8
18
votes
5 answers

from_logits=True and from_logits=False get different training result for tf.losses.CategoricalCrossentropy for UNet

I am doing the image semantic segmentation job with unet, if I set the Softmax Activation for last layer like this: ... conv9 = Conv2D(n_classes, (3,3), padding = 'same')(conv9) conv10 = (Activation('softmax'))(conv9) model = Model(inputs,…
tidy
  • 4,747
  • 9
  • 49
  • 89
18
votes
4 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
  • 39,839
  • 68
  • 255
  • 489
1
2 3
99 100