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
65 votes
4 answers
21k views

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 ...
gosuto's user avatar
  • 5,552
59 votes
20 answers
131k views

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 ...
Alice's user avatar
  • 663
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
29 votes
8 answers
23k views

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 ...
Gary's user avatar
  • 823
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
26 votes
2 answers
17k views

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'...
Animesh Sinha's user avatar
24 votes
4 answers
47k views

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 ...
Aadnan Farooq A's user avatar
20 votes
3 answers
31k views

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....
valend.in's user avatar
  • 393
20 votes
5 answers
28k views

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('...
tidy's user avatar
  • 4,857
16 votes
6 answers
49k views

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 ...
Manuel Popp's user avatar
  • 1,121
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
2 answers
49k views

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(...
Siladittya's user avatar
  • 1,166
13 votes
7 answers
25k views

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 ...
Dean's user avatar
  • 199
13 votes
1 answer
656 views

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 ...
SantoshGupta7's user avatar
11 votes
1 answer
25k views

How to save a list of numpy arrays into a single file and load file back to original form [duplicate]

I am currently trying to save a list of numpy arrays into a single file, an example of such a list can be of the form below import numpy as np np_list = [] for i in range(10): if i % 2 == 0: ...
DVK's user avatar
  • 495
11 votes
3 answers
37k views

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 ...
razimbres's user avatar
  • 4,916
11 votes
1 answer
4k views

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 ...
Luke's user avatar
  • 6,879
11 votes
1 answer
1k views

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 ...
Ravish Jha's user avatar
11 votes
1 answer
644 views

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 ...
francoisr's user avatar
  • 4,487
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
10 votes
2 answers
7k views

Passing `training=true` when using Tensorflow 2's Keras Functional API

When operating in graph mode in TF1, I believe I needed to wire up training=True and training=False via feeddicts when I was using the functional-style API. What is the proper way to do this in TF2? ...
cosentiyes's user avatar
10 votes
2 answers
9k views

How do you apply layer normalization in an RNN using tf.keras?

I would like to apply layer normalization to a recurrent neural network using tf.keras. In TensorFlow 2.0, there is a LayerNormalization class in tf.layers.experimental, but it's unclear how to use it ...
MiniQuark's user avatar
  • 47.5k
10 votes
1 answer
974 views

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 ...
Xi Liu's user avatar
  • 619
10 votes
1 answer
5k views

CUDNN_STATUS_BAD_PARAM when trying to perform inference on a LSTM Seq2Seq with masked inputs

I'm using keras layers on tensorflow 2.0 to build a simple LSTM-based Seq2Seq model for text generation. versions I'm using: Python 3.6.9, Tensorflow 2.0.0, CUDA 10.0, CUDNN 7.6.1, Nvidia driver ...
Felipe's user avatar
  • 11.8k
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
4 answers
5k views

Saving meta data/information in Keras model

Is it possible to save meta data/meta information in Keras model? My goal is to save input pre-processing parameters, train/test set used, class label maps etc. which I can use while loading model ...
Vivek Mehta's user avatar
  • 2,612
9 votes
4 answers
17k views

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,...
Vahid Mirjalili's user avatar
9 votes
1 answer
7k views

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' ...
Adomas Baliuka's user avatar
9 votes
5 answers
7k views

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 ...
Ridane's user avatar
  • 101
8 votes
2 answers
9k views

How to correctly use the Tensorflow MeanIOU metric?

I want to use the MeanIoU metric in keras (doc link). But I don't really understand how it could be integrated with the keras api. In the example, the prediction and the ground truth are given as ...
opetit's user avatar
  • 81
8 votes
2 answers
23k views

TensorFlow 2.0 How to get trainable variables from tf.keras.layers layers, like Conv2D or Dense

I have been trying to get the trainable variables from my layers and can't figure out a way to make it work. So here is what I have tried: I have tried accessing the kernel and bias attribute of the ...
MattSt's user avatar
  • 1,093
8 votes
1 answer
11k views

SHAP DeepExplainer with TensorFlow 2.4+ error

I'm trying to compute shap values using DeepExplainer, but I get the following error: keras is no longer supported, please use tf.keras instead Even though i'm using tf.keras? KeyError ...
Fred's user avatar
  • 95
8 votes
1 answer
16k views

Tensorflow model.fit() using a Dataset generator

I am using the Dataset API to generate training data and sort it into batches for a NN. Here is a minimum working example of my code: import tensorflow as tf import numpy as np import random def ...
berkelem's user avatar
  • 2,065
8 votes
1 answer
6k views

Tensorflow Keras RMSE metric returns different results than my own built RMSE loss function

This is a regression problem My custom RMSE loss: def root_mean_squared_error_loss(y_true, y_pred): return tf.keras.backend.sqrt(tf.keras.losses.MSE(y_true, y_pred)) Training code sample, ...
ma7555's user avatar
  • 370
8 votes
3 answers
23k views

Cannot use keras models on Mac M1 with BigSur

I am trying to use Sequential model from keras of tensorflow. When I am executing following statement: model.fit(x_train, y_train, epochs=20, verbose=True, validation_data=(x_dev, y_dev), batch_size=...
Ankita's user avatar
  • 159
8 votes
2 answers
5k views

Does tf.keras.metrics.AUC work on multi-class problems?

I have a multi-class classification problem and I want to measure AUC on training and test data. tf.keras has implemented AUC metric (tf.keras.metrics.AUC), but I'm not be able to see whether this ...
Oscar Gabriel Reyes Pupo's user avatar
8 votes
1 answer
2k views

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. (https://www.tensorflow.org/beta/guide/keras/functional#...
mpotma's user avatar
  • 243
7 votes
1 answer
17k views

ValueError: No gradients provided for any variable - Tensorflow 2.0/Keras

I am trying to implement a simple sequence-to-sequence model using Keras. However, I keep seeing the following ValueError: ValueError: No gradients provided for any variable: ['simple_model/...
Stefan Falk's user avatar
  • 24.6k
7 votes
4 answers
3k views

Keras - no good way to stop and resume training?

After a lot of research, it seems like there is no good way to properly stop and resume training using a Tensorflow 2 / Keras model. This is true whether you are using model.fit() or using a custom ...
Daniel's user avatar
  • 1,145
7 votes
4 answers
7k views

The clear_session() method of keras.backend does not clean up the fitting data

I am working on a comparison of the fitting accuracy results for the different types of data quality. A "good data" is the data without any NA in the feature values. A "bad data" is the data with NA ...
Ruben Kazumov's user avatar
7 votes
2 answers
7k views

Keras callback AttributeError: 'ModelCheckpoint' object has no attribute '_implements_train_batch_hooks'

I'm using Keras (with TensorFlow back-end) to implement a neural network and want to only save the model that minimises loss on the validation set during training. To do this, I instantiated a ...
Sanda Achard's user avatar
7 votes
3 answers
7k views

Using tf.keras.utils.Sequence with model.fit_generator with use_multiprocessing=True generated warning

This is the warning I got: WARNING:tensorflow:multiprocessing can interact badly with TensorFlow, causing nondeterministic deadlocks. For high performance data pipelines tf.data is recommended. The ...
kawingkelvin's user avatar
  • 3,769
7 votes
1 answer
2k views

How do sessions and parallelism work in TF2.0?

I am trying to run two tensorflow models in parallel in the same process. In Tensorflow 1.x we could do e.g. Keras Tensorflow - Exception while predicting from multiple threads graph = tf.Graph() ...
Martingale's user avatar
7 votes
0 answers
3k views

Tensorflow Keras model.summary() shows 0 trainable parameters on a layer

I'm training a LSTM variant, PhasedLSTM, for regression. I'm using tensorflow.contrib.rnn.PhasedLSTMCell which expects a vector of timestamps in addition to the features. Here's my model definition : ...
Tapio's user avatar
  • 1,582
6 votes
2 answers
17k views

tf.keras.preprocessing.image_dataset_from_directory Value Error: No images found

belos is my code to ensure that the folder has images, but tf.keras.preprocessing.image_dataset_from_directory returns no images found. What did I do wrong? Thanks. DATASET_PATH = pathlib.Path('C:\\...
LLTeng's user avatar
  • 395
6 votes
2 answers
6k views

Why am I receive AlreadyExistsError?

When I train my binary classification via keras I received this error: AlreadyExistsError: Resource __per_step_16/training_4/Adam/gradients/lstm_10/while/ReadVariableOp_8/Enter_grad/...
Shem's user avatar
  • 71
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
7k views

How to substitute `keras.layers.merge._Merge` in `tensorflow.keras`

I want to create a custom Merge layer using the tf.keras API. However, the new API hides the keras.layers.merge._Merge class that I want to inherit from. The purpose of this is to create a Layer that ...
romanovzky's user avatar
6 votes
1 answer
7k views

Why does Keras gives me different results between model.evaluate, model.predicts & model.fit?

I'm working on a project with a resnet50 based dual output model. One output is for the regression task and the second output is for a classification task. My main question is about the model ...
yannivain's user avatar

1
2 3 4 5
20