Lesson 2 - Doubt: Getting distribution of classes from ImageDataBunch

Hi,

For Deep learning Part 1: Lesson 2, I created my own dataset for a classification problem. I scrolled through the google images results page and used the Javascript code snippet to get the URLs of the images and used the download_images function to create the dataset.

Is there a way to get the distribution of the classes from the ImageDataBunch object, i.e the number of images under each class? I looked through the documentation but wasn’t able to find anything regarding this. I might be missing something very basic here, but I’m new to FastAI and Python in general, please help. Thanks!

Maybe something like this.

y = data.train_ds.y
classes = [str(y.reconstruct(c)) for c in np.arange(y.c)]
plt.figure(figsize = (15,15))
plt.hist(y.items, bins = y.c, width = 0.9)
r= plt.xticks(ticks=np.arange(y.c), labels = classes, rotation =90)
2 Likes

Thank you!