kaixin96 / PANet

Code for our ICCV 2019 paper PANet: Few-Shot Image Semantic Segmentation with Prototype Alignment
315 stars 64 forks source link

Why the query label pixel values are modified? #47

Closed SalarYakamoz closed 1 year ago

SalarYakamoz commented 1 year ago

Hi, I read the paper and code but not sure why the query label's values are changed here:

query_labels_tmp = [torch.zeros_like(x) for x in query_labels]

for i, query_label_tmp in enumerate(query_labels_tmp):
query_label_tmp[query_labels[i] == 255] = 255

for j in range(n_ways):
query_labels_tmp[query_labels[i] == class_ids[j]] = j + 1

My other question is why query_label_tmp is returned instead of query_labels_tmp?

kaixin96 commented 1 year ago

The original labels (in query_labels) correspond to concrete classes (e.g., airplane, boat). In the few-shot setting, we need to convert those to abstract labels (e.g., the 2nd class out of 5 ways). They do not carry semantic information about the class, that is, we do not know if the 2nd class belongs to airplanes, boats, or anything else.

query_labels_tmp is returned (see https://github.com/kaixin96/PANet/blob/master/dataloaders/customized.py#L163).

SalarYakamoz commented 1 year ago

Thank you for your quick response. About the first question, then why the same is not considered for support labels. Besides, why do we have to change the pixel values which will effect in the loss calculation. I understand the reason behind randomizing the class orders to randomly pick N-way K-shot support and query samples from the N-ways but why do we have to change the pixel values of the label mask of query image only? Any about my second question, I made a mistake and wanted to ask why query_label_tmp is not returned? It seems that some modifications on the query label is considered(which is called query_label_tmp ) but at last query_labels_tmp = [torch.zeros_like(x) for x in query_labels]is returned.

kaixin96 commented 1 year ago

About the first question, support_labels are only used to compute support_mask and are not returned. We need the semantic class information in the function getMask(). About the second question, the modification is in-place, that is, query_labels_tmp is modified when we modify query_label_tmp.

SalarYakamoz commented 1 year ago

Thank you for your answers.