How do I disable TensorFlow’s eager execution?

Assume you are using Tensorflow 2.0 preview release which has eager execution enabled by default. There is a disable_eager_execution() in v1 API, which you can put in the front of your code like: import tensorflow as tf tf.compat.v1.disable_eager_execution() On the other hand, if you are not using 2.0 preview, please check if you accidentally enabled … Read more

In Keras, what exactly am I configuring when I create a stateful `LSTM` layer with N `units`?

You can check this question for further information, although it is based on Keras-1.x API. Basically, the unit means the dimension of the inner cells in LSTM. Because in LSTM, the dimension of inner cell (C_t and C_{t-1} in the graph), output mask (o_t in the graph) and hidden/output state (h_t in the graph) should … Read more

What does batch, repeat, and shuffle do with TensorFlow Dataset?

Update: Here is a small collaboration notebook for demonstration of this answer. Imagine, you have a dataset: [1, 2, 3, 4, 5, 6], then: How ds.shuffle() works dataset.shuffle(buffer_size=3) will allocate a buffer of size 3 for picking random entries. This buffer will be connected to the source dataset. We could image it like this: Random … Read more

Making predictions with a TensorFlow model

In the “Deep MNIST for Experts” example, see this line: We can now implement our regression model. It only takes one line! We multiply the vectorized input images x by the weight matrix W, add the bias b, and compute the softmax probabilities that are assigned to each class. y = tf.nn.softmax(tf.matmul(x,W) + b) Just … Read more

Higher validation accuracy, than training accurracy using Tensorflow and Keras

This happens when you use Dropout, since the behaviour when training and testing are different. When training, a percentage of the features are set to zero (50% in your case since you are using Dropout(0.5)). When testing, all features are used (and are scaled appropriately). So the model at test time is more robust – … Read more

How do display different runs in TensorBoard?

In addition to TensorBoard scanning subdirectories (so you can pass a directory containing the directories with your runs), you can also pass multiple directories to TensorBoard explicitly and give custom names (example taken from the –help output): tensorboard –logdir=name1:/path/to/logs/1,name2:/path/to/logs/2 More information can be found at the TensorBoard documentation. In recent versions of TensorBoard, aliasing this … Read more

On Windows, running “import tensorflow” generates No module named “_pywrap_tensorflow” error

The problem was the cuDNN Library for me – for whatever reason cudnn-8.0-windows10-x64-v6.0 was NOT working – I used cudnn-8.0-windows10-x64-v5.1 – ALL GOOD! My setup working with Win10 64 and the Nvidia GTX780M: Be sure you have the lib MSVCP140.DLL by checking your system/path – if not get it here Run the windows installer for … Read more

How to stack multiple lstm in keras?

You need to add return_sequences=True to the first layer so that its output tensor has ndim=3 (i.e. batch size, timesteps, hidden state). Please see the following example: # expected input data shape: (batch_size, timesteps, data_dim) model = Sequential() model.add(LSTM(32, return_sequences=True, input_shape=(timesteps, data_dim))) # returns a sequence of vectors of dimension 32 model.add(LSTM(32, return_sequences=True)) # returns … Read more