text_plain_output_2.png text_plain_output_1.png
import matplotlib.pyplot as plt

import os

import pandas as pd

import pathlib

data_path = pathlib.Path('../input/a-large-scale-fish-dataset/Fish_Dataset/Fish_Dataset')

all_images = list(data_path.glob('*/*/*.jpg')) + list(data_path.glob('*/*/*.png'))
images = []
labels = []
for item in all_images:
    path = os.path.normpath(item)
    splits = path.split(os.sep)
    if 'GT' not in splits[-2]:
        images.append(item)
        label = splits[-2]
        labels.append(label)

image_pathes = pd.Series(images).astype(str)
labels = pd.Series(labels)
dataframe = pd.concat([image_pathes, labels], axis=1)
dataframe.columns = ['images', 'labels']

fig, axes = plt.subplots(nrows=3, ncols=5, figsize=(15, 10), subplot_kw={'xticks': [], 'yticks': []})
for i, ax in enumerate(axes.flat):
    ax.imshow(plt.imread(dataframe.images[i]))
    ax.set_title(dataframe.labels[i])
plt.show()