Solved by markdaoust in post #7 
              
              
                Ah, yes that could use a little more explanation. 
tf.data and tf.function (also used in keras) use TensorFlow’s 2-stage process. First it builds the graph, and then it executes the graph on your tensors. 
Tensor.shape is the shape that was determined at graph build time (tf.shape(tensor) gets you …