{"id":18949940,"url":"https://github.com/salesforce/pcl","last_synced_at":"2025-04-05T02:11:45.535Z","repository":{"id":37769020,"uuid":"283078844","full_name":"salesforce/PCL","owner":"salesforce","description":"PyTorch code for \"Prototypical Contrastive Learning of Unsupervised Representations\"","archived":false,"fork":false,"pushed_at":"2022-05-27T10:28:39.000Z","size":185,"stargazers_count":581,"open_issues_count":8,"forks_count":83,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-29T01:13:59.601Z","etag":null,"topics":["contrastive-learning","pre-trained-model","representation-learning","self-supervised-learning","unsupervsied-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/salesforce.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":"CODEOWNERS","security":null,"support":null}},"created_at":"2020-07-28T02:45:07.000Z","updated_at":"2025-03-18T18:04:28.000Z","dependencies_parsed_at":"2022-07-11T02:38:56.695Z","dependency_job_id":null,"html_url":"https://github.com/salesforce/PCL","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/salesforce%2FPCL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salesforce%2FPCL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salesforce%2FPCL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salesforce%2FPCL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/salesforce","download_url":"https://codeload.github.com/salesforce/PCL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276189,"owners_count":20912288,"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","pre-trained-model","representation-learning","self-supervised-learning","unsupervsied-learning"],"created_at":"2024-11-08T13:19:47.226Z","updated_at":"2025-04-05T02:11:45.515Z","avatar_url":"https://github.com/salesforce.png","language":"Python","readme":"## Prototypical Contrastive Learning of Unsupervised Representations (Salesforce Research)\n\u003cimg src=\"./img/PCL_framework.png\" width=\"600\"\u003e\n\nThis is a PyTorch implementation of the \u003ca href=\"https://openreview.net/forum?id=KmykpuSrjcq\"\u003ePCL paper\u003c/a\u003e:\n\u003cpre\u003e\n@inproceedings{PCL,\n\ttitle={Prototypical Contrastive Learning of Unsupervised Representations},\n\tauthor={Junnan Li and Pan Zhou and Caiming Xiong and Steven C.H. Hoi},\n\tbooktitle={ICLR},\n\tyear={2021}\n}\u003c/pre\u003e\n\n### Requirements:\n* ImageNet dataset\n* Python ≥ 3.6\n* PyTorch ≥ 1.4\n* \u003ca href=\"https://github.com/facebookresearch/faiss\"\u003efaiss-gpu\u003c/a\u003e: pip install faiss-gpu\n* pip install tqdm\n\n### Unsupervised Training:\nThis implementation only supports multi-gpu, DistributedDataParallel training, which is faster and simpler; single-gpu or DataParallel training is not supported.\n\nTo perform unsupervised training of a ResNet-50 model on ImageNet using a 4-gpu or 8-gpu machine, run: \n\u003cpre\u003epython main_pcl.py \\ \n  -a resnet50 \\ \n  --lr 0.03 \\\n  --batch-size 256 \\\n  --temperature 0.2 \\\n  --mlp --aug-plus --cos (only activated for PCL v2) \\\t\n  --dist-url 'tcp://localhost:10001' --multiprocessing-distributed --world-size 1 --rank 0 \\\n  --exp-dir experiment_pcl\n  [Imagenet dataset folder]\n\u003c/pre\u003e\n\n### Download Pre-trained Models\n\u003ca href=\"https://storage.googleapis.com/sfr-pcl-data-research/PCL_checkpoint/PCL_v1_epoch200.pth.tar\"\u003ePCL v1\u003c/a\u003e| \u003ca href=\"https://storage.googleapis.com/sfr-pcl-data-research/PCL_checkpoint/PCL_v2_epoch200.pth.tar\"\u003ePCL v2\u003c/a\u003e\n------ | ------\n\n### Linear SVM Evaluation on VOC\nTo train a linear SVM classifier on VOC dataset, using frozen representations from a pre-trained model, run:\n\u003cpre\u003epython eval_svm_voc.py --pretrained [your pretrained model] \\\n  -a resnet50 \\ \n  --low-shot (only for low-shot evaluation, otherwise the entire dataset is used) \\\n  [VOC2007 dataset folder]\n\u003c/pre\u003e\n\nLinear SVM classification result on VOC, using ResNet-50 pretrained with PCL for 200 epochs:\n\nModel| k=1 | k=2 | k=4 | k=8 | k=16| Full\n --- | --- | --- | --- | --- | --- | ---\nPCL v1| 46.9| 56.4| 62.8| 70.2| 74.3 | 82.3\nPCL v2| 47.9| 59.6| 66.2| 74.5| 78.3 | 85.4\n\nk is the number of training samples per class.\n\n### Linear Classifier Evaluation on ImageNet\nRequirement: pip install tensorboard_logger \\\nTo train a logistic regression classifier on ImageNet, using frozen representations from a pre-trained model, run:\n\u003cpre\u003epython eval_cls_imagenet.py --pretrained [your pretrained model] \\\n  -a resnet50 \\ \n  --lr 5 \\\n  --batch-size 256 \\\n  --id ImageNet_linear \\ \n  --dist-url 'tcp://localhost:10001' --multiprocessing-distributed --world-size 1 --rank 0 \\\n  [Imagenet dataset folder]\n\u003c/pre\u003e\n\nLinear classification result on ImageNet, using ResNet-50 pretrained with PCL for 200 epochs:\nPCL v1 | PCL v2\n------ | ------\n  61.5 |  67.6\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalesforce%2Fpcl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalesforce%2Fpcl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalesforce%2Fpcl/lists"}