0

I needed to convert my data generator based on Sequence to tf.data.Dataset format. For that purpose, I used the from_generator function to create repeating BatchedDataset for all my train, validation and testing data.

  dataset = tf.data.Dataset.from_generator(gen_function,
                                           output_signature=output_signature)
  dataset = dataset.shuffle(shuffle_buffer,
                            reshuffle_each_iteration=True)
  dataset = dataset.repeat()
  dataset = dataset.batch(batch_size)

These were used in the model fitting:

OCR.model.fit(x=training_generator,
              validation_data=validation_generator,
              steps_per_epoch=steps_per_epoch, 
              epochs=epochs,
              use_multiprocessing=True,
              callbacks=callbacks,
              workers=workers,
              verbose=verbose)

Which resulted in the following error:

    /user/.../python3.8/site-packages/tensorflow/python/keras/engine/data_adapter.py, 
    line 739, in _validate_args raise ValueError(
    ValueError: When providing an infinite dataset, you must specify the number of 
    steps to run (if you did not intend to create an infinite dataset, make sure to 
    not call `repeat()` on the dataset).
    [date time]: W tensorflow/core/kernels/data/generator_dataset_op.cc:107] Error 
    occurred when finalizing GeneratorDataset iterator: Failed precondition: Python 
    interpreter state is not initialized. The process may be terminated.
    >· [[{{node PyFunc}}]]

This was confusing because I specified the number of steps for my repeating infinite dataset as suggested. Moreover, it worked in this way with the steps_per_epoch specified in that way, when I used a Sequence-based data generator before.

1 Answer 1

0

The solution was simple, you just need to specify the validation_steps parameter, in addition to steps_per_epoch in the fit function.

2
  • excuse me i'm facing same problem but before this error i got ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type dict). 2021-06-30 20:08:00.122545: W tensorflow/core/kernels/data/generator_dataset_op.cc:107] Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated. does that mean i need to set validation_steps and steps_per_epoch ? as i set it likevalidation_steps =len(val_descriptions)
    – user
    Jun 30, 2021 at 18:54
  • I am not sure what exactly are you doing, I suggest you make a new question for this detailing your approach.
    – vcucu
    Jul 1, 2021 at 19:25

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.