-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvisualization.py
More file actions
35 lines (24 loc) · 1.01 KB
/
visualization.py
File metadata and controls
35 lines (24 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import random
import matplotlib.pyplot as plt
from PIL import Image
# Replace with the actual path to your UTK dataset images folder
dataset_folder = '/home/ebrahim/Python_projects/projects/dataset/UTKface/'
def show_random_samples(num_samples=9):
image_files = os.listdir(dataset_folder)
selected_image_files = random.sample(image_files, num_samples)
plt.figure(figsize=(8, 8))
for idx, image_file in enumerate(selected_image_files, 1):
image_path = os.path.join(dataset_folder, image_file)
age, gender, ethnicity = image_file.split('_')[:3]
image = Image.open(image_path)
gender = 'Male' if int(gender) == 0 else 'Female'
ethnicity = ['White', 'Black', 'Asian', 'Indian', 'Others'][int(ethnicity)]
plt.subplot(3, 3, idx)
plt.imshow(image)
plt.title(f"Age: {age}\nGender: {gender}\nEthnicity: {ethnicity}")
plt.axis('off')
plt.tight_layout()
plt.show()
# Call the function to display random samples
show_random_samples()