Skip to content

Commit

Permalink
fix #41
Browse files Browse the repository at this point in the history
  • Loading branch information
hkchengrex committed Feb 17, 2024
1 parent a1e0af1 commit 5e022e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions gui/TIPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Reset memory if needed.
- Use middle-click to toggle visualization target (for layered, popout, and binary mask export).
- Use number keys or the spinbox to change the object to be operated on. If it does not respond, most likely the correct number of objects was not specified during program startup.
- "Export as video" only aggregates visualizations that are saved on disks. You need to check "save overlay" for that to happen.
- Soft masks are only saved for the "propagated" frames, not for the interacted frames. To save all frames, utilize forward and backward propagation
- Exported binary/soft masks can be used in other applications like ProPainter. Note inpainting prefer over-segmentation over under-segmentation -- use a larger dilation radius if needed
- Memory can be corrupted by bad segmentations. Make good use of "reset memory" and do not commit bad segmentations.
- The "layered" visualization mode inserts an RGBA layer between the foreground and the background. Use "import layer" to select a new layer.
Expand Down
13 changes: 8 additions & 5 deletions gui/main_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@


class MainController():

def __init__(self, cfg: DictConfig) -> None:
super().__init__()

Expand Down Expand Up @@ -209,24 +210,25 @@ def compose_current_im(self):
def update_canvas(self):
self.gui.set_canvas(self.vis_image)

def update_current_image_fast(self):
def update_current_image_fast(self, do_no_save_soft_mask: bool = False):
# fast path, uses gpu. Changes the image in-place to avoid copying
# thus current_image_torch must be voided afterwards
# do_no_save_soft_mask is an override to solve #41
self.vis_image = get_visualization_torch(self.vis_mode, self.curr_image_torch,
self.curr_prob, self.overlay_layer_torch,
self.vis_target_objects)
self.curr_image_torch = None
self.vis_image = np.ascontiguousarray(self.vis_image)
if self.save_visualization:
self.res_man.save_visualization(self.curr_ti, self.vis_mode, self.vis_image)
if self.save_soft_mask:
if self.save_soft_mask and not do_no_save_soft_mask:
self.res_man.save_soft_mask(self.curr_ti, self.curr_prob.cpu().numpy())
self.gui.set_canvas(self.vis_image)

def show_current_frame(self, fast: bool = False):
def show_current_frame(self, fast: bool = False, do_no_save_soft_mask: bool = False):
# Re-compute overlay and show the image
if fast:
self.update_current_image_fast()
self.update_current_image_fast(do_no_save_soft_mask)
else:
self.compose_current_im()
if self.save_visualization:
Expand Down Expand Up @@ -301,7 +303,8 @@ def on_propagate(self):
# clear
self.interacted_prob = None
self.reset_this_interaction()
self.show_current_frame(fast=True)
# override this for #41
self.show_current_frame(fast=True, do_no_save_soft_mask=True)

self.propagating = True
self.gui.clear_all_mem_button.setEnabled(False)
Expand Down

0 comments on commit 5e022e6

Please sign in to comment.