Spaces:
Running
on
Zero
Running
on
Zero
ZhengPeng7
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -29,6 +29,14 @@ class ImagePreprocessor():
|
|
29 |
return image
|
30 |
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
model = GCoNet(bb_pretrained=False).to(device)
|
33 |
state_dict = './ultimate_duts_cocoseg (The best one).pth'
|
34 |
if os.path.exists(state_dict):
|
@@ -71,9 +79,8 @@ def pred_maps(images):
|
|
71 |
for image_shape, pred_tensor, save_path in zip(image_shapes, scaled_preds_tensor, save_paths):
|
72 |
if device == 'cuda':
|
73 |
pred_tensor = pred_tensor.cpu()
|
74 |
-
pred_tensor = torch.nn.functional.interpolate(pred_tensor.unsqueeze(0), size=image_shape, mode='bilinear', align_corners=True).squeeze()
|
75 |
-
|
76 |
-
cv2.imwrite(save_path, pred_tensor)
|
77 |
|
78 |
zip_file_path = os.path.join(save_dir, "{}.zip".format(save_dir))
|
79 |
with zipfile.ZipFile(zip_file_path, 'w') as zipf:
|
@@ -82,9 +89,6 @@ def pred_maps(images):
|
|
82 |
return save_paths, zip_file_path
|
83 |
|
84 |
|
85 |
-
# N = 4
|
86 |
-
# examples = [[_] for _ in glob('example_images/butterfly/*')][:N]
|
87 |
-
|
88 |
tab_batch = gr.Interface(
|
89 |
fn=pred_maps,
|
90 |
inputs=gr.File(label="Upload multiple images in a group", type="filepath", file_count="multiple"),
|
|
|
29 |
return image
|
30 |
|
31 |
|
32 |
+
def save_tensor_img(path, tenor_im):
|
33 |
+
im = tenor_im.cpu().clone()
|
34 |
+
im = im.squeeze(0)
|
35 |
+
tensor2pil = transforms.ToPILImage()
|
36 |
+
im = tensor2pil(im)
|
37 |
+
im.save(path)
|
38 |
+
|
39 |
+
|
40 |
model = GCoNet(bb_pretrained=False).to(device)
|
41 |
state_dict = './ultimate_duts_cocoseg (The best one).pth'
|
42 |
if os.path.exists(state_dict):
|
|
|
79 |
for image_shape, pred_tensor, save_path in zip(image_shapes, scaled_preds_tensor, save_paths):
|
80 |
if device == 'cuda':
|
81 |
pred_tensor = pred_tensor.cpu()
|
82 |
+
pred_tensor = torch.nn.functional.interpolate(pred_tensor.unsqueeze(0), size=image_shape, mode='bilinear', align_corners=True).squeeze()
|
83 |
+
save_tensor_img(save_path, pred_tensor)
|
|
|
84 |
|
85 |
zip_file_path = os.path.join(save_dir, "{}.zip".format(save_dir))
|
86 |
with zipfile.ZipFile(zip_file_path, 'w') as zipf:
|
|
|
89 |
return save_paths, zip_file_path
|
90 |
|
91 |
|
|
|
|
|
|
|
92 |
tab_batch = gr.Interface(
|
93 |
fn=pred_maps,
|
94 |
inputs=gr.File(label="Upload multiple images in a group", type="filepath", file_count="multiple"),
|