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 with a lot of examples). The API of is described here

1494 questions
8
votes
2 answers

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 within a recurrent layer like LSTM, at each time…
MiniQuark
  • 40,659
  • 30
  • 140
  • 167
7
votes
0 answers

TypeError: can't pickle weakref objects for deep learning model

when I ran pickle.dump(model,open('modelDL.pkl','wb')) , I am getting TypeError: can't pickle weakref objects. I have a created a deep learning model , which I am trying to save. Below is the model. model = Sequential() model.add(…
7
votes
0 answers

tf.data.Dataset iterator returning Tensor("IteratorGetNext:1", shape=(None, 16), dtype=int32) but cannot get the values of the Tensors

I am trying to write a Custom Model in which I am writing a custom train_step function I am creating a 'tf.data.Dataset` from a Custom Datagenerator like tds = tf.data.Dataset.from_generator(tdg.__iter__,args=None,output_types =…
Siladittya
  • 802
  • 1
  • 10
  • 25
7
votes
1 answer

TF2.1: SegNet model architecture problem. Bug with metric calculation, keeps constant and converge to determined value

I'm building a custom model (SegNet) in Tensorflow 2.1.0. The first problem I'm facing is the reutilization of the indices of the max pooling operation needed as described in the paper. Basically, since it is an encoder-decoder architecture, the…
rpasianotto
  • 1,273
  • 1
  • 8
  • 21
7
votes
3 answers

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 so far (if it helps). Suppose I have two functions…
BLBA
  • 371
  • 1
  • 13
7
votes
0 answers

Call Model.fit with tensors / Executing op on CPU not GPU / Tensorflow 2.1

I am experimenting with reinforcement learning in python. I am using Tensorflow 2.1 and my machine has muyliple GPUs (with CUDA 10.2 driver 440.59). I am allocating the operations on my GPUs using tf.device(). I am not using the…
NicMaq
  • 71
  • 3
7
votes
1 answer

Unable to train my keras model : (Data cardinality is ambiguous:)

I am using the bert-for-tf2 library to do a Multi-Class Classification problem. I created the model but training throws the following error: --------------------------------------------------------------------------- ValueError …
7
votes
1 answer

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 version 410.78. I'm aware of the criteria needed by…
Felipe
  • 10,031
  • 7
  • 45
  • 97
7
votes
2 answers

Unable to import Keras(from TensorFlow 2.0) in PyCharm 2019.2

I have just installed the stable version of TensorFlow 2.0 (released on October 1st 2019) in PyCharm. The problem is that the keras package is unavailable. The actual error is : "cannot import name 'keras' from tensorflow" I have installed via…
Timbus Calin
  • 8,826
  • 2
  • 22
  • 40
7
votes
1 answer

Loading file from path contained in tf.Tensor

I build a simple model using tf.keras and a tf.data.Dataset for efficient loading as the dataset is a couple of GBs big. The images are in tiff format and therefore need to be loaded directly as numpy.array. I do have a dataset of labels and file…
turnman
  • 144
  • 7
7
votes
1 answer

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 my_generator(): while True: x =…
berkelem
  • 1,573
  • 2
  • 13
  • 27
7
votes
1 answer

Should I use the standalone Keras library or tf.keras?

As Keras becomes an API for TensorFlow, there are lots of old versions of Keras code, such as https://github.com/keiserlab/keras-neural-graph-fingerprint/blob/master/examples.py from keras import models With the current version of TensorFlow, do we…
jason
  • 1,320
  • 2
  • 13
  • 28
6
votes
1 answer

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'
dPac
  • 927
  • 9
  • 14
6
votes
1 answer

Keras, 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 an entire time series from IR[i] (Intermediate…
OmnipotentEntity
  • 14,886
  • 5
  • 58
  • 93
6
votes
1 answer

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 ModelCheckpoint and pass it when calling the fit method…
Sanda Achard
  • 61
  • 1
  • 3