tfzhou / ContrastiveSeg

ICCV2021 (Oral) - Exploring Cross-Image Pixel Contrast for Semantic Segmentation
MIT License
655 stars 85 forks source link

About the hard anchor samping #43

Open leeh43 opened 2 years ago

leeh43 commented 2 years ago

Hi, thank you for the great work. I am currently using your pipeline on my dataset. I have a question about the hard anchor sampling function. As the label (128 x 128) is resampled to the feature size (16 x 16), the segmentation prediction from the model is not resampled and it pops up an error of different dimensions between labels and predictions in the following line:

hard_indices = ((this_y_hat == cls_id) & (this_y != cls_id)).nonzero()

Is there anything that I can do to fix the error?

Thank you so much!

hhxzzy commented 2 years ago

I met the same problem before. I think this may because the stride of your backbone network is different from the author's. You can try resizing the labels, features and predictions to the same size to see if it works.

wcyjerry commented 2 years ago

I met the problem, and It's because ur decoder have already upsample the predictions, like after the encoder maybe the feature_map's h w is 16X16 , so the embed is bsXembed_dimX16X16, but if your decoder upsample the feature_map maybe ur prediction is like 128X128, this would report an error. the solution is resize your prediction to the same size as the embed like the way to do with labels

lennart-maack commented 1 year ago

@tfzhou Does the proposed solution from @q671383789 answers the question? Thanks a lot for your great work!