QtacierP / PRIOR

Official repository for the paper "Prototype Representation Joint Learning from Medical Images and Reports, ICCV 2023".
Apache License 2.0
64 stars 6 forks source link

Retrieval task codes #11

Closed AlexCo1d closed 5 months ago

AlexCo1d commented 5 months ago

Hi, could you show me how your codes doing the retrieval task, just the function you used is okay! Thank you!

QtacierP commented 5 months ago

You are welcome to use the code available at this https://github.com/QtacierP/PRIOR/blob/086bf2e0d379d7dacc47a6ad738ffabc1ad6e25f/codes/prior/downstream/zero_classification_model.py#L159

However, before utilizing it, please replace the prompt as indicated here https://github.com/QtacierP/PRIOR/blob/086bf2e0d379d7dacc47a6ad738ffabc1ad6e25f/codes/prior/downstream/zero_classification_model.py#L76

Specifically, you can modify the prompts in the dataset by using the reports from MIMIC-CXR, which can be found at https://github.com/QtacierP/PRIOR/blob/086bf2e0d379d7dacc47a6ad738ffabc1ad6e25f/codes/prior/data/zero_shot_classification/chexpert_zls.py#L58

For zero-shot classification, prompts are generated simply. However, for retrieval tasks, the primary adjustment is to use the reports as the prompts. The remaining steps are similar to zero-shot classification.

I hope you find this information helpful.

AlexCo1d commented 5 months ago

https://github.com/QtacierP/PRIOR/blob/086bf2e0d379d7dacc47a6ad738ffabc1ad6e25f/codes/prior/downstream/zero_classification_model.py#L183 Thank you for your reply! I noticed that this part you comment it [1,1], so i am confused that how I can process and generate a [B,B] similarity matrix based on logits, do you still remember the specfied shape of total_local_logits? Or is it already a [B,B] matrix before softmax?

QtacierP commented 5 months ago

You can remove the mean() here https://github.com/QtacierP/PRIOR/blob/086bf2e0d379d7dacc47a6ad738ffabc1ad6e25f/codes/prior/downstream/zero_classification_model.py#L154 text_to_local_image_atten and image_to_local_text_atten are both [B, B] similarity matrixs :)

AlexCo1d commented 5 months ago

Thank you a lot!