{"id":13564309,"url":"https://github.com/tristandeleu/pytorch-meta","last_synced_at":"2025-05-14T15:02:16.719Z","repository":{"id":41158723,"uuid":"160432571","full_name":"tristandeleu/pytorch-meta","owner":"tristandeleu","description":"A collection of extensions and data-loaders for few-shot learning \u0026 meta-learning in PyTorch","archived":false,"fork":false,"pushed_at":"2023-07-17T16:05:00.000Z","size":1133,"stargazers_count":2026,"open_issues_count":59,"forks_count":258,"subscribers_count":41,"default_branch":"master","last_synced_at":"2025-04-11T21:48:44.541Z","etag":null,"topics":["few-shot-learning","meta-learning","pytorch"],"latest_commit_sha":null,"homepage":"https://tristandeleu.github.io/pytorch-meta/","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/tristandeleu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-12-04T23:36:45.000Z","updated_at":"2025-04-10T13:50:44.000Z","dependencies_parsed_at":"2024-01-06T00:03:21.582Z","dependency_job_id":"ce5dca17-ff3c-40e7-8299-1dbb192219c0","html_url":"https://github.com/tristandeleu/pytorch-meta","commit_stats":{"total_commits":353,"total_committers":13,"mean_commits":"27.153846153846153","dds":0.2521246458923513,"last_synced_commit":"d55d89ebd47f340180267106bde3e4b723f23762"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristandeleu%2Fpytorch-meta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristandeleu%2Fpytorch-meta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristandeleu%2Fpytorch-meta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristandeleu%2Fpytorch-meta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tristandeleu","download_url":"https://codeload.github.com/tristandeleu/pytorch-meta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254168653,"owners_count":22026205,"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":["few-shot-learning","meta-learning","pytorch"],"created_at":"2024-08-01T13:01:29.521Z","updated_at":"2025-05-14T15:02:16.422Z","avatar_url":"https://github.com/tristandeleu.png","language":"Python","funding_links":[],"categories":["Python","AutoML","Profiling","Table of Contents","Scheduling","Tools and projects","Pytorch实用程序","Libraries"],"sub_categories":["Profiling","LLM","[Meta Reinforcement Learning]()"],"readme":"# Torchmeta\n[![PyPI](https://img.shields.io/pypi/v/torchmeta)](https://pypi.org/project/torchmeta/) [![Build Status](https://travis-ci.com/tristandeleu/pytorch-meta.svg?branch=master)](https://travis-ci.com/tristandeleu/pytorch-meta) [![Documentation](https://img.shields.io/badge/docs-torchmeta-blue)](https://tristandeleu.github.io/pytorch-meta/)\n\nA collection of extensions and data-loaders for few-shot learning \u0026 meta-learning in [PyTorch](https://pytorch.org/). Torchmeta contains popular meta-learning benchmarks, fully compatible with both [`torchvision`](https://pytorch.org/docs/stable/torchvision/index.html) and PyTorch's [`DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader).\n\n#### Features\n  - A unified interface for both few-shot classification and regression problems, to allow easy benchmarking on multiple problems and reproducibility.\n  - Helper functions for some popular problems, with default arguments from the literature.\n  - An thin extension of PyTorch's [`Module`](https://pytorch.org/docs/stable/nn.html#torch.nn.Module), called `MetaModule`, that simplifies the creation of certain meta-learning models (e.g. gradient based meta-learning methods). See the [MAML example](examples/maml) for an example using `MetaModule`.\n\n#### Datasets available\n  - **Few-shot regression** (toy problems):\n    - Sine waves ([Finn et al., 2017](https://arxiv.org/abs/1703.03400))\n    - Harmonic functions ([Lacoste et al., 2018](https://arxiv.org/abs/1806.07528))\n    - Sinusoid \u0026 lines ([Finn et al., 2018](https://arxiv.org/abs/1806.02817))\n  - **Few-shot classification** (image classification):\n    - Omniglot ([Lake et al., 2015](http://www.sciencemag.org/content/350/6266/1332.short)[, 2019](https://arxiv.org/abs/1902.03477))\n    - Mini-ImageNet ([Vinyals et al., 2016](https://arxiv.org/abs/1606.04080), [Ravi et al., 2017](https://openreview.net/forum?id=rJY0-Kcll))\n    - Tiered-ImageNet ([Ren et al., 2018](https://arxiv.org/abs/1803.00676))\n    - CIFAR-FS ([Bertinetto et al., 2018](https://arxiv.org/abs/1805.08136))\n    - Fewshot-CIFAR100 ([Oreshkin et al., 2018](https://arxiv.org/abs/1805.10123))\n    - Caltech-UCSD Birds ([Hilliard et al., 2019](https://arxiv.org/abs/1802.04376), [Wah et al., 2019](http://www.vision.caltech.edu/visipedia/CUB-200-2011.html))\n    - Double MNIST ([Sun, 2019](https://github.com/shaohua0116/MultiDigitMNIST))\n    - Triple MNIST ([Sun, 2019](https://github.com/shaohua0116/MultiDigitMNIST))\n  - **Few-shot segmentation** (semantic segmentation):\n    - Pascal5i 1-way Setup\n  - **Few-shot classification (tabular datasets)**\n    - Letter ([Frey \u0026 Slate, 1991](https://www.openml.org/d/6))\n    - One Hundred Plants (Margin) ([Mallah et al. 2013](https://www.openml.org/d/1491))\n    - One Hundred Plants (Shape) ([Mallah et al. 2013](https://www.openml.org/d/1492))\n    - One Hundred Plants (Texture) ([Mallah et al. 2013](https://www.openml.org/d/1493))\n    - Bach Choral Harmony ([Radicioni \u0026 Esposito, 2010](https://www.openml.org/d/4552))\n\n## Installation\nYou can install Torchmeta either using Python's package manager pip, or from source. To avoid any conflict with your existing Python setup, it is suggested to work in a virtual environment with [`virtualenv`](https://docs.python-guide.org/dev/virtualenvs/). To install `virtualenv`:\n```bash\npip install --upgrade virtualenv\nvirtualenv venv\nsource venv/bin/activate\n```\n\n#### Requirements\n - Python 3.6 or above\n - PyTorch 1.4 or above\n - Torchvision 0.5 or above\n\n#### Using pip\nThis is the recommended way to install Torchmeta:\n```bash\npip install torchmeta\n```\n\n#### From source\nYou can also install Torchmeta from source. This is recommended if you want to contribute to Torchmeta.\n```bash\ngit clone https://github.com/tristandeleu/pytorch-meta.git\ncd pytorch-meta\npython setup.py install\n```\n\n## Example\n\n#### Minimal example\nThis minimal example below shows how to create a dataloader for the 5-shot 5-way Omniglot dataset with Torchmeta. The dataloader loads a batch of randomly generated tasks, and all the samples are concatenated into a single tensor. For more examples, check the [examples](examples/) folder.\n```python\nfrom torchmeta.datasets.helpers import omniglot\nfrom torchmeta.utils.data import BatchMetaDataLoader\n\ndataset = omniglot(\"data\", ways=5, shots=5, test_shots=15, meta_train=True, download=True)\ndataloader = BatchMetaDataLoader(dataset, batch_size=16, num_workers=4)\n\nfor batch in dataloader:\n    train_inputs, train_targets = batch[\"train\"]\n    print('Train inputs shape: {0}'.format(train_inputs.shape))    # (16, 25, 1, 28, 28)\n    print('Train targets shape: {0}'.format(train_targets.shape))  # (16, 25)\n\n    test_inputs, test_targets = batch[\"test\"]\n    print('Test inputs shape: {0}'.format(test_inputs.shape))      # (16, 75, 1, 28, 28)\n    print('Test targets shape: {0}'.format(test_targets.shape))    # (16, 75)\n```\n\n#### Advanced example\nHelper functions are only available for some of the datasets available. However, all of them are available through the unified interface provided by Torchmeta. The variable `dataset` defined above is equivalent to the following\n```python\nfrom torchmeta.datasets import Omniglot\nfrom torchmeta.transforms import Categorical, ClassSplitter, Rotation\nfrom torchvision.transforms import Compose, Resize, ToTensor\nfrom torchmeta.utils.data import BatchMetaDataLoader\n\ndataset = Omniglot(\"data\",\n                   # Number of ways\n                   num_classes_per_task=5,\n                   # Resize the images to 28x28 and converts them to PyTorch tensors (from Torchvision)\n                   transform=Compose([Resize(28), ToTensor()]),\n                   # Transform the labels to integers (e.g. (\"Glagolitic/character01\", \"Sanskrit/character14\", ...) to (0, 1, ...))\n                   target_transform=Categorical(num_classes=5),\n                   # Creates new virtual classes with rotated versions of the images (from Santoro et al., 2016)\n                   class_augmentations=[Rotation([90, 180, 270])],\n                   meta_train=True,\n                   download=True)\ndataset = ClassSplitter(dataset, shuffle=True, num_train_per_class=5, num_test_per_class=15)\ndataloader = BatchMetaDataLoader(dataset, batch_size=16, num_workers=4)\n```\nNote that the dataloader, receiving the dataset, remains the same.\n\n## Citation\n\u003e Tristan Deleu, Tobias Würfl, Mandana Samiei, Joseph Paul Cohen, and Yoshua Bengio. Torchmeta: A Meta-Learning library for PyTorch, 2019 [[ArXiv](https://arxiv.org/abs/1909.06576)]\n\nIf you want to cite Torchmeta, use the following Bibtex entry:\n```\n@misc{deleu2019torchmeta,\n  title={{Torchmeta: A Meta-Learning library for PyTorch}},\n  author={Deleu, Tristan and W\\\"urfl, Tobias and Samiei, Mandana and Cohen, Joseph Paul and Bengio, Yoshua},\n  year={2019},\n  url={https://arxiv.org/abs/1909.06576},\n  note={Available at: https://github.com/tristandeleu/pytorch-meta}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftristandeleu%2Fpytorch-meta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftristandeleu%2Fpytorch-meta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftristandeleu%2Fpytorch-meta/lists"}