OriLib commited on
Commit
70974c3
1 Parent(s): 7118259

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -57,9 +57,10 @@ def process(image):
57
  print(type(image))
58
  print(image.shape)
59
  orig_image = Image.fromarray(image)
60
- return [orig_image,orig_image]
61
  w,h = orig_im_size = orig_image.size
62
  image = resize_image(orig_image)
 
63
  im_np = np.array(image)
64
  im_tensor = torch.tensor(im_np, dtype=torch.float32).permute(2,0,1)
65
  im_tensor = torch.unsqueeze(im_tensor,0)
@@ -67,24 +68,25 @@ def process(image):
67
  im_tensor = normalize(im_tensor,[0.5,0.5,0.5],[1.0,1.0,1.0])
68
  if torch.cuda.is_available():
69
  im_tensor=im_tensor.cuda()
70
-
 
71
  #inference
72
  result=net(im_tensor)
73
-
74
  # post process
75
  result = torch.squeeze(F.interpolate(result[0][0], size=(h,w), mode='bilinear') ,0)
76
  ma = torch.max(result)
77
  mi = torch.min(result)
78
  result = (result-mi)/(ma-mi)
79
-
80
- # save result
81
  im_array = (result*255).cpu().data.numpy().astype(np.uint8)
82
  pil_im = Image.fromarray(np.squeeze(im_array))
83
  # paste the mask on the original image
84
  new_im = Image.new("RGBA", pil_im.size, (0,0,0))
85
  new_im.paste(orig_image, mask=pil_im)
86
 
87
- return [new_im]
88
 
89
 
90
  # block = gr.Blocks().queue()
 
57
  print(type(image))
58
  print(image.shape)
59
  orig_image = Image.fromarray(image)
60
+ # return [orig_image,orig_image]
61
  w,h = orig_im_size = orig_image.size
62
  image = resize_image(orig_image)
63
+ print("process debug1")
64
  im_np = np.array(image)
65
  im_tensor = torch.tensor(im_np, dtype=torch.float32).permute(2,0,1)
66
  im_tensor = torch.unsqueeze(im_tensor,0)
 
68
  im_tensor = normalize(im_tensor,[0.5,0.5,0.5],[1.0,1.0,1.0])
69
  if torch.cuda.is_available():
70
  im_tensor=im_tensor.cuda()
71
+
72
+ print("process debug2")
73
  #inference
74
  result=net(im_tensor)
75
+ print("process debug3")
76
  # post process
77
  result = torch.squeeze(F.interpolate(result[0][0], size=(h,w), mode='bilinear') ,0)
78
  ma = torch.max(result)
79
  mi = torch.min(result)
80
  result = (result-mi)/(ma-mi)
81
+ print("process debug4")
82
+ # image to pil
83
  im_array = (result*255).cpu().data.numpy().astype(np.uint8)
84
  pil_im = Image.fromarray(np.squeeze(im_array))
85
  # paste the mask on the original image
86
  new_im = Image.new("RGBA", pil_im.size, (0,0,0))
87
  new_im.paste(orig_image, mask=pil_im)
88
 
89
+ return [orig_image, new_im]
90
 
91
 
92
  # block = gr.Blocks().queue()