{"id":13737558,"url":"https://github.com/xyupeng/ContrastiveCrop","last_synced_at":"2025-05-08T14:33:03.673Z","repository":{"id":37674491,"uuid":"456527298","full_name":"xyupeng/ContrastiveCrop","owner":"xyupeng","description":"[CVPR 2022 Oral] Crafting Better Contrastive Views for Siamese Representation Learning","archived":false,"fork":false,"pushed_at":"2022-06-27T03:04:10.000Z","size":428,"stargazers_count":285,"open_issues_count":4,"forks_count":27,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-10T01:08:54.757Z","etag":null,"topics":["contrastive-learning","pytorch","self-supervised-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xyupeng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-07T13:55:44.000Z","updated_at":"2025-04-05T08:07:59.000Z","dependencies_parsed_at":"2022-07-21T04:48:57.498Z","dependency_job_id":null,"html_url":"https://github.com/xyupeng/ContrastiveCrop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyupeng%2FContrastiveCrop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyupeng%2FContrastiveCrop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyupeng%2FContrastiveCrop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyupeng%2FContrastiveCrop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xyupeng","download_url":"https://codeload.github.com/xyupeng/ContrastiveCrop/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253085766,"owners_count":21851696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["contrastive-learning","pytorch","self-supervised-learning"],"created_at":"2024-08-03T03:01:53.274Z","updated_at":"2025-05-08T14:33:02.932Z","avatar_url":"https://github.com/xyupeng.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"## Crafting Better Contrastive Views for Siamese Representation Learning (CVPR 2022 Oral)\r\n\r\n\u003cimg src=\"figs/motivation.png\"\u003e \r\n\r\n**2022-03-29**: The paper was selected as a **CVPR 2022 Oral** paper!\r\n\r\n**2022-03-03**: The paper was accepted by **CVPR 2022**!\r\n\r\nThis is the official PyTorch implementation of the [ContrastiveCrop paper](https://arxiv.org/abs/2202.03278):\r\n```\r\n@article{peng2022crafting,\r\n  title={Crafting Better Contrastive Views for Siamese Representation Learning},\r\n  author={Peng, Xiangyu and Wang, Kai and Zhu, Zheng and You, Yang},\r\n  journal={arXiv preprint arXiv:2202.03278},\r\n  year={2022}\r\n}\r\n```\r\nThis repo includes PyTorch implementation of **SimCLR**, **MoCo**, **BYOL** and **SimSiam**, as well as their DDP training code.\r\n## Preparation\r\n1. Create a python enviroment with `pytorch \u003e= 1.8.1`.\r\n2. `pip install -r requirements.txt`\r\n\r\n\r\n## Datasets\r\nPlease download and organize the datasets in this structure:\r\n```\r\nContrastiveCrop\r\n├── data/\r\n    ├── ImageNet/\r\n    │   ├── train/ \r\n    │   ├── val/\r\n    ├── cifar-10-batches-py/\r\n    ├── cifar-100-python/\r\n    ├── stl10_binary/\r\n    ├── tiny-imagenet-200/\r\n    │   ├── train/\r\n    │   ├── val/\r\n```\r\nUse this [script](https://gist.github.com/moskomule/2e6a9a463f50447beca4e64ab4699ac4) to prepare tiny-imagenet-200.\r\n\r\n## Pre-train\r\n```\r\n# MoCo, CIFAR-10, CCrop\r\npython DDP_moco_ccrop.py configs/small/cifar10/moco_ccrop.py\r\n\r\n# SimSiam, CIFAR-100, CCrop\r\npython DDP_simsiam_ccrop.py configs/small/cifar100/simsiam_ccrop.py\r\n\r\n# MoCo V2, IN-200, CCrop\r\npython DDP_moco_ccrop.py configs/IN200/mocov2_ccrop.py\r\n\r\n# MoCo V2, IN-1K, CCrop\r\npython DDP_moco_ccrop.py configs/IN1K/mocov2_ccrop.py\r\n```\r\nWe also recommend trying an even simpler version of ContrastiveCrop, named **SimCCrop**, \r\nthat simply fixes a box at the center of the image with half height \u0026 width of that image.\r\n**SimCCrop** even does not require localization and thus adds **NO** extra training overhead.\r\nIt should work well on almost 'object-centric' datasets.\r\n```\r\n# MoCo, SimCCrop\r\npython DDP_moco_ccrop.py configs/small/cifar10/moco_simccrop.py\r\npython DDP_moco_ccrop.py configs/small/cifar100/moco_simccrop.py\r\n```\r\n\r\n## Linear Evaluation\r\n```\r\n# CIFAR-10\r\npython DDP_linear.py configs/linear/cifar10_res18.py --load ./checkpoints/small/cifar10/moco_ccrop/last.pth\r\n\r\n# CIFAR-100\r\npython DDP_linear.py configs/linear/cifar100_res18.py --load ./checkpoints/small/cifar100/simsiam_ccrop/last.pth\r\n\r\n# IN-200 \r\npython DDP_linear.py configs/linear/IN200_res50.py --load ./checkpoints/IN200/mocov2_ccrop/last.pth\r\n\r\n# IN-1K\r\npython DDP_linear.py configs/linear/IN1K_res50.py --load ./checkpoints/IN1K/mocov2_ccrop/last.pth\r\n```\r\n\r\nMore models and datasets coming soon.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyupeng%2FContrastiveCrop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxyupeng%2FContrastiveCrop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyupeng%2FContrastiveCrop/lists"}