How to visualize RNN/LSTM gradients in Keras/TensorFlow?

Gradients can be fetched w.r.t. weights or outputs – we’ll be needing latter. Further, for best results, an architecture-specific treatment is desired. Below code & explanations cover every possible case of a Keras/TF RNN, and should be easily expandable to any future API changes. Completeness: code shown is a simplified version – the full version … Read more

Strange behaviour of the loss function in keras model, with pretrained convolutional base

Looks like I found the solution. As I have suggested the problem is with BatchNormalization layers. They make tree things subtract mean and normalize by std collect statistics on mean and std using running average train two additional parameters (two per node). When one sets trainable to False, these two parameters freeze and layer also … Read more

How do I plot a Keras/Tensorflow subclassing API model?

I’ve found some workaround to plot with the model sub-classing API. For the obvious reason Sub-Classing API doesn’t support Sequential or Functional API like model.summary() and nice visualization using plot_model. Here, I will demonstrate both. class my_model(keras.Model): def __init__(self, dim): super(my_model, self).__init__() self.Base = keras.keras.applications.VGG16( input_shape=(dim), include_top = False, weights=”imagenet” ) self.GAP = L.GlobalAveragePooling2D() self.BAT … Read more

What is the difference between keras and tf.keras?

The difference between tf.keras and keras is the Tensorflow specific enhancement to the framework. keras is an API specification that describes how a Deep Learning framework should implement certain part, related to the model definition and training. Is framework agnostic and supports different backends (Theano, Tensorflow, …) tf.keras is the Tensorflow specific implementation of the … Read more

How to fix “ResourceExhaustedError: OOM when allocating tensor”

OOM stands for “out of memory”. Your GPU is running out of memory, so it can’t allocate memory for this tensor. There are a few things you can do: Decrease the number of filters in your Dense, Conv2D layers Use a smaller batch_size (or increase steps_per_epoch and validation_steps) Use grayscale images (you can use tf.image.rgb_to_grayscale) … Read more