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.

tf.keras
Filter by
Sorted by
Tagged with
4 votes
1 answer
2k views

ModuleNotFoundError: No module named 'keras' using tensorflow 2.6.0 in Anaconda

I am trying to learn tensorflow and use a book to gain some first insights. The code I am currently trying to get to run can also be found here: https://github.com/chrismattmann/MLwithTensorFlow2ed/...
Aushilfsgott'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
4 votes
1 answer
2k views

Save / Load Tensorflow Keras model for Prediction only

I have a tensorflow keras model with custom losses. After trianing, I want to store the model using model.save(path) and in another python script load the model for prediction only using model = tf....
ruhig brauner's user avatar
4 votes
0 answers
1k views

tf.keras mixed precision loss scale still causing underflow

When I use mixed precision for my tf.keras model, my model's loss isn't going down at all. I noticed that my gradients often either end up at "nan" values or "-inf" or "inf" after using mixed ...
cmed123's user avatar
  • 685
4 votes
0 answers
3k views

TypeError: 'SparseTensor' object is not subscriptable in tf-keras

I am trying to train a Deep Learning model. model.fit(x_train, y_train, batch_size=batch_size, validation_data=(x_test, y_test), epochs=epochs, callbacks=callbacks, ...
loadbox's user avatar
  • 646
4 votes
0 answers
398 views

How to use tfa.seq2seq.BahdanauAttention with tf.keras functional API?

I want to use tfa.seq2seq.BahdanauAttention with functional API of tf.keras. I have looked at the example given at tensorflow/nmt/attention_model.py. But I couldn't figure out how to use it with tf....
Manideep's user avatar
4 votes
0 answers
772 views

How to create a combined tf.keras model with conditional evaluation of sub-models

I want to create a combination of multiple tf.keras.Sequential models such that only one of the sub-models is evaluated at any given point in time. To better explain, I created the following model (...
EcoView's user avatar
  • 78
4 votes
0 answers
678 views

tf keras, custom loss function that require multiple network outputs as inputs

I've recently decided to try tf2.0, especially the high level keras API. I am not too familiar with keras either, have mainly been using tensorflow before. However, I cannot find a good way of using ...
Hongtao Yang's user avatar
4 votes
0 answers
250 views

Tensorflow/Keras local training 6x faster than distributed training

I am training a Classifier (via RNN) in Tensorflow with tf.data api, tf.keras api and tf. estimator api. In local training i got a troughput of around 240 steps/sec, than i enter distributed mode with ...
ancube's user avatar
  • 69
4 votes
0 answers
866 views

Uncaught exception on Future: Generic conv implementation does not support grouped convolutions for now

E/TensorFlowInferenceInterface: Failed to run TensorFlow inference with inputs:[conv2d_1_input], outputs:[dense_2/Softmax] Uncaught exception on Future: Generic conv implementation does not support ...
Manisha's user avatar
  • 41
4 votes
0 answers
438 views

How to import a keras model into lucid

The short version: I would like to visualize a keras model in lucid, and fail to transform the model into a format lucid would accept. The long version: I would like to play around with lucid ...
Peter's user avatar
  • 41
4 votes
0 answers
205 views

Train multi-column CNN with memory contrains

I deployed an Inception v3 model with tf.keras and it's working fine. At the moment, I'm trying to improve my model to let it handle multiple patches/images together, something along this article by ...
dcolazin's user avatar
  • 1,009
4 votes
0 answers
576 views

Issue with GPU utilization with TensorFlow

I am trying to train a network (a lrcn ie a CNN followed by LSTM) using TensoFlow like so: model=Sequential(); .. . . # my model model.compile(loss='...
a_rb's user avatar
  • 41
4 votes
2 answers
8k views

Keras Error: "Optimization loop failed: Cancelled: Operation was cancelled" When Calling predict_on_batch

I had some older working code that used keras. I recently dusted it off and tried to use it but with current versions of keras/tensorflow. I am getting a warning/error when calling predict_on_batch: W ...
Bruce Nielson's user avatar
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
8k views

RMSprop optimizer in model compiling section ,in keras does not work

i use tensorflow 2.1.0 and keras 2.2.4tf when I want to compile my model[here is the piece of code I use]: model.compile(loss='binary_crossentropy', optimizer=optimizers.RMSprop(lr=2e-5),...
Mo.be's user avatar
  • 95
3 votes
2 answers
3k views

tf.keras how to save ModelCheckPoint object

ModelCheckpoint can be used to save the best model based on a specific monitored metrics. So it obviously has information about the best metrics stored within its object. If you train on google colab ...
kawingkelvin's user avatar
  • 3,769
3 votes
2 answers
9k views

ValueError: Could not interpret optimizer identifier: <tensorflow.python.keras.optimizers.SGD object at 0x0000013887021208>

I try to run this code and I have this error, Please any one had the same error in the past: sgd = optimizers.SGD(lr = 0.01, decay = 1e-6, momentum = 0.9, nesterov = True) Compile model model....
SpEm1822's user avatar
3 votes
2 answers
2k views

Tensorflow.Keras: Custom Constraint Not Working

Im trying to implement the Weights Orthogonality Constraint showed here, in section 2.0. when i try to use it on a Keras Dense Layer, An Value Error is raised. This is happening too when trying to ...
ElPapi42's user avatar
  • 514
3 votes
3 answers
2k views

How to display the layers of a pretrained model instead of a single entry in model.summary() output?

As the title clearly describes the question, I want to display the layers of a pretained model instead of a single entry (please see the vgg19 (Functional) entry below) in model.summary() function ...
talha06's user avatar
  • 6,346
3 votes
1 answer
3k views

Why training accuracy and validation accuracy are different for the same dataset with tensorflow2.0?

I am training with tensorflow2.0 and tensorflow_datasets. But I am not understand: why does the training accuracy and loss and valdataion accuracy and loss are different? This is my code: import ...
tidy's user avatar
  • 4,857
3 votes
1 answer
3k views

Explicit broadcasting of variable batch-size tensor

I'm trying to implement a custom Keras Layer in Tensorflow 2.0RC and need to concatenate a [None, Q] shaped tensor onto a [None, H, W, D] shaped tensor to produce a [None, H, W, D + Q] shaped tensor. ...
wwilliamcook's user avatar
3 votes
1 answer
8k views

Keras GlobalMaxPooling2D TypeError: ('Keyword argument not understood:', 'keepdims')

I'm trying to implement a layer GlobalMaxPooling2D layer. I have a 10x10x128 input and want it reduced to a 3D tensor of shape 1x1x128. I tried using keepdims=True, but it throws a TypeError: ('...
Sukrit Kumar's user avatar
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 ...
Serj Ionescu's user avatar
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 ...
David Bradford's user avatar
3 votes
2 answers
8k views

UnknownError: Failed to get convolution algorithm

Complete Error : UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above. [Op:...
CHETAN RAJPUT's user avatar
3 votes
1 answer
1k views

Keras Layer Build Error: build() takes 1 Positional Argument but two were given

I have the following error in this simple layer: class MyLayer(Layer): def __init__(self): super(MyLayer, self).__init__() def build(self): # Create a trainable weight variable for this ...
tstseby's user avatar
  • 1,279
3 votes
1 answer
9k views

module 'tensorflow' has no attribute 'get_default_graph'

I am trying to build a deep learning model but I am getting an error using tensorflow and I am failing to fix this issue. I am trying to build a deep learning model but I m getting this error while ...
Moinak Dey's user avatar
3 votes
1 answer
3k views

How to rename the layers of a Keras model without corrupting the structure?

For some library functionality I'm trying to rename the layers (including the input layers) of a given model. The following minimal example shows the error I run into with my current approach (using ...
Tobias Hermann's user avatar
3 votes
3 answers
1k views

Colab+TPU not supporting TF 2.3.0 tf.keras.layers.experimental.preprocessing

I was updating my model using TF 2.3.0 on Colab+TPU based on https://keras.io/examples/vision/image_classification_efficientnet_fine_tuning/, specifically following the Data augmentation and Transfer ...
Daviddd's user avatar
  • 781
3 votes
2 answers
259 views

The model is broken when I replaced keras with tf.keras

When I tried to use keras to build a simple autoencoder, I found something strange between keras and tf.keras. tf.__version__ 2.2.0 (x_train,_), (x_test,_) = tf.keras.datasets.mnist.load_data() ...
letterbee's user avatar
3 votes
1 answer
9k views

Re-called on a Tensor with incompatible shape

I'm trying to create a CNN + Regression model here through the code below: # Create the base model from the pre-trained model MobileNet V2 cnn_model = keras.applications.MobileNetV2(input_shape=...
SDG's user avatar
  • 2,280
3 votes
1 answer
3k views

How to access and visualize the weights in a pre-trained TensorFlow 2 model?

So, I have re-trained a pre-trained ResNet50 V2 model in TensorFlow 2 using the tf.keras framework with two Dense layers added to the top. Now I want to visualize the weights in the layers within the ...
kelkka's user avatar
  • 954
3 votes
2 answers
379 views

Does model.reset_states for LSTM affect any other non-LSTM layers in the model?

I am using the Stateful mode of LSTMs in tf.keras where I need to manually do reset_states when I have processed my sequence data, as described here. It seems that normally people do model....
adamconkey's user avatar
  • 4,414
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
1 answer
1k views

Meaning of tf.keras.layers.LSTM parameters

I am having trouble understanding some of the parameters of LSTM layers in the tf.keras.layers API. I am investigating using CuDNNLSTM layers instead of LSTM layers (to speed up training), but ...
mickey's user avatar
  • 485
3 votes
1 answer
653 views

How to find keras.json file in google colab?

On my local system I know where is the keras.json file present(.keras/keras.json) but when I switched to google colab, I don't know where to find it. I did google search for this problem but have not ...
Rahul Anand'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
1k views

tf.keras.Model.predict and call return different result

tf.keras.Model.predict and call return different result import tensorflow as tf import numpy as np tf.set ipts = tf.keras.Input([2]) x = tf.keras.layers.Dense(10)(ipts) x = tf.keras.layers.Dropout(0....
nan's user avatar
  • 401
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
1 answer
3k views

from_tensor_slices() with big numpy array while using tf.keras

I have some training data in a numpy array - it fits in the memory but it is bigger than 2GB. I'm using tf.keras and the dataset API. To give you a simplified, self-contained example: import numpy as ...
godfryd's user avatar
  • 582
3 votes
1 answer
3k views

Keras model fails to predict if called in a thread

I try to perform predictions using keras and the available model VGG16 in a threaded application. However, if I call the prediction in the main thread everything works fine. But if I predict inside a ...
Tik0's user avatar
  • 2,599
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 ...
MightyOwl's user avatar
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% ...
Panda's user avatar
  • 101
3 votes
2 answers
1k views

TensorFlow, Keras: Replace Activation layer in pretrained model

I'm trying to replace swish activation with relu activation in pretrained TF model EfficientNetB0. EfficientNetB0 uses swish activation in Conv2D and Activation layers. This SO post is very similar to ...
mrtpk's user avatar
  • 1,407
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 ...
user avatar
3 votes
1 answer
3k views

What is the difference between tf.square, tf.math.square and tf.keras.backend.square?

I have been looking to learn TensorFlow and I have noticed that different functions are used for the same goal. To square a variable for instance, I have seen tf.square(), tf.math.square() and tf....
Gokulnath's user avatar

1
3 4
5
6 7
44