1
$\begingroup$

I am trying to import a image dataset in Google Colab in order to do image classification. The dataset is in my Google drive, so I do the following:

from google.colab import drive
drive.mount('/content/drive')

now, i want to import my images and divide them into trainig set and test set, so I do the following:

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

batch_size = 32
train_datagen = ImageDataGenerator(
    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=(118, 224),
    color_mode="rgb",
    batch_size=batch_size,
    class_mode="categorical",
    shuffle=True
)

test_datagen = ImageDataGenerator(
    rescale = 1. / 255)

test_generator = test_datagen.flow_from_directory(
    directory=testset,
    target_size=(118, 224),
    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

classnames = [k for k,v in train_generator.class_indices.items()]

print("Image input %s" %str(input_shape))
print("Classes: %r" %classnames)

    print('Loaded %d training samples from %d classes.' % 
   (num_samples,num_classes))
     print('Loaded %d test samples from %d classes.' % 
    (test_generator.n,test_generator.num_classes))

but as output I get:

Found 0 images belonging to 0 classes.
Found 0 images belonging to 4 classes.
Image input (118, 224, 3)
Classes: []
Loaded 0 training samples from 0 classes.
Loaded 0 test samples from 4 classes.

so, it seems the dataset has not been uploaded. I think the problem is that the dataset is composed by zip files, in particular I have a dataset composed by moder zip files, and each of these contains images. The images are of four classes: Haze, Sunny, Snowy, Rainy. So are images of these four weathers.

To be more clear I can show the dyrectory:

enter image description here

I am really having troubles understanding how to operate. Can somebody please help me?

Thanks in advance.

$\endgroup$
  • 1
    $\begingroup$ I guess you need to place image files into the train/test folders (not zipped) $\endgroup$ – Peter Nov 26 '19 at 21:47
0
$\begingroup$

Based on Keras documentation here, flow_from_directory should contain one subdirectory per class. Any PNG, JPG, BMP, PPM or TIF images inside each of the subdirectories directory tree will be included in the generator. See this script for more details. That means you should probably unzip your zip files.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.