LTH14 / targeted-supcon

A PyTorch implementation of the paper Targeted Supervised Contrastive Learning for Long-tailed Recognition
MIT License
91 stars 13 forks source link

reproduce cifar10 #3

Open YunYunY opened 2 years ago

YunYunY commented 2 years ago

Hi, thank you for the code. Could you please provide your cifar10 code for reproducing? I have followed your supplemental material and run the code for 1000 epochs for pretraining (Moco based). But the result is still lower than the number in the paper. I'm wondering if using SimCLR as you claimed in the paper will reach higher accuracy? Have you compared Moco and Simclr structures on CIFAR? It would be great if you could share that part of the code.
Thank you very much for your time.

Angelina1996 commented 12 months ago

Hi @YunYunan and @LTH14 , please guide or share the link to supplementary material. It would be great if you could share the code for reproducing the results on Cifar and INat datasets on my email: robertangelina92@gmail.com Cheers

LTH14 commented 12 months ago

Hi, thanks for your interest! Please refer to this supplementary material -- I submitted with the CVPR camera ready but I don't know why it does not appear online. For Cifar you need to replace the moco framework with supcon. For inat you can simply change the imagenet-LT to inat. Hope this helps.

On Tue, Jul 25, 2023 at 11:20 PM Angelina1996 @.***> wrote:

Hi @YunYunan and @LTH14 https://github.com/LTH14 , please guide or share the link to supplementary material. It would be great if you could share the code for reproducing the results on Cifar and INat datasets on my email: @.*** Cheers

— Reply to this email directly, view it on GitHub https://github.com/LTH14/targeted-supcon/issues/3#issuecomment-1650916600, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJD3KAZ54ZXHVZXIRPZRH3XSCEH3ANCNFSM5Z4OTBTA . You are receiving this because you were mentioned.Message ID: @.***>

LTH14 commented 12 months ago

Hi, thanks for your interest! Please refer to this supplementary material -- I submitted with the CVPR camera ready but I don't know why it does not appear online. For Cifar you need to replace the moco framework with supcon https://github.com/HobbitLong/SupContrast. For inat you can simply change the imagenet-LT to inat. Hope this helps.

On Wed, Jul 26, 2023 at 10:22 AM Tianhong Li @.***> wrote:

Hi, thanks for your interest! Please refer to this supplementary material -- I submitted with the CVPR camera ready but I don't know why it does not appear online. For Cifar you need to replace the moco framework with supcon. For inat you can simply change the imagenet-LT to inat. Hope this helps.

On Tue, Jul 25, 2023 at 11:20 PM Angelina1996 @.***> wrote:

Hi @YunYunan and @LTH14 https://github.com/LTH14 , please guide or share the link to supplementary material. It would be great if you could share the code for reproducing the results on Cifar and INat datasets on my email: @.*** Cheers

— Reply to this email directly, view it on GitHub https://github.com/LTH14/targeted-supcon/issues/3#issuecomment-1650916600, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJD3KAZ54ZXHVZXIRPZRH3XSCEH3ANCNFSM5Z4OTBTA . You are receiving this because you were mentioned.Message ID: @.***>

Angelina1996 commented 12 months ago

Thanks so much, Tianhong, for the reply. Could you exactly guide me about the line where I have to replace moco with supcon framework? I already know about supcon, however, supcon uses a different loss function than yours (TSC). I am a bit confused about this. Any help regarding this will be highly appreciated. Cheers

LTH14 commented 12 months ago

Our implementation in Cifar is not based on the moco and imagenet framework, so it could be hard to directly adapt the released code to Cifar. Our implementation in Cifar is based on this repo: https://github.com/HobbitLong/SupContrast. You need to replace the supcon losses file with the targeted supcon loss https://github.com/HobbitLong/SupContrast/blob/master/losses.py. I don't have a clean version of the Cifar repo, but I can share with you the tsc loss implementation. Hope it can make your reproduction easier.

Best Tianhong

On Thu, Jul 27, 2023 at 4:23 AM Angelina1996 @.***> wrote:

Thanks so much, Tianhong, for the reply. Could you exactly guide me about the line where I have to replace moco with supcon framework? I already know about supcon, however, supcon uses a different loss function than yours (TSC). I am a bit confused about this. Any help regarding this will be highly appreciated. Cheers

— Reply to this email directly, view it on GitHub https://github.com/LTH14/targeted-supcon/issues/3#issuecomment-1653132792, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJD3KFKXLVZWT3U7BWITZ3XSIQPHANCNFSM5Z4OTBTA . You are receiving this because you were mentioned.Message ID: @.***>

Angelina1996 commented 12 months ago

Thanks so much, Tianhong, for your kind help. It makes sense to me now. Could you share the TSC loss, I want to reproduce the results on CIFAR.

LTH14 commented 12 months ago

Please see the attachment of the previous email

On Fri, Jul 28, 2023 at 3:11 AM Angelina1996 @.***> wrote:

Thanks so much, Tianhong, for your kind help. It makes sense to me now. Could you share the TSC loss, I want to reproduce the results on CIFAR.

— Reply to this email directly, view it on GitHub https://github.com/LTH14/targeted-supcon/issues/3#issuecomment-1655160104, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJD3KEB5SQN4PVLHNFFPIDXSNQ2TANCNFSM5Z4OTBTA . You are receiving this because you were mentioned.Message ID: @.***>

Angelina1996 commented 11 months ago

Tianhong

Thanks, Tianhong, for your help. It is still unclear as the attachments or the links you have provided are for Supcon loss but not for targetted soupcon loss (TSC), moreover I am wondering how the targetted centres are calculated in Cifar dataset.

LTH14 commented 11 months ago

On CIFAR10, since the number of classes is smaller than the output dimension for contrastive loss, the targets can be directly computed without using gradient descent (see section 3.1 of the paper). Here is the main function we use to use target, hope it helps:

On Sun, Jul 30, 2023 at 10:04 PM Angelina1996 @.***> wrote:

Tianhong

Thanks, Tianhong, for your help. It is still unclear as the attachments or the links you have provided are for Supcon loss but not for targetted soupcon loss (TSC), moreover I am wondering how the targetted centres are calculated in Cifar dataset.

— Reply to this email directly, view it on GitHub https://github.com/LTH14/targeted-supcon/issues/3#issuecomment-1657388545, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJD3KCMBNHHMWGD5OY7JTDXS4HB3ANCNFSM5Z4OTBTA . You are receiving this because you were mentioned.Message ID: @.***>

Angelina1996 commented 11 months ago

Thanks, Tianhong

I have applied the setting for the Cifar dataset as you suggested. However, the performance accuracies are far less than the results claimed in the paper. Would you mind sharing the code for reproducing the Cifar Dataset?

Angelina1996 commented 11 months ago

Hi, thank you for the code. Could you please provide your cifar10 code for reproducing? I have followed your supplemental material and run the code for 1000 epochs for pretraining (Moco based). But the result is still lower than the number in the paper. I'm wondering if using SimCLR as you claimed in the paper will reach higher accuracy? Have you compared Moco and Simclr structures on CIFAR? It would be great if you could share that part of the code. Thank you very much for your time.

Hi Yun, I am wondering if you managed to reproduce the Cifar dataset results. I have tried but the results are far less than the claimed results in the paper. Cheers

LTH14 commented 11 months ago

Hi, it seems there are some discrepancies between email and the Github reply -- I thought the attachment in the email apply will also appear here. I just uploaded the uncleaned main python file and loss file for TSC in the repo here. I'm sorry that I haven't really got time to clean it up. Hope it helps.

Angelina1996 commented 11 months ago

Hi, it seems there are some discrepancies between email and the Github reply -- I thought the attachment in the email apply will also appear here. I just uploaded the uncleaned main python file and loss file for TSC in the repo here. I'm sorry that I haven't really got time to clean it up. Hope it helps.

Angelina1996 commented 11 months ago

Hi, it seems there are some discrepancies between email and the Github reply -- I thought the attachment in the email apply will also appear here. I just uploaded the uncleaned main python file and loss file for TSC in the repo here. I'm sorry that I haven't really got time to clean it up. Hope it helps.

Thanks, Tianhong, Thanks so much for your help, yes, I already integrated TSC loss into the SupCon model and trained the model using SimCLR, and used LDAM and reweighting in the second stage (classification) but the results were far less than the claimed ones. Would you mind sharing the whole uncleaned version of the code for Cifar dataset?

Angelina1996 commented 11 months ago

Hi, it seems there are some discrepancies between email and the Github reply -- I thought the attachment in the email apply will also appear here. I just uploaded the uncleaned main python file and loss file for TSC in the repo here. I'm sorry that I haven't really got time to clean it up. Hope it helps. Tianhong, could you please provide the code?

LTH14 commented 11 months ago

Please check the cifar_dirty sub directory. It should contain every necessary file.

Angelina1996 commented 11 months ago

Please check the cifar_dirty sub directory. It should contain every necessary file.

Dear Tianhong, Thanks for providing the code; however, I believe there are still some files missing i.e. FileNotFoundError: [Errno 2] No such file or directory: 'optimal_10_10.npy'

Could you please, provide the missing files Cheers

LTH14 commented 11 months ago

Just uploaded. This file would be also easy to generate, as there is a analytical optimal solution for target positions when the number of classes <= output dimension.

xuxhuan commented 10 months ago

Please check the cifar_dirty sub directory. It should contain every necessary file.

Dear Tianhong, Thanks for providing the code; however, I believe there are still some files missing i.e. FileNotFoundError: [Errno 2] No such file or directory: 'optimal_10_10.npy'

Could you please, provide the missing files Cheers

Hi, did you finally reproduce the cifar10 code? If so, could you please provide me with a copy of your code?