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:
I am really having troubles understanding how to operate. Can somebody please help me?
Thanks in advance.