Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diversity ratio code #16

Open
zhouyaqian666 opened this issue Jan 20, 2022 · 3 comments
Open

diversity ratio code #16

zhouyaqian666 opened this issue Jan 20, 2022 · 3 comments

Comments

@zhouyaqian666
Copy link

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.

@cuishuhao
Copy link
Owner

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

@zhouyaqian666
Copy link
Author

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.

@cuishuhao
Copy link
Owner

  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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants