Spaces:
Runtime error
Runtime error
app fixed
Browse files
app.py
CHANGED
@@ -44,6 +44,27 @@ def tensor01_to_pil(xt):
|
|
44 |
r = transforms.ToPILImage(mode='RGB')(xt.squeeze())
|
45 |
return r
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
def predict(img):
|
49 |
"""
|
@@ -56,7 +77,7 @@ def predict(img):
|
|
56 |
|
57 |
img = Image.fromarray(np.array(img))
|
58 |
img = lr_transforms(img)
|
59 |
-
lr_tensor =
|
60 |
|
61 |
xLR = lr_tensor.to(device).unsqueeze(0)
|
62 |
xLR = xLR.type(dtype)
|
|
|
44 |
r = transforms.ToPILImage(mode='RGB')(xt.squeeze())
|
45 |
return r
|
46 |
|
47 |
+
def image2tensor(image: np.ndarray, range_norm: bool, half: bool) -> torch.Tensor:
|
48 |
+
"""Convert ``PIL.Image`` to Tensor.
|
49 |
+
Args:
|
50 |
+
image (np.ndarray): The image data read by ``PIL.Image``
|
51 |
+
range_norm (bool): Scale [0, 1] data to between [-1, 1]
|
52 |
+
half (bool): Whether to convert torch.float32 similarly to torch.half type.
|
53 |
+
Returns:
|
54 |
+
Normalized image data
|
55 |
+
Examples:
|
56 |
+
>>> image = Image.open("image.bmp")
|
57 |
+
>>> tensor_image = image2tensor(image, range_norm=False, half=False)
|
58 |
+
"""
|
59 |
+
tensor = F.to_tensor(image)
|
60 |
+
|
61 |
+
if range_norm:
|
62 |
+
tensor = tensor.mul_(2.0).sub_(1.0)
|
63 |
+
if half:
|
64 |
+
tensor = tensor.half()
|
65 |
+
|
66 |
+
return tensor
|
67 |
+
|
68 |
|
69 |
def predict(img):
|
70 |
"""
|
|
|
77 |
|
78 |
img = Image.fromarray(np.array(img))
|
79 |
img = lr_transforms(img)
|
80 |
+
lr_tensor = image2tensor(img, range_norm=False, half=False)
|
81 |
|
82 |
xLR = lr_tensor.to(device).unsqueeze(0)
|
83 |
xLR = xLR.type(dtype)
|