All Questions
Tagged with tf.keras python-3.x
205
questions
20
votes
5
answers
22k
views
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 ...
13
votes
1
answer
2k
views
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 ...
12
votes
1
answer
13k
views
"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()
...
9
votes
4
answers
7k
views
Cannot clone object <tensorflow.python.keras.wrappers.scikit_learn.KerasClassifier object
This is with regards to TF 2.0.
Please find below my code that performs GridSearch along with Cross Validation using sklearn.model_selection.GridSearchCV for the mnist dataset that works perfectly ...
8
votes
3
answers
7k
views
Keras Model AttributeError: 'str' object has no attribute 'call'
I'm trying to convert my Keras hdf5 file into a TensorFlow Lite file with the following code:
import tensorflow as tf
# Convert the model.
converter = tf.lite.TFLiteConverter.from_keras_model("/...
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 ...
7
votes
1
answer
8k
views
What is the difference between input_shape and input_dim in keras?
Currently i am learning deep learning and stumbled upon these confusion:
when to use input_shape and input_dim parameter.
shape of my data is (798,9) and these has 8 input variable and 1 output ...
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
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
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
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
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
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
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
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....
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/...
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 ...
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 ...
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 ...
3
votes
1
answer
1k
views
Tensorflow 2.1 full memory and tf.function called twice
I'm developing a Convolutional Autoencoder with Tensorflow 2.1.
This is the code
class ConvAutoencoder:
def __init__(self, input_shape, latent_dim):
self.input_shape = input_shape
self....
3
votes
2
answers
1k
views
Tensorflow 1.15 / Keras 2.3.1 Model.train_on_batch() returns more values than there are outputs/loss functions
I am trying to train a model that has more than one output and as a result, also has more than one loss function attached to it when I compile it.
I haven't done something similar in the past (not ...
3
votes
1
answer
410
views
TF 2.0 - Method estimator.model_to_estimator( ) fails but model.fit works for tf.keras created model
While using the TF 2.0 Alpha and converting a working TF Keras model to TF estimator I encountered a strange error.
The below code has been taken from the Tensorflow without PHD series - RNN time ...
3
votes
1
answer
3k
views
using tfa.layers.crf on top of biLSTM
I am trying to implement NER model based on CRF with tensorflow-addons library. The model gets sequence of words in word to index and char level format and the concatenates them and feeds them to the ...
3
votes
0
answers
277
views
Why is my GAN not producing more good images after a certain point?
Question
I was training a gan to generate human faces. Within approximately 500 epochs, it learned to generate images like this:
Well, now this image is not too bad. We can see a face in the center ...
3
votes
1
answer
1k
views
How to normalize output from BERT classifier
I've trained a BERT classifier using HuggingFace transformers.TFBertForSequenceClassification classifier. It's working fine, but when using the model.predict() method, it gives a tuple as output which ...
2
votes
1
answer
2k
views
TensorFlow 2.0 'build' function
I was reading about creating neural networks using TensorFlow 2.0 in conjunction with 'GradientTape' API and came across the following code:
model = tf.keras.Sequential((
tf.keras.layers.Reshape(...
2
votes
2
answers
2k
views
Loading ModelCheckpoint in tensorflow 2
In keras using tensorflow 1 I could ModelCheckpoint(filepath) and the saved file was a called filepath and then I could call model = load_model(filepath) to load the saved model.
Now the equivalent ...
2
votes
1
answer
597
views
keras vs. tensorflow.keras
Inspired by this post.
Why is there a difference between the 2 modules?
When would I use one over the other?
Anything else I should know?
2
votes
2
answers
1k
views
TensorFlow 2.0 - Model subclassing : no input dimension
I was reading the TensorFlow 2.0 Tutorial and I came across model subclassing to create TensorFlow 2.0 models.
The code I found was:
class MyModel(Model):
def __init__(self):
super(MyModel, ...
2
votes
2
answers
2k
views
"The CPU implementation of FusedBatchNorm only supports NHWC tensor format for now."
I am trying to recreate a model and re-produce its published results. I use TF 2.0 and the model I think was coded with Theano backend. The model came from this repo in github, for context.
I also do ...
2
votes
2
answers
2k
views
ImageDataGenerator.flow_from_directory to a dataset that can be used in Kfold
I am trying to use the cross validation approach for the model I use for classifying images into 3 classes. I use the following code to import images:
train_datagen = ImageDataGenerator(rescale=1./255)...
2
votes
1
answer
68
views
Error receiving while loading the pickle in ANN model
I am new in deep learning and apologies if the question was asked earlier as i am not able to find relevant content so asking.
Need one help regarding error which i am getting while building a model ...
2
votes
1
answer
861
views
mse loss function not compatible with regularization loss (add_loss) on hidden layer output
I would like to code in tf.Keras a Neural Network with a couple of loss functions. One is a standard mse (mean squared error) with a factor loading, while the other is basically a regularization term ...
2
votes
1
answer
4k
views
Tensorflow, Keras pretrained MobileNetV2 Model doesn't download
I following this tutorial on on transferred learning in tensorflow keras. An error occurs when it tries to download the mobilenetV2 model.
This is the code that fails:
base_model = tf.keras....
2
votes
1
answer
87
views
AttributeError: module 'keras._tf_keras.keras' has no attribute '__internal__'
Trying to install top2vec on colab ,and install everything that other people mentioned, but still get this error, have no idea how to solve,anybody knows? really appreciate! error screenshot
!pip ...
2
votes
1
answer
839
views
Inheritance of Build in Custom Layer (super().build(input_shape))
I was trying to understanding the concept of custom layer in tensorflow keras.
When the Simple_dense Layer was created without activation then the code looked like the below:
class SimpleDense(Layer):
...
2
votes
1
answer
2k
views
AttributeError: 'DirectoryIterator' object has no attribute 'map'
I would like to applicate a function (gaussian_filter) to my dataset with map
here is a part of my code
datagen = tf.keras.preprocessing.image.ImageDataGenerator(vertical_flip=True)
training_set = ...
2
votes
1
answer
270
views
Assign tensor value to placeholder in tensorflow v1.13
In my tensorflow model, output of one network is a tensor. This value I need to feed as input to another pretrained network. I'm loading the pretrained network as follows
input_b_ph = tf.placeholder(...
2
votes
1
answer
466
views
Evaluating pairwise distances between the output of a tf.keras.model
I am trying to create a custom loss function in tensorflow. I am using tensorflow v2.0.rc0 for running the code. Following is the code and the function min_dist_loss computes the pairwise loss between ...
2
votes
1
answer
1k
views
6GB GPU memory available, but tensorflow.keras only uses 3
Can anyone tell me why im running out of memory? My GPU has 6GB of dedicated. In the start keras only wanted to see 3GB. But after forcing it to see 5.5, it still refuses to go above 3, and produces ...
2
votes
0
answers
510
views
Memory Leakage tflite models
I have a tensorsorflow lite model (keras) in a flutter application that segments objects in an image (model is trained only on one specific object). With this model I can make 50-60 predictions ...
2
votes
1
answer
744
views
tf.keras ImageDataGenerator for Semantic Segmentation: Keep y values as integers
In short
I want to use the easy to use tf.keras.preprocessing.image.ImageDataGenerator to load batches of X and y images to train CNNs for semantic segmentation. Augmentation is to be applied on the ...
2
votes
0
answers
404
views
Can't load weights of a keras model saved with old keras version using new keras version
I'm trying to set weights of a keras model (loaded with new keras version - 2.2.4-tf, which is now under tensorflow package) which was saved to a DB using old keras, but it is failing with the error:
...
2
votes
0
answers
208
views
Call `model.predict()` from an externally attached function
Using this as reference, I came up with the code below:
import tensorflow as tf
from tensorflow.keras.applications.densenet import DenseNet121
from tensorflow.keras.applications.densenet import ...
2
votes
0
answers
645
views
Failed to convert object of type <class 'tensorflow.python.framework.sparse_tensor.SparseTensor'> to Tensor
I'm trying to build a ML production pipeline using TFX, and currently working on Trainer module. I need to implement modelling in a separate file.
Here is part of pipeline, which handle training:
...
2
votes
0
answers
251
views
tape.gradient for model.trainable_variables returning None value
Here is my Function:
def grad(self,model,ytrain, x_train):
with tf.GradientTape() as tape:
loss_value = self.calculate_loss(ytrain, self.pred)
#Value of ...
2
votes
1
answer
267
views
AttributeError: 'KerasTPUModel' object has no attribute '_ckpt_saved_epoch'
I am training a keras model with google colab TPU. My code ran successfully on CPU and GPU before. However, when I changed the code to the TPU version, I met some error.
Here is my transform code:
...
2
votes
0
answers
591
views
How to set loss for train_op using tf estimator API when the loss is input-dependent and implemented via a custom loss layer?
I am implementing a CNN model with tf.estimator API.
Briefly, the cost/loss function is input-dependent and contains variables to be updated during training. I implemented a custom layer with ...
1
vote
2
answers
9k
views
ValueError: A merge layer should be called on a list of inputs. Tensorflow Keras
I am currently trying to use the first 50 layers of the MobileNetV2. Therefore, I want to extract those layers and create a new model.
I thought I could just call every layer, but the "block_2_add" ...
1
vote
1
answer
2k
views
TypeError when using tf.keras.optimizers.apply_gradients method in TensorFlow 2.0
When I executed codes as the following, an error message TypeError: zip argument #2 must support iteration popped onto the screen.
theta = tf.Variable(tf.zeros(100), dtype=tf.float32, name='theta')
...