{"id":13422233,"url":"https://github.com/kjunelee/MetaOptNet","last_synced_at":"2025-03-15T11:31:27.803Z","repository":{"id":44396034,"uuid":"155912925","full_name":"kjunelee/MetaOptNet","owner":"kjunelee","description":"Meta-Learning with Differentiable Convex Optimization (CVPR 2019 Oral)","archived":false,"fork":false,"pushed_at":"2024-07-25T10:15:57.000Z","size":2915,"stargazers_count":520,"open_issues_count":13,"forks_count":95,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-07-31T23:45:02.424Z","etag":null,"topics":["convex-optimization","cvpr2019","few-shot","few-shot-learning","few-shot-recognition","image-classification","meta-learning","metalearning"],"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/kjunelee.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":"2018-11-02T19:32:50.000Z","updated_at":"2024-07-31T04:09:27.000Z","dependencies_parsed_at":"2023-01-30T18:30:39.409Z","dependency_job_id":null,"html_url":"https://github.com/kjunelee/MetaOptNet","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/kjunelee%2FMetaOptNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjunelee%2FMetaOptNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjunelee%2FMetaOptNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjunelee%2FMetaOptNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kjunelee","download_url":"https://codeload.github.com/kjunelee/MetaOptNet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221572069,"owners_count":16845574,"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":["convex-optimization","cvpr2019","few-shot","few-shot-learning","few-shot-recognition","image-classification","meta-learning","metalearning"],"created_at":"2024-07-30T23:00:40.019Z","updated_at":"2024-10-26T19:32:35.918Z","avatar_url":"https://github.com/kjunelee.png","language":"Python","funding_links":[],"categories":["Meta-Learning with Differentiable Convex Optimization. CVPR 2019 (Oral)"],"sub_categories":[],"readme":"# Meta-Learning with Differentiable Convex Optimization\nThis repository contains the code for the paper:\n\u003cbr\u003e\n[**Meta-Learning with Differentiable Convex Optimization**](https://arxiv.org/pdf/1904.03758.pdf)\n\u003cbr\u003e\nKwonjoon Lee, [Subhransu Maji](https://people.cs.umass.edu/~smaji/), Avinash Ravichandran, [Stefano Soatto](http://web.cs.ucla.edu/~soatto/)   \nCVPR 2019 (**Oral**)\n\u003cp align='center'\u003e\n  \u003cimg src='algorithm.png' width=\"800px\"\u003e\n\u003c/p\u003e\n\n### Abstract\n\nMany meta-learning approaches for few-shot learning rely on simple base learners such as nearest-neighbor classifiers. However, even in the few-shot regime, discriminatively trained linear predictors can offer better generalization. We propose to use these predictors as base learners to learn representations for few-shot learning and show they offer better tradeoffs between feature size and performance across a range of few-shot recognition benchmarks. Our objective is to learn feature embeddings that generalize well under a linear classification rule for novel categories. To efficiently solve the objective, we exploit two properties of linear classifiers: implicit differentiation of the optimality conditions of the convex problem and the dual formulation of the optimization problem. This allows us to use high-dimensional embeddings with improved generalization at a modest increase in computational overhead. Our approach, named MetaOptNet, achieves state-of-the-art performance on miniImageNet, tieredImageNet, CIFAR-FS and FC100 few-shot learning benchmarks.\n\n### Citation\n\nIf you use this code for your research, please cite our paper:\n```\n@inproceedings{lee2019meta,\n  title={Meta-Learning with Differentiable Convex Optimization},\n  author={Kwonjoon Lee and Subhransu Maji and Avinash Ravichandran and Stefano Soatto},\n  booktitle={CVPR},\n  year={2019}\n}\n```\n\n## Dependencies\n* Python 2.7+ (not tested on Python 3)\n* [PyTorch 0.4.0+](http://pytorch.org)\n* [qpth 0.0.11+](https://github.com/locuslab/qpth)\n* [tqdm](https://github.com/tqdm/tqdm)\n\n## Usage\n\n### Installation\n\n1. Clone this repository:\n    ```bash\n    git clone https://github.com/kjunelee/MetaOptNet.git\n    cd MetaOptNet\n    ```\n2. Download and decompress dataset files: [**miniImageNet**](https://drive.google.com/file/d/12V7qi-AjrYi6OoJdYcN_k502BM_jcP8D/view?usp=sharing) (courtesy of [**Spyros Gidaris**](https://github.com/gidariss/FewShotWithoutForgetting)), [**tieredImageNet**](https://drive.google.com/open?id=1nVGCTd9ttULRXFezh4xILQ9lUkg0WZCG), [**FC100**](https://drive.google.com/file/d/1_ZsLyqI487NRDQhwvI7rg86FK3YAZvz1/view?usp=sharing), [**CIFAR-FS**](https://drive.google.com/file/d/1GjGMI0q3bgcpcB_CjI40fX54WgLPuTpS/view?usp=sharing)\n\n3. For each dataset loader, specify the path to the directory. For example, in MetaOptNet/data/mini_imagenet.py line 30:\n    ```python\n    _MINI_IMAGENET_DATASET_DIR = 'path/to/miniImageNet'\n    ```\n\n### Meta-training\n1. To train MetaOptNet-SVM on 5-way miniImageNet benchmark:\n    ```bash\n    python train.py --gpu 0,1,2,3 --save-path \"./experiments/miniImageNet_MetaOptNet_SVM\" --train-shot 15 \\\n    --head SVM --network ResNet --dataset miniImageNet --eps 0.1\n    ```\n    As shown in Figure 2, of our paper, we can meta-train the embedding once with a high shot for all meta-testing shots. We don't need to meta-train with all possible meta-test shots unlike in Prototypical Networks.\n2. You can experiment with varying base learners by changing '--head' argument to ProtoNet or Ridge. Also, you can change the backbone architecture to vanilla 4-layer conv net by setting '--network' argument to ProtoNet. For other arguments, please see MetaOptNet/train.py from lines 85 to 114.\n3. To train MetaOptNet-SVM on 5-way tieredImageNet benchmark:\n    ```bash\n    python train.py --gpu 0,1,2,3 --save-path \"./experiments/tieredImageNet_MetaOptNet_SVM\" --train-shot 10 \\\n    --head SVM --network ResNet --dataset tieredImageNet\n    ```\n3. To train MetaOptNet-RR on 5-way CIFAR-FS benchmark:\n    ```bash\n    python train.py --gpu 0 --save-path \"./experiments/CIFAR_FS_MetaOptNet_RR\" --train-shot 5 \\\n    --head Ridge --network ResNet --dataset CIFAR_FS\n    ```\n4. To train MetaOptNet-RR on 5-way FC100 benchmark:\n    ```bash\n    python train.py --gpu 0 --save-path \"./experiments/FC100_MetaOptNet_RR\" --train-shot 15 \\\n    --head Ridge --network ResNet --dataset FC100\n    ```\n### Meta-testing\n1. To test MetaOptNet-SVM on 5-way miniImageNet 1-shot benchmark:\n```\npython test.py --gpu 0,1,2,3 --load ./experiments/miniImageNet_MetaOptNet_SVM/best_model.pth --episode 1000 \\\n--way 5 --shot 1 --query 15 --head SVM --network ResNet --dataset miniImageNet\n```\n2. Similarly, to test MetaOptNet-SVM on 5-way miniImageNet 5-shot benchmark:\n```\npython test.py --gpu 0,1,2,3 --load ./experiments/miniImageNet_MetaOptNet_SVM/best_model.pth --episode 1000 \\\n--way 5 --shot 5 --query 15 --head SVM --network ResNet --dataset miniImageNet\n```\n\n## Acknowledgments\n\nThis code is based on the implementations of [**Prototypical Networks**](https://github.com/cyvius96/prototypical-network-pytorch),  [**Dynamic Few-Shot Visual Learning without Forgetting**](https://github.com/gidariss/FewShotWithoutForgetting), and [**DropBlock**](https://github.com/miguelvr/dropblock).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkjunelee%2FMetaOptNet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkjunelee%2FMetaOptNet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkjunelee%2FMetaOptNet/lists"}