Tensorflow: tf.data.Dataset, Cannot batch tensors with different shapes in component 0

后端 未结 2 2155
暗喜
暗喜 2021-02-15 17:57

I have the following error in my input pipeline:

tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot batch tensors with different shape

2条回答
  •  暖寄归人
    2021-02-15 18:18

    What worked for me with tensorflow 2 :

    1) setting the repeat() function when creating the dataset, therefore replacing

    data = tf.data.Dataset.from_tensor_slices(x)
    

    by

    data = tf.data.Dataset.from_tensor_slices(x).repeat()
    

    B) Passing the steps/epoch parameter to the fit method, therefore replacing

    history = model.fit(dataset, epochs=EPOCHS, callbacks=[checkpoint_callback])
    

    by

    history = model.fit(dataset, epochs=EPOCHS, steps_per_epoch=data[0]/BUFFER_SIZE, callbacks=[checkpoint_callback])
    

提交回复
热议问题