Why does TPU strategy.scope() change keras.model.fit()'s input data type?

Viewed 14

TPU strategy.scope seems to modify the data type of x in keras.model.fit().For example,

# Case 1
model = unet()
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])  
results = model.fit(train_X, train_Y, batch_size = 16, epochs = 100, validation_split=0.1, callbacks=callbacks)
>>> Starts training


# Case 2
with tpu_strategy.scope():
   model = unet()
   model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

results = model.fit(train_X, train_Y, batch_size = 16, epochs = 100, validation_split=0.1)    
>>>`validation_split` argument is not supported when input `x` is a dataset or a dataset iterator. Received: x=<BatchDataset element_spec=(TensorSpec(shape=(16, 128, 128, 3), dtype=tf.uint8, name=None), TensorSpec(shape=(16, 128, 128, 1), dtype=tf.bool, name=None))>, validation_split=0.100000

train_X is np.ndarray (16,128,128,3) so it's neither a dataset nor a dataset iterator. So, case 1 perfectly works. But for case 2 train_X becomes BatchDataset so the error occurs. Any insight why TPU-on behaves in that way?

0 Answers
Related