Tensorflow ImageDataGenerator 'DirectoryIterator' object has no attribute 'shape'

If you are using Tensorflow 1.14.0 and ImageDataGenerator, then when fitting the generator to the model, this error appears:

AttributeError: 'DirectoryIterator' object has no attribute 'shape'

FIX

Enter

nano ~/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_generator.py

into the terminal and edit the problem line.

From:

# Convert to a format that supports `next(generator)`.
generator, steps_per_epoch = convert_to_generator_like(
     data,
     steps_per_epoch=steps_per_epoch,
     batch_size=batch_size,
     epochs=epochs - initial_epoch,
     shuffle=shuffle)

To:

generator = data
# Convert to a format that supports `next(generator)`.
# generator, steps_per_epoch = convert_to_generator_like(
#      data,
#      steps_per_epoch=steps_per_epoch,
#      batch_size=batch_size,
#      epochs=epochs - initial_epoch,
#      shuffle=shuffle)
H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center