Fix TensorArray Tried to write to index 28 but array is not resizeable and size is: 28 Error – TensorFlow Tutorial

By | June 6, 2020

We plan to create a customized LSTM model, TensorArray is used in this model. However, when training our model, TensorArray Tried to write to index 28 but array is not resizeable and size is: 28 error occured. In this tutorial, we will introduce you how to fix this problem.

fix TensorArray tried to write to index 28 but array is not resizeable and size is 28

How to fix this TensorArray write error?

We used TensorArray object in our code like this:

gen_o = tf.TensorArray(dtype=tf.float32, size= 0, clear_after_read = False, dynamic_size=True, infer_shape=True)

dynamic_size = True, which means the size of TensorArray is changed dynamically. When you insert a tensor into TensorArray, TensorFlow will allocate space to save it. If tensorflow fail to allocate space, this error will occur.

Meanwhile, clear_after_read = False, which mean we will make gen_o TensorArray object exit all time, it can not be destroyed by tensorflow.

In order to fix this error, you can do:

1.The simplest way is to close TensorArray, here is an example:

gen_o.close()

2.Make your memory space large

3.Make a smaller batch size to train model.

For example, set batch_size = 32

Leave a Reply