-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcds.py
More file actions
40 lines (31 loc) · 1 KB
/
Copy pathcds.py
File metadata and controls
40 lines (31 loc) · 1 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
36
37
38
39
40
# This is the driver file
from imports import random, Image, plt, torch, v2
from tool_functions import get_images
from parameters import *
# Download images
#get_images()
# Get all image paths
image_path_list = list(IMAGE_PATH.glob("*/*/*.jpg"))
# Pick a random image path
random_image_path = random.choice(image_path_list)
print(random_image_path)
# Get the image class name using pathlib.Path.parent.stem
image_class = random_image_path.parent.stem
# Open image with Python's pillow (PIL fork)
img = Image.open(random_image_path)
# Show the image and print metadata
plt.imshow(img)
plt.title(f"Image class: {image_class}")
plt.axis(False) # hide axes
plt.show()
print(f"Random image path: {random_image_path}")
print(f"Image class: {image_class}")
print(f"Image height: {img.height}")
print(f"Image width: {img.width}")
data_transform = v2.Compose([
v2.ToImage(),
v2.Resize(size=(64, 64)),
v2.RandomHorizontalFlip(p=0.5),
v2.ToDtype(torch.float32, scale=True)
])
print(data_transform(img).shape)