1

I have a generator that yields three variables. The first two variables are the two inputs to a two-input Keras model (functional API). I am using TF-Dataset to feed my model. Code is as follows:


train_dataset = tf.data.Dataset.from_generator(generator=make_generator_train,
                                                   args=[train_x_paths, train_y_int],
                                                   output_types=(tf.tuple((tf.float16, tf.float16)), tf.int8),
                                                   output_shapes=(tf.TensorShape([2]),
                                                                  tf.TensorShape([1]))).batch(batch_size=batch_size)

I get a TypeError with this:

TypeError: If shallow structure is a sequence, input must also be a sequence. Input has type: <class 'tensorflow.python.framework.tensor_shape.TensorShape'>.

2 Answers 2

1

Try it like this:

train_dataset = tf.data.Dataset.from_generator(
        generator=make_generator_train,
       args=[train_x_paths, train_y_int],
       output_types=(tf.float16, tf.int8)
).batch(batch_size=batch_size)

Most of the time you don't need to specify the output_shapes. It is decided in the runtime. Additionally, you only need to specify the overall dtype of the output tensor in the output_types. Not a dtype for each individual tensor dimension.

Sign up to request clarification or add additional context in comments.

1 Comment

Skipping the output_shapes parameter did not fix it, I had to fix my generator instead. Thanks!
1

Solution: the generator should yield a dictionary for the inputs, and the output as is.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.