Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Show in legend only classes that appear in an image for vis_label #345

Merged
merged 6 commits into from
Jul 21, 2017

Conversation

yuyu2172
Copy link
Member

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

figure_1-2

After

figure_1

@Hakuyume
Copy link
Member

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 unused_regend or all_regend? It is better to set the default behaviour to show only used legends.

@yuyu2172
Copy link
Member Author

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 unused_regend or all_regend? It is better to set the default behaviour to show only used legends.

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):
Copy link
Member

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)))
Copy link
Member

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.
Copy link
Member

@Hakuyume Hakuyume Jul 20, 2017

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))
Copy link
Member

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.

@yuyu2172 yuyu2172 added this to the v0.7 milestone Jul 21, 2017
Copy link
Member

@Hakuyume Hakuyume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Hakuyume Hakuyume merged commit 19b9a10 into chainer:master Jul 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants