Spaces:
Build error
Build error
秋山翔
commited on
Commit
·
02038d4
1
Parent(s):
11c3557
MAINT: catch all before sleeping to avoid downtime
Browse files
app.py
CHANGED
|
@@ -67,29 +67,32 @@ def get_model(style):
|
|
| 67 |
|
| 68 |
|
| 69 |
def inference(img, style):
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
|
| 95 |
title = "Anime Background GAN"
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
def inference(img, style):
|
| 70 |
+
try:
|
| 71 |
+
# load image
|
| 72 |
+
input_image = img.convert(COLOUR_MODEL)
|
| 73 |
+
input_image = np.asarray(input_image)
|
| 74 |
+
# RGB -> BGR
|
| 75 |
+
input_image = input_image[:, :, [2, 1, 0]]
|
| 76 |
+
input_image = transforms.ToTensor()(input_image).unsqueeze(0)
|
| 77 |
+
# preprocess, (-1, 1)
|
| 78 |
+
input_image = -1 + 2 * input_image
|
| 79 |
+
|
| 80 |
+
if disable_gpu:
|
| 81 |
+
input_image = Variable(input_image).float()
|
| 82 |
+
else:
|
| 83 |
+
input_image = Variable(input_image).cuda()
|
| 84 |
+
|
| 85 |
+
# forward
|
| 86 |
+
model = get_model(style)
|
| 87 |
+
output_image = model(input_image)
|
| 88 |
+
output_image = output_image[0]
|
| 89 |
+
# BGR -> RGB
|
| 90 |
+
output_image = output_image[[2, 1, 0], :, :]
|
| 91 |
+
output_image = output_image.data.cpu().float() * 0.5 + 0.5
|
| 92 |
+
|
| 93 |
+
return transforms.ToPILImage()(output_image)
|
| 94 |
+
except:
|
| 95 |
+
logger.error(f"Error while processing image {img}")
|
| 96 |
|
| 97 |
|
| 98 |
title = "Anime Background GAN"
|