Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mask visualization bug #860

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions datumaro/components/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ def _get_wrapped_text():
context = defaultdict(list)
for ann in annotations:
if ann.type in self.ignored_types:
warnings.warn(f"{ann.type} in self.ignored_types. Skip it.")
ignore_type = AnnotationType(ann.type).name
msg = f"{ignore_type} in self.ignored_types. Skip it."
warnings.warn(msg)
continue
self._draw(ann, label_categories, fig, ax, context[ann.type])

Expand Down Expand Up @@ -303,11 +305,19 @@ def _draw_mask(
context: List,
) -> None:
h, w = ann.image.shape
source = ann.image
if source.dtype != bool:
warnings.warn(
f"Mask should has dtype == bool, but its dtype == {source.dtype}. "
"Try to change it to bool dtype."
)
source = source.astype(bool)

mask_map = np.zeros((h, w, 4), dtype=np.uint8)
color = self._get_color(ann)
rgba_color = (*ImageColor.getcolor(color, "RGB"), 0.0)
mask_map[ann.image] = rgba_color
mask_map[ann.image, 3] = int(255 * self.alpha)
mask_map[source] = rgba_color
mask_map[source, 3] = int(255 * self.alpha)

ax.imshow(mask_map)

Expand Down