秋山翔 commited on
Commit
02038d4
·
1 Parent(s): 11c3557

MAINT: catch all before sleeping to avoid downtime

Browse files
Files changed (1) hide show
  1. app.py +26 -23
app.py CHANGED
@@ -67,29 +67,32 @@ def get_model(style):
67
 
68
 
69
  def inference(img, style):
70
- # load image
71
- input_image = img.convert(COLOUR_MODEL)
72
- input_image = np.asarray(input_image)
73
- # RGB -> BGR
74
- input_image = input_image[:, :, [2, 1, 0]]
75
- input_image = transforms.ToTensor()(input_image).unsqueeze(0)
76
- # preprocess, (-1, 1)
77
- input_image = -1 + 2 * input_image
78
-
79
- if disable_gpu:
80
- input_image = Variable(input_image).float()
81
- else:
82
- input_image = Variable(input_image).cuda()
83
-
84
- # forward
85
- model = get_model(style)
86
- output_image = model(input_image)
87
- output_image = output_image[0]
88
- # BGR -> RGB
89
- output_image = output_image[[2, 1, 0], :, :]
90
- output_image = output_image.data.cpu().float() * 0.5 + 0.5
91
-
92
- return transforms.ToPILImage()(output_image)
 
 
 
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"