How to solve warning : ImageDataGenerator specifies `featurewise_center`, but it hasn't been fit on any training data?

I am doing image classification and I have a training set and a test set with different distributions. So to try to overcome this problem I am using an Image generator in the following way:

trainingset = '/content/drive/My Drive/Colab Notebooks/Train'
testset = '/content/drive/My Drive/Colab Notebooks/Test'


batch_size = 32
train_datagen = ImageDataGenerator(
    featurewise_center=True,
    featurewise_std_normalization=True,
    rescale = 1. / 255,\
    zoom_range=0.1,\
    rotation_range=10,\
    width_shift_range=0.1,\
    height_shift_range=0.1,\
    horizontal_flip=True,\
    vertical_flip=False)

train_generator = train_datagen.flow_from_directory(
    directory=trainingset,
    target_size=(256, 256),
    color_mode="rgb",
    batch_size=batch_size,
    class_mode="categorical",
    shuffle=True
)


test_datagen = ImageDataGenerator(
    featurewise_center=True,
    featurewise_std_normalization=True,
    rescale = 1. / 255
   )



test_generator = test_datagen.flow_from_directory(
    directory=testset,
    #target_size=(256, 256),
    color_mode="rgb",
    batch_size=batch_size,
    class_mode="categorical",
    shuffle=False
)

num_samples = train_generator.n
num_classes = train_generator.num_classes
input_shape = train_generator.image_shape

So I use featurewise_center=True and featurewise_std_normalization=True, which by doing some research I have found that it should solve the problem, at least a little bit.

But then if I build my CNN and train it, I have the following warning:

I don't understand how to solve this, since if I try to do the fitting as said in the warning, it says me that I need a numpy array, while I have a string:

train_datagen.fit(trainingset)

I get:

    ValueError                                Traceback (most recent call last)
ipython-input-7-afd35f2bf342 in module()
     29     vertical_flip=False)
     30 
--- 31 train_datagen.fit(trainingset)
     32 
     33 train_generator = train_datagen.flow_from_directory(

1 frames
/usr/local/lib/python3.6/dist-packages/numpy/core/_asarray.py in asarray(a, 
dtype, order)
     83 
     84     """
--- 85     return array(a, dtype, copy=False, order=order)
     86 
     87 

ValueError: could not convert string to float: '/content/drive/My Drive/Colab 
 Notebooks/Train'

I have been stucking in this for days, but I don't understand how to solve this problem. Can somebody pleas help me? Thanks in advance.

Topic cnn keras neural-network machine-learning

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.