Spaces:
Runtime error
Runtime error
Update app.py
Browse files56 unmodified lines5758596061626364651 unmodified line67686970717273747576777879808182838485868788899056 unmodified linesprint(type(image))print(image.shape)orig_image = Image.fromarray(image)return [orig_image,orig_image]w,h = orig_im_size = orig_image.sizeimage = resize_image(orig_image)im_np = np.array(image)im_tensor = torch.tensor(im_np, dtype=torch.float32).permute(2,0,1)im_tensor = torch.unsqueeze(im_tensor,0)1 unmodified lineim_tensor = normalize(im_tensor,[0.5,0.5,0.5],[1.0,1.0,1.0])if torch.cuda.is_available():im_tensor=im_tensor.cuda()#inferenceresult=net(im_tensor)# post processresult = torch.squeeze(F.interpolate(result[0][0], size=(h,w), mode='bilinear') ,0)ma = torch.max(result)mi = torch.min(result)result = (result-mi)/(ma-mi)# save resultim_array = (result*255).cpu().data.numpy().astype(np.uint8)pil_im = Image.fromarray(np.squeeze(im_array))# paste the mask on the original imagenew_im = Image.new("RGBA", pil_im.size, (0,0,0))new_im.paste(orig_image, mask=pil_im)return [new_im]# block = gr.Blocks().queue()56 unmodified lines575859606162636465661 unmodified line6869707172737475767778798081828384858687888990919256 unmodified linesprint(type(image))print(image.shape)orig_image = Image.fromarray(image)# return [orig_image,orig_image]w,h = orig_im_size = orig_image.sizeimage = resize_image(orig_image)print("process debug1")im_np = np.array(image)im_tensor = torch.tensor(im_np, dtype=torch.float32).permute(2,0,1)im_tensor = torch.unsqueeze(im_tensor,0)1 unmodified lineim_tensor = normalize(im_tensor,[0.5,0.5,0.5],[1.0,1.0,1.0])if torch.cuda.is_available():im_tensor=im_tensor.cuda()print("process debug2")#inferenceresult=net(im_tensor)print("process debug3")# post processresult = torch.squeeze(F.interpolate(result[0][0], size=(h,w), mode='bilinear') ,0)ma = torch.max(result)mi = torch.min(result)result = (result-mi)/(ma-mi)print("process debug4")# image to pilim_array = (result*255).cpu().data.numpy().astype(np.uint8)pil_im = Image.fromarray(np.squeeze(im_array))# paste the mask on the original imagenew_im = Image.new("RGBA", pil_im.size, (0,0,0))new_im.paste(orig_image, mask=pil_im)return [orig_image, new_im]# block = gr.Blocks().queue()
app.py+8-6