Update app.py
Browse files
app.py
CHANGED
|
@@ -44,7 +44,26 @@ def denormalize(x, mean=(0., 0., 0.), std=(1.0, 1.0, 1.0)):
|
|
| 44 |
|
| 45 |
return x
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
def nogan(input_img):
|
|
|
|
| 48 |
i = np.asarray(input_img)
|
| 49 |
i = i.astype("float32")
|
| 50 |
i = np.transpose(i, (2, 0, 1))
|
|
|
|
| 44 |
|
| 45 |
return x
|
| 46 |
|
| 47 |
+
def resize_image(input_image_path, size):
|
| 48 |
+
original_image = Image.open(input_image_path)
|
| 49 |
+
width, height = original_image.size
|
| 50 |
+
if max(width, height) > size:
|
| 51 |
+
if width > height:
|
| 52 |
+
ratio = width / size
|
| 53 |
+
new_height = int(height / ratio)
|
| 54 |
+
new_width = size
|
| 55 |
+
else:
|
| 56 |
+
ratio = height / size
|
| 57 |
+
new_width = int(width / ratio)
|
| 58 |
+
new_height = size
|
| 59 |
+
resized_image = original_image.resize((new_width, new_height), Image.ANTIALIAS)
|
| 60 |
+
return resized_image
|
| 61 |
+
else:
|
| 62 |
+
return original_image
|
| 63 |
+
|
| 64 |
+
|
| 65 |
def nogan(input_img):
|
| 66 |
+
input_img = resize_image(input_img, 1024)
|
| 67 |
i = np.asarray(input_img)
|
| 68 |
i = i.astype("float32")
|
| 69 |
i = np.transpose(i, (2, 0, 1))
|