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

octav(50)
Published in
#python
Words
31
Reading
1 min
Listen
Play
7y

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)
Tensorflow ImageDataGenerator 'DirectoryIterator' object has no att... | Ecency