{"id":13738583,"url":"https://github.com/ServiceNow/embedding-propagation","last_synced_at":"2025-05-08T16:34:45.237Z","repository":{"id":37974550,"uuid":"246041650","full_name":"ServiceNow/embedding-propagation","owner":"ServiceNow","description":"Codebase for Embedding Propagation: Smoother Manifold for Few-Shot Classification. This is a ServiceNow Research project that was started at Element AI.","archived":false,"fork":false,"pushed_at":"2022-06-27T13:36:41.000Z","size":173,"stargazers_count":208,"open_issues_count":6,"forks_count":21,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-11-15T07:34:51.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ServiceNow.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":"2020-03-09T13:22:59.000Z","updated_at":"2024-10-08T01:23:00.000Z","dependencies_parsed_at":"2022-09-02T13:10:49.322Z","dependency_job_id":null,"html_url":"https://github.com/ServiceNow/embedding-propagation","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/ServiceNow%2Fembedding-propagation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ServiceNow%2Fembedding-propagation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ServiceNow%2Fembedding-propagation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ServiceNow%2Fembedding-propagation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ServiceNow","download_url":"https://codeload.github.com/ServiceNow/embedding-propagation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253105682,"owners_count":21855078,"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":[],"created_at":"2024-08-03T03:02:27.891Z","updated_at":"2025-05-08T16:34:44.170Z","avatar_url":"https://github.com/ServiceNow.png","language":"Python","readme":"*ServiceNow completed its acquisition of Element AI on January 8, 2021. All references to Element AI in the materials that are part of this project should refer to ServiceNow.*\n\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)\n\n\n\u003ch1 align=\"center\"\u003eEmbedding Propagation\u003c/h1\u003e\n\u003ch5 align=\"center\"\u003eSmoother Manifold for Few-Shot Classification \u003ca href=\"https://arxiv.org/abs/2003.04151\"\u003e[Paper]\u003c/a\u003e (ECCV2020) \u003c/h5\u003e  \n\n\n\nEmbedding propagation can be used to regularize the intermediate features so that generalization performance is improved.\n\n![](embedding_prop.jpeg)\n\n## Usage\n\nAdd an embedding propagation layer to your network.\n\n```\npip install git+https://github.com/ElementAI/embedding-propagation\n```\n\n```python\nimport torch\nfrom embedding_propagation import EmbeddingPropagation\n\nep = EmbeddingPropagation()\nfeatures = torch.randn(32, 32)\nembeddings = ep(features)\n```\n\n## Experiments \n\nGenerate the results from the \u003ca href=\"https://arxiv.org/abs/2003.04151\"\u003e[Paper]\u003c/a\u003e.\n\n### Install requirements\n\n`pip install -r requirements.txt`\n \nThis command installs the [Haven library](https://github.com/haven-ai/haven-ai) which helps in managing the experiments.\n\n### Download the Datasets\n\n* [mini-imagenet](https://github.com/renmengye/few-shot-ssl-public#miniimagenet) ([pre-processing](https://github.com/ElementAI/TADAM/tree/master/datasets))\n* [tiered-imagenet](https://github.com/renmengye/few-shot-ssl-public#tieredimagenet)\n* [CUB](https://github.com/wyharveychen/CloserLookFewShot/tree/master/filelists/CUB)\n\nIf you have the `pkl` version of miniimagenet, you can still use it by setting the dataset name to \"episodic_miniimagenet_pkl\", in each of the files in `exp_configs`.\n\n\u003c!-- You can either edit `data_root` in the `exp_configs/[pretraining|finetuning].py` or create a symbolic link to the each of the dataset folders at `./data/dataset-name/` (default). --\u003e\n\n### Reproduce the results in the paper\n\n#### 1. Pre-training\n\n```\npython3 trainval.py -e pretrain -sb ./logs/pretraining -d \u003cdatadir\u003e\n```\nwhere `\u003cdatadir\u003e` is the directory where the data is saved.\n\n#### 2. Fine-tuning\n\nIn `exp_configs/finetune_exps.py`, set `\"pretrained_weights_root\": ./logs/pretraining/`\n\n```\npython3 trainval.py -e finetune -sb ./logs/finetuning -d \u003cdatadir\u003e\n```\n\n#### 3. SSL experirments with 100 unlabeled\n\nIn `exp_configs/ssl_exps.py`, set `\"pretrained_weights_root\": ./logs/finetuning/`\n\n```\npython3 trainval.py -e ssl_large -sb ./logs/ssl/ -d \u003cdatadir\u003e\n```\n\n#### 4. SSL experirments with 20-100% unlabeled\n\nIn `exp_configs/ssl_exps.py`, set `\"pretrained_weights_root\": ./logs/finetuning/`\n\n```\npython3 trainval.py -e ssl_small -sb ./logs/ssl/ -d \u003cdatadir\u003e\n```\n\n### Results\n\n|dataset|model|1-shot|5-shot|\n|-------|-----|------|------|\n|episodic_cub|conv4|65.94 ± 0.93|78.80 ± 0.64|\n|episodic_cub|resnet12|81.32 ± 0.84|91.02 ± 0.44|\n|episodic_cub|wrn|87.48 ± 0.68|93.74 ± 0.35|\n|episodic_miniimagenet|conv4|57.41 ± 0.85|72.35 ± 0.62|\n|episodic_miniimagenet|resnet12|64.82 ± 0.89|80.59 ± 0.64|\n|episodic_miniimagenet|wrn|69.92 ± 0.81|83.64 ± 0.54|\n|episodic_tiered-imagenet|conv4|58.63 ± 0.92|72.80 ± 0.78|\n|episodic_tiered-imagenet|resnet12|75.90 ± 0.90|86.83 ± 0.58|\n|episodic_tiered-imagenet|wrn|78.46 ± 0.90|87.46 ± 0.62|\n\nDifferent from the paper, these results were obtained on a run with fixed hyperparameters during fine-tuning: lr=0.001, alpha=0.2 (now default), train_iters=600, classification_weight=0.1\n\n### Pre-trained weights\nhttps://zenodo.org/record/5552602#.YV2b-UbMKvU\n\n## Citation\n```\n@article{rodriguez2020embedding,\n  title={Embedding Propagation: Smoother Manifold for Few-Shot Classification},\n  author={Pau Rodríguez and Issam Laradji and Alexandre Drouin and Alexandre Lacoste},\n  year={2020},\n  journal={arXiv preprint arXiv:2003.04151},\n}\n```\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FServiceNow%2Fembedding-propagation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FServiceNow%2Fembedding-propagation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FServiceNow%2Fembedding-propagation/lists"}