liyunsheng13 / BDL

MIT License
222 stars 30 forks source link

About threshold and mask in SSL #8

Closed jarvisWang0903 closed 4 years ago

jarvisWang0903 commented 5 years ago
thres = []
for i in range(19):
    x = predicted_prob[predicted_label==i]
    if len(x) == 0:
        thres.append(0)
        continue        
    x = np.sort(x)
    thres.append(x[np.int(np.round(len(x)*0.5))])
print (thres)
thres = np.array(thres)
thres[thres>0.9]=0.9
print (thres)
for index in range(len(targetloader)):
    name = image_name[index]
    label = predicted_label[index]
    prob = predicted_prob[index]
    for i in range(19):
        label[(prob<thres[i])*(label==i)] = 255  
    output = np.asarray(label, dtype=np.uint8)
    output = Image.fromarray(output)
    name = name.split('/')[-1]
    output.save('%s/%s' % (args.save, name)) 
  1. I didn't really understand these code. You describe in paper that you choose 0.9 as threshold ,but it seems that you choose the mid prob as thrshold[thres.append(x[np.int(np.round(len(x)*0.5))])]
  2. pixel higher than 0.9 should be choosed for pseudo label, but the code [ [label[(prob<thres[i])*(label==i)] = 255 ] shows that prob<thres=255 ,why? shouldn't it be > or =0 ?
  3. Sorry, my question may be a little confusing, but I wonder how mask and threshold are selected. Thanks
liyunsheng13 commented 5 years ago

That is a good question. When we choose the threshold to generate the pseudo labels, on one hand, we don't want to induce a lot of noisy labels, so we set the threshold to be 0.9 in general. On the other hand, we don't want to cause a big imbalance across different classes when we choose 0.9 as the threshold. For some categories, due to the rare pixels or poor prediction, if we still use 0.9 as the threshold, there will be only a very small number of pixels are assigned with a pseudo label. In this case, we use 0.5 as the threshold which means as long as the predictor has confidence larger than 50%, we thought it was a confident prediction. Hope my explanation is clear to you.