-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
Upload weights to TorchXrayVision github #121
Comments
Hey! We are coordinating here on who has the time to do it. Sorry for the delay! I'll get back to you with an update in a few days. |
Hey so some questions for you. I was able to get the model loaded by using the resnet code in your repo. I was able to extract just the encoder_q weights and it is much smaller than the entire checkpoint (300MB->100MB). There is an fc layer in the checkpoint that predicts 128 outputs. Do you have the labels for these outputs? I can add it so the model will predict the outputs and also have a .features() function that will extract just the features from an input. It would be nice to allow people to directly compare downstream performance with your model. I see the input image size is 512x512. Can you tell me how the normalization should work? If I give you a numpy array that is normalized between 0 and 1 how should it be normalized to go into this model? |
Would this be the right normalization? |
That's right. We trained MoCo-v2, which uses ResNet50 as its backbone, as a self-supervised learning method. MoCo-v2 uses two image encoders, one of which learns the encoder through momentum updates (encoder_k). Therefore, we use the state_dict of encoder_q. Additionally, since the model is trained as a self-supervised learning method, the 128 prediction (for contrastive learning) FC layer should be dropped, and this part should be transformed to fit the downstream task that the user desires. The 512 x 512 image size was preprocessed as follows. We referred to the paper (https://doi.org/10.1016/j.cmpb.2022.106705) and carried out preprocessing and normalization. The value of torchvision.transforms.Normalize(0.658, 0.221) is the mean std of our training dataset, which was used for normalization. (0-255 pixel value range)
|
I have a PR open here: #122 The model weights will download automatically. I'm not sure the processing is correct because a UMAP of the representations doesn't look good. I made a demo notebook showing things. If you edit the paths in dataset_utils.py you can load the datasets. Here is what I expect them to look like: https://github.com/mlmed/torchxrayvision/blob/master/scripts/xray_representations.ipynb |
I have seen the codes you showed me.
|
So if I do this with torchvision.transforms.Normalize(0.658, 0.221)
The values appear to be between -3 and 3 but the UMAP plots still look wrong. The UMAP has the label information for 4 targets. Each CXR only has a single pathology to avoid issues with multiple positive labels. It is essentially like looking at a KNN classifier. If I scale them between 0-255 before the normalize the values are between -3 and 1150 and the UMAP looks like this:
Any ideas? Can you make a small end to end script that will take in an image file and compute the embedding? Then I can figure out where the code diverges. |
We modified our image classification module in (https://github.com/mi2rl/CheSS/blob/main/downstream/classification/datasets.py). You can check if the dataset preprocessing is correct. I believe that our method will be helpful for users to train a separate downstream task, but I don't think that the current weights trained using contrastive learning method alone will result in clustering results like the ones you showed me before Is there anything else I can help you with? |
Ok! I added the normalize after the 0,255 scale and I believe it is matched to your code now: https://github.com/mlmed/torchxrayvision/pull/122/files#diff-4e3fee5eb94fc6335266cbd042c570aec49d5894e54b0ae480ecbc1046273b07R49 If you agree then I will prepare to merge it in and add documentation. Do you want to try it out to make sure it is correct? |
Okay. Where can I find the added documentation? |
Nothing fancy but I added it to the readme in the PR here: https://github.com/mlmed/torchxrayvision/tree/mi2rl-chess |
Great, I hope there will be some research or work that we can do together later. |
Were you able to test and confirm that the model outputs are correct? I have a fear that something is not correct and it will hurt the performance of your model when people benchmark against it. I'd prefer to double check now than later |
Unlike the existing supervised learning model, the Self-supervised learning model requires fine-tuning using labeled dataset even if it is a small data set. I observed that loss decreases well when you fine-tuned the model based on the models you made with baseline_models.
|
Were you able to achieve the same results as in your paper? If there is something wrong with the code it will likely train properly but the performance wouldn't be that high. In the paper I see a 0.808 AUC number for chexpert. Is that the data you are testing on in the plot above? The train AUC should be even higher right? |
I didn't experiment with chexpert dataset. I think it will take some time to set up the experiment because I removed the chexpert dataset from NAS. |
I am curious about the progress of the issue you registered in the corresponding GitHub repository (mi2rl/CheSS#23 (comment)).
I'm really honored that the weights of the model were uploaded to TorchXrayVision.
When will it be uploaded?
The text was updated successfully, but these errors were encountered: