Skip to content

The code of "Enhancing Contrastive Learning Inspired by the Philosophy of 'the Blind Men and the Elephant'"

Notifications You must be signed in to change notification settings

btzyd/JointCrop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enhancing Contrastive Learning Inspired by the Philosophy of “the Blind Men and the Elephant”

This is a PyTorch implementation of the JointCrop paper (AAAI 2025). The code is mainly modified from MoCo v3.

Appendix of JointCrop

Due to AAAI's page limit, we have supplemented the appendix of JointCrop within the code repository.

Preparing the environment, code and dataset

  1. Prepare the environment.

Creating a python environment and activate it via the following command.

conda create -n jointcrop python=3.9
conda activate jointcrop
conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.8 -c pytorch -c nvidia
pip install tensorboard timm==0.4.9 numpy==1.26.4
  1. Clone this repository.
git clone https://github.com/btzyd/JointCrop.git
  1. Prepare the dataset ImageNet.

Download and organize the ImageNet-1K dataset according to the same form as MoCo v3.

Training script of JointCrop

MoCo v3 based on ResNet50 requires 2 nodes with a total of 16 GPUs and about 29GB of memory per GPU.

On the first node, run:

python main_jointcrop.py \
  --moco-m-cos --crop-min=.2 \
  --dist-url 'tcp://[your first node address]:[specified port]' \
  --multiprocessing-distributed --world-size 2 --rank 0 \
  --ckpt_path './checkpoint_resnet50_ep100_jointcrop0' \
  [your imagenet-folder with train and val folders]

On the second node, run the same command with --rank 1.

For scripts with 300 epochs, you can refer to the MoCo v3 repository.

Fine-tuning script of JointCrop

The fine-tuning of MoCo v3 based on ResNet50 nearly requires a total of 8 GPUs on 1 node, with about 6GB memory per GPU.

python main_lincls.py \
  --dist-url 'tcp://127.0.0.1:10001' \
  --multiprocessing-distributed --world-size 1 --rank 0 \
  --pretrained 'checkpoint_resnet50_ep100_jointcrop0/checkpoint_0099.pth.tar' \
  [your imagenet-folder with train and val folders]

Results of JointCrop

epoch MoCo v3
baseline
MoCo v3 +
JointCrop(0)
100 68.9 69.47
300 72.8 73.23

Citation

To be added after publication.

About

The code of "Enhancing Contrastive Learning Inspired by the Philosophy of 'the Blind Men and the Elephant'"

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages