-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransformations.py
44 lines (36 loc) · 1.1 KB
/
Transformations.py
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
41
42
43
44
import PIL
import torchvision.transforms as transforms
import numpy as np
# 15 Objekte
MEAN = (0.62, 0.62, 0.62)
STD = (0.12, 0.12, 0.12)
def forward(x, resize, dim_input):
if resize:
transform = transforms.Compose([
transforms.Resize(dim_input[0]),
transforms.ToTensor(),
transforms.Normalize(MEAN, STD)
])
else:
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(MEAN, STD)
])
x = PIL.Image.fromarray(np.array(x * 255 / np.max(x))
.astype('uint8'))
x = transform(x)
return x
def forward2(x, resize, dim_input):
if resize:
transform = transforms.Compose([
transforms.Resize(dim_input[0]),
transforms.ToTensor()
])
else:
transform = transforms.Compose([
transforms.ToTensor()
])
x = PIL.Image.fromarray(np.array(x * 255 / np.max(x))
.astype('uint8'))
x = transform(x)
return x.squeeze(0)