BNM icon indicating copy to clipboard operation
BNM copied to clipboard

diversity ratio code

Open zhouyaqian666 opened this issue 4 years ago • 3 comments

Hello, the diversity ratio is measured by the mean predicted category number dividing the mean ground-truth category number. Is there a code to calculate the diversity ratio? Thanks.

zhouyaqian666 avatar Jan 20 '22 12:01 zhouyaqian666

The main code can be shown by

diversity = torch.unique(torch.argmax(outputs_target,dim=1)).shape[0]/ torch.unique(labels_target).shape[0]

where labels_target denotes the ground truth of labels, and outputs_target denotes the prediction outputs.

Details can be refer to train_image.py

cuishuhao avatar Jan 22 '22 10:01 cuishuhao

In unsupervised domain adaptation,the "labels_target" is usually unknown, how do you get the "labels_target"? Where should this line of code be placed in the train_image.py? Can you explain it in detail? Thank you very much.

zhouyaqian666 avatar Jan 22 '22 14:01 zhouyaqian666

  1. "labels_target" is usually unknown for target domain, but it is available during the test process. For example, the calculation of "Accuracy" is always based on labels_target, and diversity can be regarded as a measurement calculated during the test process. To simplify, diversity can be also calculated during the training process, with "labels_target". Note that labels_target is not used to calculate loss for backward in calculation of diversity.
  2. By replacing line 149 to
inputs_target, labels_target= iter_target.next()

Then we can add the calculation diversity before line 173

Finally, we can print the diversity to see the variation.

cuishuhao avatar Jan 27 '22 06:01 cuishuhao