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
2,189
questions
6
votes
1
answer
678
views
Cascade multiple RNN models for N-dimensional output
I'm having some difficulty with chaining together two models in an unusual way.
I am trying to replicate the following flowchart:
For clarity, at each timestep of Model[0] I am attempting to generate ...
6
votes
1
answer
540
views
How to trigger a python function inside a tf.keras custom loss function?
Inside my custom loss function I need to call a pure python function passing in the computed TD errors and some indexes. The function doesn't need to return anything or be differentiated. Here's the ...
6
votes
1
answer
6k
views
Tensorflow 2.1.0 - An op outside of the function building code is being passed a "Graph" tensor
I am trying to implement a recent paper. Part of this implementation involves moving from tf 1.14 to tf 2.1.0. The code was working with tf 1.14 but is no longer working.
NOTE: If I disable eager ...
6
votes
1
answer
2k
views
Error with exporting TF2.2.0 model with tf.lookup.StaticHashTable for Serving
I'm using StaticHashTable as in one Lambda layer after the output layer of my tf.keras model. It's quite simple actually: I've a text classification models and I'm adding a simple lambda layer that ...
6
votes
1
answer
464
views
How to save a keras subclassed model with positional parameters in Call() method?
import tensorflow as tf
class MyModel(tf.keras.Model):
def __init__(self):
super(MyModel, self).__init__()
self.dense1 = tf.keras.layers.Dense(4, activation=tf.nn.relu)
...
6
votes
1
answer
2k
views
Is it possible to integrate Levenberg-Marquardt optimizer from Tensorflow Graphics with a Tensorflow 2.0 model?
I have a Tensorflow 2.0 tf.keras.Sequential model. Now, my technical specification prescribes using the Levenberg-Marquardt optimizer to fit the model. Tensorflow 2.0 doesn't provide it as an ...
6
votes
1
answer
2k
views
When should we inherits keras.Model instead of keras.layers.Layer even if we don't use model.fit?
In some Tensorflow tutorials with tf2 (e.g. Neural Machine Translation with Attention and Eager essentials), they define custom tf.keras.Models instead of tf.keras.layers.Layers (e.g. ...
6
votes
2
answers
2k
views
Keras Autoencoder: Tying Weights from Encoder To Decoder not working
Im creating an Autoencoder as part of my full model for a Kaggle competition. Im trying to tie the weighs of the Encoder, transposed to the Decoder. Before the first Epoch the weights are correctly ...
6
votes
2
answers
3k
views
Is there any implementation of mtcnn face detection in tensorflow 2.0?
Recently I've moved to tensorflow==2.0.0-rc0 and now mtcnn for face detection is not working on my computer. Can I find tensorflow==2.0.0-rc0 version of mtcnn? Pure Keras implementation of mtcnn would ...
6
votes
0
answers
150
views
Is it possible to visualize gradients in comet-ml?
It is straightforward to set up TensorBoard in Keras (it's just a callback!) and then it is possible to visualize the distribution and magnitude of the weights and gradients. Is it possible to do the ...
5
votes
2
answers
17k
views
AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'
I have been working on keras yolov3 model for object detection. This error keeps showing up.
Here is the error:
AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'
...
5
votes
1
answer
6k
views
What is the numpy equivalent of TensorFlow Xavier initializer for CNN?
I would like to re-create the Xavier initialization in NumPy (using basic functions) in the same way that TensorFlow2 does for CNN.
Here is how I learned to do Xavier initialization in NumPy:
# ...
5
votes
3
answers
5k
views
Keras ImageDataGenerator for multiple inputs and image based target output
I have a model which takes two Images as inputs and generates a single image as a Target output.
All of my training image-data is in the following sub-folders:
input1
input2
target
Can I use ...
5
votes
2
answers
11k
views
keras : add layers to another model
I need to add layers to an existing model. However, I need to add the layers at "the main model level", that is I can't use the classic functional approach. For example, if I use something ...
5
votes
1
answer
932
views
How to create two layers with shared weights, where one is the transpose of the other?
I am using the Keras API in Tensorflow 2.0.
As an example, say I want to have two dense layers in my model, called layer1 and layer2. But I want to tie their weights, such that the weight matrix in ...
5
votes
3
answers
15k
views
Keras: fix "IndexError: list index out of range" error when using model.fit
I'm trying to build a Variational Autoencoder with several Conv2d layers that works with cifar-10.
It seems all right, but when I run the training I get this error:
Train on 50000 samples, validate ...
5
votes
1
answer
6k
views
Effects of channel_shift_range in ImageDataGenerator (Keras image augmentation)
Maybe I'm misunderstanding. If I implement channel_shift_range in my ImageDataGenerator, the output should have "scrambled" color values, right? I would like to use it to make my model more robust ...
5
votes
6
answers
8k
views
ModuleNotFoundError: No module named 'tensorflow.python.trackable'
The statement is:
from tensorflow.python.trackable import base as trackable
But the module not found error is coming up.
##### File "C:\Users\mahit\anaconda3\lib\site-packages\keras\dtensor\...
5
votes
1
answer
2k
views
Keras evaluate the validation data before the epoch ends
I'm want to train my model with Keras. I'm using a huge dataset Where one training epoch has more than 30000 steps. My problem is that I don't want to wait for an epoch before checking the model ...
5
votes
1
answer
5k
views
how to use for loop in tensorflow/keras when using tf.keras functional API?
I wish to modify the CuDNNGRU Output with for loop. However, it seems like I can't do so due to the tf.GradientTape graph mode. How can I modify the CuDNNGRU in Functional API? I know that normally we ...
5
votes
2
answers
5k
views
how to Split data in 3 folds (train,validation,test) using ImageDataGenerator when data is in different directories of each class
How do I split my data into 3 folds using ImageDataGenerator of Keras? ImageDataGenerator only gives validation_split argument so if I use it, I wont be having my test set for later purpose.
My data ...
5
votes
1
answer
10k
views
ValueError: A `Concatenate` layer should be called on a list of at least 2 inputs
I'm trying to use a sigmoid to join the output of two models with different embedding matrix. but I keep getting the error at the concatenate line. I have tried other suggestions from similar ...
5
votes
2
answers
2k
views
How does tf.keras.Model tell between features and label(s) in tf.data.Dataset and in TFRecords?
I'm trying to create tfrecords files from CSV data, then I want to use tf.data.TFRecordDataset() to create Dataset from them, and then feed the Dataset to tf.keras.Model. (In fact I'm using spark-...
5
votes
2
answers
8k
views
Difference about "BinaryCrossentropy" and "binary_crossentropy" in tf.keras.losses?
I'm training a model using TensorFlow 2.0 using tf.GradientTape(), but I find that the model's accuracy is 95% if I use tf.keras.losses.BinaryCrossentropy, but degrade to 75% if I use tf.keras.losses....
5
votes
1
answer
2k
views
Tensorflow Keras load_model from Memory or Variable?
Because tensorflow.keras.models.load_model input is path.
But I have to load it from file first, and decrypt it. then point to
load_model
if there have any idea to implementation it?
from ...
5
votes
1
answer
1k
views
Extract (or Set) input/output TF tensor names information from python API instead of saved_model_cli
I trained a simple model with Keras/TF2.5 and saved it as saved model.
tf.saved_model.save(my_model,'/path/to/model')
If I examine it via
saved_model_cli show --dir /path/to/model --tag_set serve --...
5
votes
1
answer
2k
views
Keras custom metrics self.validation_data is none , when using data generators
I have been trying to train a model and calculate precision and recall at the end of each epoch.
The custom metric
class Metrics(keras.callbacks.Callback):
def on_train_begin(self, logs={}):
...
5
votes
1
answer
7k
views
How to add CRF layer in a tensorflow sequential model?
I am trying to implement a CRF layer in a TensorFlow sequential model for a NER problem. I am not sure how to do it. Previously when I implemented CRF, I used CRF from keras with tensorflow as backend ...
5
votes
2
answers
217
views
scikeras.wrappers.KerasClassifier returning ValueError: Could not interpret metric identifier: loss
I was looking into KerasClassifier, as I would like to plug it in a scikit-learn pipeline, but I'm getting the aforementioned ValueError.
The following code should be able to reproduce the error I'm ...
5
votes
2
answers
5k
views
Tensorflow: Memory growth cannot differ between GPU devices | How to use multi-GPU with tensorflow
I am trying to run a keras code on a GPU node within a cluster. The GPU node has 4 GPUs per node. I made sure to have all 4 GPUs within the GPU node available for my use. I run the code below to let ...
5
votes
2
answers
434
views
Why tf.function traces layers twice?
The example code is as follows:
import tensorflow as tf # tf-2.4 or tf-2.x
from datetime import datetime
# Define a layer with an eager side effect
class EagerLayer(tf.keras.layers.Layer):
def ...
5
votes
1
answer
3k
views
How does Embedding layer in Keras work on float input values?
x is a (64, 1) dimensional vector created randomly using tf.random.uniform((BATCH_SIZE, 1)), where the BATCH_SIZE = 64.
A random initialization looks like this:
tf.Tensor(
[[0.76922464]
[0.7928164 ]
...
5
votes
1
answer
2k
views
How to use KerasClassifier validation split and using scitkit learn GridSearchCV
I want to try to test some hyperparameters, thats i want to use the GridSearchCV, because it seems like thats the way to do it.
But i also want to use the validation split. To use Callsbacks like ...
5
votes
1
answer
1k
views
Knowledge Distillation loss with Tensorflow 2 + Keras
I am trying to implement a very simple keras model that uses Knowledge Distillation [1] from another model.
Roughly, I need to replace the original loss L(y_true, y_pred) by L(y_true, y_pred)+L(...
5
votes
1
answer
3k
views
TypeError: 'Not JSON Serializable' while doing tf.keras.Model.save and using keras variable in loss_weights in tf.keras.Model.compile
System information
OS Platform and Distribution: Ubuntu 16.04 LTS
TensorFlow installed from (source or binary): binary
TensorFlow version (use command below): 1.12.0
Python version: 3.5.2 ...
5
votes
1
answer
2k
views
TF2.13: Local rendezvous recv item cancelled
Since TF2.13 we see this warning using the Docker tensorflow/tensorflow:latest-gpu:
tensorflow/core/framework/local_rendezvous.cc:405] Local rendezvous recv item cancelled. Key hash:
It is repeating ...
5
votes
0
answers
2k
views
Using XLA in TensorFlow libdevice.10.bc InternalEr
When I run this line of code:
tf.config.optimizer.set_jit(True)
To enable XLA in TensorFlow 2.1, I get the follow error:
InternalError: libdevice not found at ./libdevice.10.bc
[[{{node ...
5
votes
0
answers
2k
views
'tensorflow.keras.models.load_model' results in "ValueError: The two structures don't have the same nested structure."
After I save a model and load it, I get "ValueError: The two structures don't have the same nested structure."
This is the code to reproduce the error
!pip install transformers --q
%...
5
votes
0
answers
2k
views
TF Dataset from Keras Sequence Class
I thought I would share something that took me a while to figure out: easily wrapping an existing Keras Sequence Class with a TF Dataset object. After following tutorials and migrating from TF 1.X and ...
5
votes
0
answers
543
views
set_weights stopped working on tensorflow 2
Updating our code base from keras --> tensorflow.keras for unrelated reasons.
keras 2.3.1
tensorflow 2.1.0
This code works on keras, but fails on tf.keras:
weights = applications.VGG16(weights='...
5
votes
0
answers
1k
views
Understanding why EagerTensor.numpy() is slow
I'm trying to make predictions using a pre-trained custom image segmentation model on some image data but I'm having problems with the predictions being too slow.
After doing some profiling using ...
5
votes
0
answers
49
views
Concatenating two saved models in tensorflow 1.13 [duplicate]
I've a pretrained model saved as ckpt files (meta, index ...) and I'm loading the graph using tf.train.import_meta_graph() and tf.train.Saver.restore().
I also have a resnet50 model from tf.keras....
5
votes
0
answers
665
views
How to convert trained in custom loop subclassed tf.keras.model to tflite?
I have a problem with converting trained subclassed model (tf.keras.Model) in custom loop to TFLite.
Suppose we have small CNN architecture that use input data (x) and additional information that ...
5
votes
1
answer
1k
views
Quantization-aware training in Tensorflow using the highlevel keras api
I built my first covnet using the process described in this colab. Now I would like to run the model on Googles shiny new edge tpu.
But according to the Model Requirments described here, I need to ...
5
votes
0
answers
2k
views
keras.backend.function return a AttributeError: Layer dense is not connected, no input to return
I want to know the median result of a neutral network for tuning purpose. I design my model and use keras.backend.function but failed(AttributeError: Layer dense is not connected, no input to return). ...
4
votes
1
answer
3k
views
What's the difference between attrubutes 'trainable' and 'training' in BatchNormalization layer in Keras Tensorfolow?
According to the official documents from tensorflow:
About setting layer.trainable = False on a `BatchNormalization layer:
The meaning of setting layer.trainable = False is to freeze the layer, i.e. ...
4
votes
3
answers
1k
views
Implementing a trainable generalized Bump function layer in Keras/Tensorflow
I'm trying to code the following variant of the Bump function, applied component-wise:
,
where σ is trainable; but it's not working (errors reported below).
My attempt:
Here's what I've coded up ...
4
votes
5
answers
29k
views
How can I ignore or remove ".ipynb_checkpoints" in colab?
My code in tf.keras is given below.
I want to retrieve a file(Xscale.npy) in each sub_directory(component_0, component_1) of model_cnn folder.
root_dir = '/content/drive/My Drive/DeepCID/model_cnn'
...
4
votes
1
answer
2k
views
How to implement a neural network with a not-fully-connected layer as the final layer?
I would like to implement a neural network with an input layer, two dense hidden layer and a non-dense output layer. A toy example is shown in the figure below. The first hidden layer has three ...
4
votes
1
answer
4k
views
Keras: Custom loss function with training data not directly related to model
I am trying to convert my CNN written with tensorflow layers to use the keras api in tensorflow (I am using the keras api provided by TF 1.x), and am having issue writing a custom loss function, to ...