Issue 1:
Tensorflow 1.11.0

Keras 2.2.4

Keras-Preprocessing 1.0.5

Ubuntu 16.04

Python 2.7.12

Example code:

from keras import models, layers
from keras_preprocessing.image import ImageDataGenerator
from keras_applications.imagenet_utils import preprocess_input

train_dir = '/tmp/workspace/Pet_Dataset/train/'
height, width, channels = (128, 128, 3)
batch_size=32

train_datagen = ImageDataGenerator(rescale=1.0/255)
train_generator = train_datagen.flow_from_directory(
train_dir, target_size=(height, width),
batch_size=batch_size, class_mode='categorical')

network = models.Sequential()
network.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(height, width, channels)))
network.add(layers.MaxPooling2D((2, 2)))
network.add(layers.Conv2D(64, (3, 3), activation='relu'))
network.add(layers.MaxPooling2D((2, 2)))
network.add(layers.Conv2D(128, (3, 3), activation='relu'))
network.add(layers.MaxPooling2D((2, 2)))
network.add(layers.Conv2D(256, (3, 3), activation='relu'))
network.add(layers.GlobalAveragePooling2D())
network.add(layers.Dense(train_generator.num_classes, activation='softmax'))

network.compile(optimizer='RMSProp',
loss='categorical_crossentropy',
metrics=['accuracy'])
network.summary()

history = network.fit_generator(train_generator, epochs=10)

breaks with Tensorflow 1.11.0 with ValueError: steps_per_epoch=None is only valid for a generator based on the keras.utils.Sequence class. Please specify steps_per_epoch or use the keras.utils.Sequence class..

Tensorflow 1.10.0 and below works.

Furthermore, providing steps_per_epoch and applying multiprocessing with workers > 1:

history = network.fit_generator(train_generator, epochs=10,
steps_per_epoch=train_generator.n/batch_size,
use_multiprocessing=True, workers=2)

causes a UserWarning about multiple workers duplicate data.

I think this is caused by wrong inheritance of ImageDataGenerator.

When printing the exact class that is used in keras_preprocessing/image.py, I get <class 'tensorflow.python.keras.utils.data_utils.Sequence'>.

But fit_generator() checks if the generator is a subclass of <class 'keras.utils.data_utils.Sequence'>, so it seems to assume that the ImageDataGenerator instance is not of type Sequence, causing above problems.

Issue 2:
I notice there is a difference in how images are pre-processed in the neural_style_transfer example and the recommended way of using VGG16 model. Specially,

The color channels in neural_style_transfer example is RGB (as read by scipy.misc.imread), whereas the order in original VGG is expected to be BGR.

The mean-centering step is not performed in the example, i.e.,

im[:,:,0] -= 103.939
im[:,:,1] -= 116.779
im[:,:,2] -= 123.68

Some of my experiments showed that these differences could result in sub-optimal results in image classification, e.g., red fox misclassified to grey fox due to the wrong order of color channel.

However, when it comes to generating "artistic" images as in the neural_style_transfer example, it seems that the results caused by the difference are not so different. I can understand there are probably some reasons behind this,

The "content loss" and "total variation loss" defined in the example don't depend on the order of color channels.

The "style loss" might depend on the color orders, because it depends on the difference of "styles" in the original and the generated image. And this style is measured by the inner-product distribution of different vgg filters (Gram matrix). However, it should be expected that most of vgg filters will be based on a mix of colors (e.g., edges, corners) rather than a single color alone (e.g, blue color for sea).

Those could be the reasons why I don't see many differences when experimenting with the different color channel encoding in the neural_style_transfer example. But I really want to know whether we can come up with some contrived cases where the different color channel order will result in a difference for the neural_style_transfer example.

I post this question here because it might lead to a potential bug report to the above example code.