Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras showing images from data generator

I am using image generator for keras like this:

val_generator = datagen.flow_from_directory(
        path+'/valid',
        target_size=(224, 224),
        batch_size=batch_size,)

x,y = val_generator.next()
for i in range(0,1):
    image = x[i]
    plt.imshow(image.transpose(2,1,0))
    plt.show()

This shows wrong colors: enter image description here

I have two questions.

  1. How to fix the problem

  2. How to get file names of the files (so that I can read it myself from something like matplotlib)

Edit : this is what my datagen looks like

datagen = ImageDataGenerator(
    rotation_range=3,
#     featurewise_std_normalization=True,
    fill_mode='nearest',
    width_shift_range=0.2,
    height_shift_range=0.2,
    horizontal_flip=True
)

Edit 2 :

After following Marcin's answer :

image = 255 - image

I get normal colors , but there are still some weird colors:

enter image description here

like image 761
harveyslash Avatar asked Jan 17 '17 11:01

harveyslash


People also ask

How many images does ImageDataGenerator generate?

There are a total of 1646 unique images in the dataset. Since these are not a lot of images to create a robust neural network, it will act as a great dataset to test the potential of the ImageDataGenerator class!

What does ImageDataGenerator return?

Then the "ImageDataGenerator" will produce 10 images in each iteration of the training. An iteration is defined as steps per epoch i.e. the total number of samples / batch_size. In above case, in each epoch of training there will be 100 iterations.


1 Answers

The dtype of your image array is 'float32', just convert it into 'uint8':

plt.imshow(image.astype('uint8'))
like image 171
in3omnia Avatar answered Oct 03 '22 17:10

in3omnia