Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
@@ -6,13 +6,6 @@ import numpy as np
|
|
6 |
mean = [0.4763, 0.4507, 0.4094]
|
7 |
std = [0.2702, 0.2652, 0.2811]
|
8 |
|
9 |
-
def load_image(filename, size=None):
|
10 |
-
img = Image.open(filename).convert('RGB')
|
11 |
-
if size is not None:
|
12 |
-
img = img.resize((size, size), Image.ANTIALIAS)
|
13 |
-
return img
|
14 |
-
|
15 |
-
|
16 |
class UnNormalize(object):
|
17 |
def __init__(self, mean, std):
|
18 |
self.mean = mean
|
@@ -39,16 +32,3 @@ def deprocess(image_tensor):
|
|
39 |
image_np = torch.clamp(img, 0, 255).numpy().astype(np.uint8)
|
40 |
image_np = image_np.transpose(1, 2, 0)
|
41 |
return image_np
|
42 |
-
|
43 |
-
def save_image(filename, data):
|
44 |
-
img = deprocess(data)
|
45 |
-
img = Image.fromarray(img)
|
46 |
-
img.save(filename)
|
47 |
-
|
48 |
-
|
49 |
-
def gram_matrix(y):
|
50 |
-
(b, ch, h, w) = y.size()
|
51 |
-
features = y.view(b, ch, w * h)
|
52 |
-
features_t = features.transpose(1, 2)
|
53 |
-
gram = features.bmm(features_t) / (ch * h * w)
|
54 |
-
return gram
|
|
|
6 |
mean = [0.4763, 0.4507, 0.4094]
|
7 |
std = [0.2702, 0.2652, 0.2811]
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
class UnNormalize(object):
|
10 |
def __init__(self, mean, std):
|
11 |
self.mean = mean
|
|
|
32 |
image_np = torch.clamp(img, 0, 255).numpy().astype(np.uint8)
|
33 |
image_np = image_np.transpose(1, 2, 0)
|
34 |
return image_np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|