Reputation: 3125
I have batches of data in an iterator, here, using native Keras and nothing fancy:
batches = gen.flow_from_directory(path, target_size=(224,224), class_mode=class_mode, shuffle=shuffle, batch_size=batch_size)
.
which appears fine:
print batches:
keras.preprocessing.image.DirectoryIterator object at 0x7f107c004210\
But now I've compiled and I'm ready to fit
:
model.compile(optimizer=Adam(1e-5), loss='categorical_crossentropy',
metrics=['accuracy'])
.
model.fit(batches, val_batches, nb_epoch=1)
but I keep getting:
Exception: Error when checking model input: data should be a Numpy array, or list/dict of Numpy arrays. Found: <keras.preprocessing.image.DirectoryIterator object at 0x7f107c004210>...
No Keras doesn't like that I'm using an iterator? Why can't I fit using an iterator? I thought that's the whole point -- don't eat up all your memory, instead use some kind of batch iterator.
Upvotes: 2
Views: 2618
Reputation: 4159
fit
method expects its input to be a Numpy array or list of Numpy array. You should use fit_generator
instead, which takes a generator as its argument.
model.fit_generator(generator=batches,
validation_data=val_batches,
nb_epoch=1)
Upvotes: 3