liuyizhang
commited on
Commit
β’
6e4c9f7
1
Parent(s):
91f6a3d
update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
|
|
|
|
|
|
|
2 |
import subprocess, io, os, sys, time
|
3 |
from loguru import logger
|
4 |
|
@@ -335,7 +338,7 @@ def run_grounded_sam(input_image, text_prompt, task_type, inpaint_prompt, box_th
|
|
335 |
return [], gr.Gallery.update(label='Please upload a image!ππππ')
|
336 |
|
337 |
file_temp = int(time.time())
|
338 |
-
logger.info(f'run_grounded_sam_[{file_temp}]_{task_type}_[{text_prompt}]
|
339 |
|
340 |
# load image
|
341 |
input_mask_pil = input_image['mask']
|
@@ -431,6 +434,7 @@ def run_grounded_sam(input_image, text_prompt, task_type, inpaint_prompt, box_th
|
|
431 |
mask_pil = input_mask_pil
|
432 |
mask = input_mask
|
433 |
else:
|
|
|
434 |
if inpaint_mode == 'merge':
|
435 |
masks = torch.sum(masks, dim=0).unsqueeze(0)
|
436 |
masks = torch.where(masks > 0, True, False)
|
@@ -452,7 +456,7 @@ def run_grounded_sam(input_image, text_prompt, task_type, inpaint_prompt, box_th
|
|
452 |
# remove from mask
|
453 |
if mask_source_radio == mask_source_segment:
|
454 |
mask_imgs = []
|
455 |
-
masks_shape =
|
456 |
boxes_filt_ori_array = boxes_filt_ori.numpy()
|
457 |
if inpaint_mode == 'merge':
|
458 |
extend_shape_0 = masks_shape[0]
|
@@ -462,7 +466,7 @@ def run_grounded_sam(input_image, text_prompt, task_type, inpaint_prompt, box_th
|
|
462 |
extend_shape_1 = 1
|
463 |
for i in range(extend_shape_0):
|
464 |
for j in range(extend_shape_1):
|
465 |
-
mask =
|
466 |
mask_pil = Image.fromarray(mask)
|
467 |
|
468 |
if remove_mode == 'segment':
|
@@ -477,7 +481,7 @@ def run_grounded_sam(input_image, text_prompt, task_type, inpaint_prompt, box_th
|
|
477 |
mask_pil_exp = mask_extend(copy.deepcopy(mask_pil).convert("RGB"),
|
478 |
xywh_to_xyxy(torch.tensor(boxes_filt_ori_array[i]), size[0], size[1]),
|
479 |
extend_pixels=remove_mask_extend, useRectangle=useRectangle)
|
480 |
-
mask_imgs.append(mask_pil_exp)
|
481 |
mask_pil = mix_masks(mask_imgs)
|
482 |
|
483 |
image_path = os.path.join(output_dir, f"image_mask_{file_temp}.jpg")
|
|
|
1 |
|
2 |
+
import warnings
|
3 |
+
warnings.filterwarnings('ignore')
|
4 |
+
|
5 |
import subprocess, io, os, sys, time
|
6 |
from loguru import logger
|
7 |
|
|
|
338 |
return [], gr.Gallery.update(label='Please upload a image!ππππ')
|
339 |
|
340 |
file_temp = int(time.time())
|
341 |
+
logger.info(f'run_grounded_sam_[{file_temp}]_{task_type}/{inpaint_mode}/[{mask_source_radio}]/{remove_mode}/{remove_mask_extend}_[{text_prompt}]/[{inpaint_prompt}]___1_')
|
342 |
|
343 |
# load image
|
344 |
input_mask_pil = input_image['mask']
|
|
|
434 |
mask_pil = input_mask_pil
|
435 |
mask = input_mask
|
436 |
else:
|
437 |
+
masks_ori = copy.deepcopy(masks)
|
438 |
if inpaint_mode == 'merge':
|
439 |
masks = torch.sum(masks, dim=0).unsqueeze(0)
|
440 |
masks = torch.where(masks > 0, True, False)
|
|
|
456 |
# remove from mask
|
457 |
if mask_source_radio == mask_source_segment:
|
458 |
mask_imgs = []
|
459 |
+
masks_shape = masks_ori.shape
|
460 |
boxes_filt_ori_array = boxes_filt_ori.numpy()
|
461 |
if inpaint_mode == 'merge':
|
462 |
extend_shape_0 = masks_shape[0]
|
|
|
466 |
extend_shape_1 = 1
|
467 |
for i in range(extend_shape_0):
|
468 |
for j in range(extend_shape_1):
|
469 |
+
mask = masks_ori[i][j].cpu().numpy()
|
470 |
mask_pil = Image.fromarray(mask)
|
471 |
|
472 |
if remove_mode == 'segment':
|
|
|
481 |
mask_pil_exp = mask_extend(copy.deepcopy(mask_pil).convert("RGB"),
|
482 |
xywh_to_xyxy(torch.tensor(boxes_filt_ori_array[i]), size[0], size[1]),
|
483 |
extend_pixels=remove_mask_extend, useRectangle=useRectangle)
|
484 |
+
mask_imgs.append(mask_pil_exp)
|
485 |
mask_pil = mix_masks(mask_imgs)
|
486 |
|
487 |
image_path = os.path.join(output_dir, f"image_mask_{file_temp}.jpg")
|