redmlr
redmlr

Reputation: 45

Length for attr 'output_shapes' of 0 must be at least minimum 1

Whenever I try to convert my list of strings into a tf.Dataset object it outputs me this error.

tensorflow.python.framework.errors_impl.InvalidArgumentError: Length for attr 'output_shapes' of 0 must be at least minimum 1
    ; NodeDef: {{node ParallelMapDatasetV2}}; Op<name=ParallelMapDatasetV2; signature=input_dataset:variant, other_arguments:, num_parallel_calls:int64 -> handle:variant; attr=f:func; attr=Targuments:list(type),min=0; attr=output_types:list(type),min=1; attr=output_shapes:list(shape),min=1; attr=use_inter_op_parallelism:bool,default=true; attr=deterministic:string,default="default"; attr=preserve_cardinality:bool,default=false> [Op:ParallelMapDatasetV2]

The code is:

just_train_filenames = tf.ragged.constant([batch[0] for batch in train_list])

tf_train_ds = tf.data.Dataset.from_generator(
    lambda: just_train_filenames,
    output_signature=(tf.Tensor(shape=(1, None), tf.string))
)

Upvotes: 1

Views: 3496

Answers (1)

ariel6653
ariel6653

Reputation: 136

Had the same issue with Dataset.map function. Your lambda function needs to have a return value.

The output_shapes is the output_shape of the lambda function in this case, which is 0 because the function returns no value.

In your case of from_generator the lambda needs to returns an object that has iterator.

from tensorflow docs: https://www.tensorflow.org/api_docs/python/tf/data/Dataset#from_generator

The generator argument must be a callable object that returns an object that supports the iter() protocol (e.g. a generator function).

The elements generated by generator must be compatible with either the given output_signature argument or with the given output_types and (optionally) output_shapes arguments, whichiver was specified.

Upvotes: 5

Related Questions