-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaugment.py
More file actions
26 lines (23 loc) · 792 Bytes
/
augment.py
File metadata and controls
26 lines (23 loc) · 792 Bytes
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
import torchvision.transforms as transforms
import torchvision.utils as utils
import os
from PIL import Image
import numpy as np
def image_loader(loader, base):
for counter, [image, label] in enumerate(loader):
unorm_image = unorm(image)
save_data(unorm_image, label, base, counter)
def unorm(image):
image = utils.make_grid(image)
image = image / 2 + 0.5
# print(image.shape)
npimage = image.numpy()
npimage = np.transpose(npimage, (1, 2, 0))
print(npimage[0][0])
return npimage
def save_data(image, label, base, counter):
print(label.item())
path = os.path.join(base, str(label.item()))
os.makedirs(path, exist_ok = True)
im = Image.fromarray((image * 255).astype(np.uint8))
im.save(os.path.join(path,f"{counter}.png"))