# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

TRAIN_DIR = '../dataset/train'

import os

classes = os.listdir(TRAIN_DIR)
len(classes)

from operator import itemgetter

# +
most_populated_classes = {}

for training_class in classes:
    images = len(os.listdir(f"{TRAIN_DIR}/{training_class}"))
    most_populated_classes[training_class] = images
    
most_populated_classes = dict(sorted(most_populated_classes.items(), key=itemgetter(1), reverse=True))
# -

classes = list(most_populated_classes.keys())[:10]
classes

import matplotlib.pyplot as plt
# %matplotlib inline

from PIL import Image

from random import choice

# +
plt.figure(figsize=(20,10))

for index, training_class in enumerate(classes):
    available_images = os.listdir(f"{TRAIN_DIR}/{training_class}")
    img = Image.open(f"{TRAIN_DIR}/{training_class}/{choice(available_images)}")
    plt.subplot(2, 5, index+1)
    plt.xticks([])
    plt.yticks([])
    plt.grid(False)
    plt.imshow(img)
    plt.xlabel(training_class)

plt.savefig('../images/data.jpg', bbox_inches='tight', pad_inches=0)
plt.show()

StarcoderdataJupyterScriptsDedupFiltered