text_plain_output_1.png
from torch.utils.data import Dataset, DataLoader

import matplotlib.pyplot as plt

import numpy as np

import os

import pandas as pd

root = '../input/104-flowers-garden-of-eden'
train_df = pd.DataFrame()
folder = os.listdir(root)
for f in folder:
    classes = os.listdir(os.path.join(root, f, 'train'))
    for c in classes:
        images = os.listdir(os.path.join(root, f, 'train', c))
        tmp_df = pd.DataFrame(images, columns=['image_name'])
        tmp_df['class'] = c
        tmp_df['folder'] = f
        tmp_df['type'] = 'train'
        train_df = train_df.append(tmp_df, ignore_index=True)
val_df = pd.DataFrame()
folder = os.listdir(root)
for f in folder:
    classes = os.listdir(os.path.join(root, f, 'val'))
    for c in classes:
        images = os.listdir(os.path.join(root, f, 'val', c))
        tmp_df = pd.DataFrame(images, columns=['image_name'])
        tmp_df['class'] = c
        tmp_df['folder'] = f
        tmp_df['type'] = 'val'
        val_df = val_df.append(tmp_df, ignore_index=True)

test_df = pd.DataFrame()
f = 'jpeg-224x224'
images = os.listdir(os.path.join(root, f, 'test'))
tmp_df = pd.DataFrame(images, columns=['image_name'])
tmp_df['class'] = 'unknown'
tmp_df['folder'] = f
tmp_df['type'] = 'test'
test_df = test_df.append(tmp_df, ignore_index=True)

train_dataset = flowerDataset(train_df)
print(train_dataset.__len__())
train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True, drop_last=True)
train_iter = iter(train_loader)
images, labels = next(train_iter)
print(images.size())
print(labels.size())
plot_size = 32
fig = plt.figure(figsize=(25, 10))
for idx in np.arange(plot_size):
    ax = fig.add_subplot(4, plot_size / 4, idx + 1, xticks=[], yticks=[])
    ax.imshow(np.transpose(images[idx], (1, 2, 0)))
    ax.set_title(classes[labels[idx].item()])