Skip to content

Commit

Permalink
Enable the switch for print out segement only to accomdate open-mmlab…
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhen-dev committed Dec 12, 2023
1 parent cbf9af1 commit 9419177
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion demo/image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def main():
help='Opacity of painted segmentation map. In (0, 1] range.')
parser.add_argument(
'--title', default='result', help='The image identifier.')
parser.add_argument(
'--segementation-only',
action='store_true',
help='Only show the segmentation map.')
args = parser.parse_args()

# build the model from a config file and a checkpoint file
Expand All @@ -38,7 +42,8 @@ def main():
opacity=args.opacity,
draw_gt=False,
show=False if args.out_file is not None else True,
out_file=args.out_file)
out_file=args.out_file,
segmentation_only=args.segementation_only)


if __name__ == '__main__':
Expand Down
4 changes: 3 additions & 1 deletion mmseg/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def show_result_pyplot(model: BaseSegmentor,
wait_time: float = 0,
show: bool = True,
withLabels: Optional[bool] = True,
segmentation_only: bool = False,
save_dir=None,
out_file=None):
"""Visualize the segmentation results on the image.
Expand Down Expand Up @@ -170,7 +171,8 @@ def show_result_pyplot(model: BaseSegmentor,
visualizer = SegLocalVisualizer(
vis_backends=[dict(type='LocalVisBackend')],
save_dir=save_dir,
alpha=opacity)
alpha=opacity,
segement_only=segmentation_only)
visualizer.dataset_meta = dict(
classes=model.dataset_meta['classes'],
palette=model.dataset_meta['palette'])
Expand Down
5 changes: 4 additions & 1 deletion mmseg/visualization/local_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ def __init__(self,
palette: Optional[List] = None,
dataset_name: Optional[str] = None,
alpha: float = 0.8,
segement_only: bool = False,
**kwargs):
super().__init__(name, image, vis_backends, save_dir, **kwargs)
self.alpha: float = alpha
if segement_only:
self.alpha = 1
self.set_dataset_meta(palette, classes, dataset_name)

def _get_center_loc(self, mask: np.ndarray) -> np.ndarray:
Expand Down Expand Up @@ -139,7 +142,7 @@ def _draw_sem_seg(self,
for label, color in zip(labels, colors):
mask[sem_seg[0] == label, :] = color

if withLabels:
if withLabels and not self.segement_only:
font = cv2.FONT_HERSHEY_SIMPLEX
# (0,1] to change the size of the text relative to the image
scale = 0.05
Expand Down

0 comments on commit 9419177

Please sign in to comment.