-
Notifications
You must be signed in to change notification settings - Fork 302
Show in legend only classes that appear in an image for vis_label #345
Conversation
I prefer showing all legends because it looks better to me when I plot more than one images. Of course, this is up to the situation. How about adding an option |
Nice suggestion! |
@@ -115,8 +115,8 @@ def vis_label( | |||
ax.imshow(img) | |||
|
|||
legend_handles = list() | |||
for l, label_name in enumerate(label_names): | |||
for l in np.unique(label): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should skip ignored label.
if l < 0:
continue
if all_label_names_in_legend: | ||
legend_labels = [l for l in np.unique(label) if l >= 0] | ||
else: | ||
legend_labels = list(range(len(label_names))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to convert to list. range(...)
can work.
all_label_names_in_legend (bool): Determines whether to include | ||
all label names in a legend. If this is :obj:`False`, | ||
only the names of labels | ||
that are included in the label image are included. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this sentence, are included
is used twice. It is hard to read. How about If this is :obj:False, the legend does not contain the names of unused labels. A unused label is defined as a label that does not appear in :obj:label.
if all_label_names_in_legend: | ||
legend_labels = [l for l in np.unique(label) if l >= 0] | ||
else: | ||
legend_labels = range(len(label_names)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
len(label_names)
can be replaced with n_class
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There is not much point in showing legends for all the classes in a dataset.
Similar to
vis_bbox
,vis_label
should limit information to the one that is contained in an image.Example
This dataset contains 80 classes.
Before
After