Skip to content
Advertisement

Reading Tensorflow Dataset changes bahaviour of `take()` and `skip()`

I am trying to inspect the labels inside my tensorflow dataset. However, the values of the labels change to something unexpected after using take() and skip(), depending on whether I inspect the data or not. (It looks like within the labels some ones changed to zeros.) I do not see any way that my inspection function could change the dataset. What am I missing?

To reproduce the behaviour, change the LOOK_AT_DATA_TWICE variable.

JavaScript

Output with LOOK_AT_DATA_TWICE = True:

JavaScript

Output with LOOK_AT_DATA_TWICE = False:

JavaScript

Advertisement

Answer

When the dataset is exhausted (i.e, after you iterated through it once), it will redo all the operations. In your case, because you are shuffling, the shuffle for the first epoch will be different than the shuffling for the second.

What it means is that your training set and testing set are actually not consistent between epochs.

You can set reshuffle_each_iteration to the call to shuffle to make the shuffle behave the same at each iteration. If you still want a different shuffle for your train set, you should call it again.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement