The error arises because tensorflow cannot determine the tensor shapes explicitly. When using tf.data.Dataset.from_generator
, you should provide an output_signature
argument to explicitly define the shape and type of the output tensors. This allows tensorflow to properly handle the data.
Instead of using this:
ds = tf.data.Dataset.from_generator(generator,
output_types=({'LoB': tf.int32}, tf.float32))
Use this:
ds = tf.data.Dataset.from_generator(generator, output_signature=(
{'LoB': tf.TensorSpec(shape=(1,), dtype=tf.int32)},
tf.TensorSpec(shape=(1,), dtype=tf.float32)
))
please refer to this document for more details.