ContrastiveSeg icon indicating copy to clipboard operation
ContrastiveSeg copied to clipboard

About args n_view,max_samples

Open xianxuan-z opened this issue 2 years ago • 4 comments

Hello! Your work is outstanding! I did a detailed research on both the paper and the code. There are a lot of questions that I don’t understand:

  1. I want to ask first about the loss_contrast.py Can you explain the meaning of max_samples and n_views in the hard_anchor_sampling function?
  2. If you apply this method to small samples, can the hard_anchor_sampling step be omitted? I hope you can explain in more detail,many thanks!

xianxuan-z avatar Dec 13 '21 09:12 xianxuan-z

Hi,Thanks for your interest.

  1. As given in the following line, max_samples is the maximum number of samples for all classes, and n_views is the average number for each class. https://github.com/tfzhou/ContrastiveSeg/blob/7be326ae9127a847558584eac489d4858adf7cb1/lib/loss/loss_contrast.py#L47
  2. You can also try to find some hard anchors (which are misclassified), no matter how many samples you have.

tfzhou avatar Dec 13 '21 10:12 tfzhou

Thank you for your prompt reply! Then I have corresponding questions and look forward to your help to explain: classes = [] total_classes = 0 for ii in range(batch_size): this_y = y_hat[ii] this_classes = torch.unique(this_y) this_classes = [x for x in this_classes if x != self.ignore_label] this_classes = [x for x in this_classes if (this_y == x).nonzero().shape[0] > self.max_views]

        classes.append(this_classes)
        total_classes += len(this_classes)

In your code, if there are the same categories in different batches, will there be duplicate statistics in the result of total_classes? Hope you can solve my confusion.

xianxuan-z avatar Dec 13 '21 10:12 xianxuan-z

What do you mean for "duplicate statistics"? p.s. If you have many questions, please also feel free to compile them together here at one time.

tfzhou avatar Dec 15 '21 12:12 tfzhou

Hello! Your work is outstanding! I did a detailed research on both the paper and the code. There are a lot of questions that I don’t understand:

  1. Can you explain the meaning of self.max_views in the hard_anchor_sampling function? And why need (this_y == x).nonzero().shape[0] > self.max_views
  2. In my project, some labels only have a little targat pixels, specially resized to the size of embedding, so the total_classes==0 situation may be happened, so that feats_ is None and self._contrast function can not run.
  3. I want to ask about the class HRNet_W48_MEM of hrnet.py: def _momentum_update_key_encoder(self): for param_q, param_k in zip(self.encoder_q.parameters(), self.encoder_k.parameters()): param_k.data = param_k.data * self.m + param_q.data * (1. - self.m) Can you explain the meaning of self.encoder_k?I am sorry that I did not find its definition. I hope you can explain in more detail,many thanks!

zh-aidy avatar Mar 29 '23 05:03 zh-aidy