diversity ratio code
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.
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
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.
- "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.
- 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.