Display a Selection of Images From Each Class in Jupyter
Python
In this example, a random two images will be displayed from each of the five classes. Each image is resized to 400x300 for displaying.
1| from IPython.display import Image, display 2| import pandas as pd 3| 4| PATH = 'data/raw/train_images/' 5| LABELS = [0,1,2,3,4] 6| IMAGES_PER_CLASS = 2 7| 8| #Contains image_id field which is the filename of the image 9| train = pd.read_csv('data/raw/train.csv') 10| 11| def show_images(row): 12| display(Image(filename=PATH + row['image_id'],width=400,height=300)) 13| 14| for label in LABELS: 15| print('Label:',label) 16| images = train[train['label']==label].sample(frac=1).iloc[0:IMAGES_PER_CLASS,:] 17| images.apply(show_images, axis=1)
133
121
117
109