[Chap 16] TypeError: '_NestedVariant' object is not subscriptable
In chapter 16 notebook running this cell:
batch_size = 32
dataset = dataset.shuffle(10000).batch(batch_size)
dataset = dataset.map(lambda windows: (windows[:, :-1], windows[:, 1:]))
produces this error in Colab:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-22-58d8a4056e3e> in <module>()
6 batch_size = 32
7 dataset = dataset.shuffle(10000).batch(batch_size)
----> 8 dataset = dataset.map(lambda windows: (windows[:, :-1], windows[:, 1:]))
10 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/autograph/impl/api.py in wrapper(*args, **kwargs)
256 except Exception as e: # pylint:disable=broad-except
257 if hasattr(e, 'ag_error_metadata'):
--> 258 raise e.ag_error_metadata.to_exception(e)
259 else:
260 raise
TypeError: in user code:
<ipython-input-15-6240017d8f77>:8 None *
dataset = dataset.map(lambda windows: (windows[:, :-1], windows[:, 1:]))
TypeError: '_NestedVariant' object is not subscriptable
I can't reproduce your error.
Hi @lucacox ,
I can't reproduce the error either. Could you please make sure you're using the latest versions of the code and the libraries and try again? You can find the instructions to update these here.
The solution of your problem is to run whole script from the begining, or just restart the kernel (clear workspace if working in jupyter lab or jupyter notebook).
The issue occures when you run lines BETWEEN
train_size = dataset_size * 90 // 100
dataset = tf.data.Dataset.from_tensor_slices(encoded[:train_size])
AND
batch_size = 32
dataset = dataset.shuffle(10000).batch(batch_size)
dataset = dataset.map(lambda windows: (windows[:, :-1], windows[:, 1:]))
more than once.
Thanks. Rerunning the entire script from the beginning helps.