easyfsl
Ready-to-use code and tutorial notebooks to boost your way into few-shot learning for image classification.
Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
2 of 13 committers (15.4%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.6%) to scientific vocabulary
Keywords
Repository
Ready-to-use code and tutorial notebooks to boost your way into few-shot learning for image classification.
Basic Info
Statistics
- Stars: 1,242
- Watchers: 16
- Forks: 168
- Open Issues: 18
- Releases: 12
Topics
Metadata Files
README.md
Easy Few-Shot Learning
Ready-to-use code and tutorial notebooks to boost your way into few-shot image classification. This repository is made for you if:
- you're new to few-shot learning and want to learn;
- or you're looking for reliable, clear and easily usable code that you can use for your projects.
Don't get lost in large repositories with hundreds of methods and no explanation on how to use them. Here, we want each line of code to be covered by a tutorial.
What's in there?
Notebooks: learn and practice
You want to learn few-shot learning and don't know where to start? Start with our tutorials.
| Notebook | Description | Colab |
|------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| First steps into few-shot image classification | Basically Few-Shot Learning 101, in less than 15min. | |
| Example of episodic training | Use it as a starting point if you want to design a script for episodic training using EasyFSL. |
|
| Example of classical training | Use it as a starting point if you want to design a script for classical training using EasyFSL. |
|
| Test with pre-extracted embeddings | Most few-shot methods use a frozen backbone at test-time. With EasyFSL, you can extract all embeddings for your dataset once and for all, and then perform inference directly on embeddings. |
|
Code that you can use and understand
State-Of-The-Art Few-Shot Learning methods:
With 11 built-in methods, EasyFSL is the most comprehensive open-source Few-Shot Learning library!
- Prototypical Networks
- SimpleShot
- Matching Networks
- Relation Networks
- FEAT
- Fine-Tune
- BD-CSPN
- LaplacianShot
- Transductive Information Maximization
- PT-MAP
- Transductive Fine-Tuning
We also provide a FewShotClassifier class to quickstart your implementation of any few-shot classification algorithm, as well as commonly used architectures.
See the benchmarks section below for more details on the methods.
Tools for data loading:
Data loading in FSL is a bit different from standard classification because we sample batches of instances in the shape of few-shot classification tasks. No sweat! In EasyFSL you have:
- TaskSampler: an extension of the standard PyTorch Sampler object, to sample batches in the shape of few-shot classification tasks
- FewShotDataset: an abstract class to standardize the interface of any dataset you'd like to use
- EasySet: a ready-to-use FewShotDataset object to handle datasets of images with a class-wise directory split
- WrapFewShotDataset: a wrapper to transform any dataset into a FewShotDataset object
- FeaturesDataset: a dataset to handle pre-extracted features
- SupportSetFolder: a dataset to handle support sets stored in a directory
Scripts to reproduce our benchmarks:
scripts/predict_embeddings.pyto extract all embeddings from a dataset with a given pre-trained backbonescripts/benchmark_methods.pyto evaluate a method on a test dataset using pre-extracted embeddings.
And also: some utilities that I felt I often used in my research, so I'm sharing with you.
Datasets to test your model
There are enough datasets used in Few-Shot Learning for anyone to get lost in them. They're all here, explicited, downloadable and easy-to-use, in EasyFSL.
We provide a make download-cub recipe to download and extract the dataset,
along with the standard (train / val / test) split along classes.
Once you've downloaded the dataset, you can instantiate the Dataset objects in your code
with this super complicated process:
```python from easyfsl.datasets import CUB
trainset = CUB(split="train", training=True) testset = CUB(split="test", training=False) ```
To use it, you need the ILSVRC2015 dataset. Once you have downloaded and extracted the dataset, ensure that its localisation on disk is consistent with the class paths specified in the specification files. Then:
```python from easyfsl.datasets import TieredImageNet
trainset = TieredImageNet(split="train", training=True) testset = TieredImageNet(split="test", training=False) ```
Same as tieredImageNet, we provide the specification files, but you need the ILSVRC2015 dataset. Once you have it:
```python from easyfsl.datasets import MiniImageNet
trainset = MiniImageNet(root="where/imagenet/is", split="train", training=True) testset = MiniImageNet(root="where/imagenet/is", split="test", training=False) ```
Since miniImageNet is relatively small, you can also load it on RAM directly at instantiation simply by
adding load_on_ram=True to the constructor.
It takes a few minutes but it can make your training significantly faster!
I've recently started using it as a Few-Shot Learning benchmarks, and I can tell you it's a great playing field. To use it, first download the data:
```shell
Download the original dataset (/!\ 110GB)
wget http://ptak.felk.cvut.cz/plants/DanishFungiDataset/DF20-train_val.tar.gz
Or alternatively the images reduced to 300px (6.5Gb)
wget http://ptak.felk.cvut.cz/plants/DanishFungiDataset/DF20-300px.tar.gz
And finally download the metadata (83Mb) to data/fungi/
wget https://public-sicara.s3.eu-central-1.amazonaws.com/easy-fsl/DF20metadata.csv -O data/fungi/DF20metadata.csv ```
And then instantiate the dataset with the same process as always:
```python from easyfsl.datasets import DanishFungi
dataset = DanishFungi(root="where/fungi/is") ```
Note that I didn't specify a train and test set because the CSV I gave you describes the whole dataset. I recommend to use it to test models with weights trained on an other dataset (like ImageNet). But if you want to propose a train/val/test split along classes, you're welcome to contribute!
QuickStart
Install the package:
pip install easyfslor simply fork the repository.Design your training and evaluation scripts. You can use our example notebooks for episodic training or classical training.
Contribute
This project is very open to contributions! You can help in various ways: - raise issues - resolve issues already opened - tackle new features from the roadmap - fix typos, improve code quality
Benchmarks
We used EasyFSL to benchmark a dozen methods. Inference times are computed over 1000 tasks using pre-extracted features. They are only indicative. Note that the inference time for fine-tuning methods highly depends on the number of fine-tuning steps.
All methods hyperparameters are defined in this JSON file.
They were selected on miniImageNet validation set.
The procedure can be reproduced with make hyperparameter-search.
We decided to use miniImageNet's hyperparameters for all benchmarks in order to highlight the adaptability of
the different methods.
Note that all methods use L2 normalization of features, except for FEAT as it harms its performance.
There are no results for Mathing and Relation Networks as the trained weights for their additional modules are unavailable.
miniImageNet & tieredImageNet
All methods use the same backbone: a custom ResNet12 using the trained parameters provided by the authors from FEAT (download: miniImageNet, tieredImageNet).
Best inductive and best transductive results for each column are shown in bold.
| Method | Ind / Trans | miniImagenet
1-shot | miniImagenet
5-shot | tieredImagenet
1-shot | tieredImagenet
5-shot | Time |
|---------------------------------------------------------------------------|--------------|---------------------------|---------------------------|-----------------------------|-----------------------------|---------|
| ProtoNet | Inductive | 63.6 | 80.4 | 60.2 | 77.4 | 6s |
| SimpleShot | Inductive | 63.6 | 80.5 | 60.2 | 77.4 | 6s |
| MatchingNet | Inductive | - | - | - | - | - |
| RelationNet | Inductive | - | - | - | - | - |
| Finetune | Inductive | 63.3 | 80.5 | 59.8 | 77.5 | 1mn33s |
| FEAT | Inductive | 64.7 | 80.1 | 61.3 | 76.2 | 3s |
| BD-CSPN | Transductive | 69.8 | 82.2 | 66.3 | 79.1 | 7s |
| LaplacianShot | Transductive | 69.8 | 82.3 | 66.2 | 79.2 | 9s |
| PT-MAP | Transductive | 76.1 | 84.2 | 71.7 | 80.7 | 39mn40s |
| TIM | Transductive | 74.3 | 84.2 | 70.7 | 80.7 | 3mn05s |
| Transductive Finetuning | Transductive | 63.0 | 80.6 | 59.1 | 77.5 | 30s |
To reproduce:
- Download the miniImageNet
and tieredImageNet weights for ResNet12
and save them under
data/models/feat_resnet12_mini_imagenet.pth(resp.tiered). - Extract all embeddings from the test sets of all datasets with
make extract-all-features-with-resnet12. - Run the evaluation scripts with
make benchmark-mini-imagenet(resp.tiered).
Owner
- Name: Sicara
- Login: sicara
- Kind: organization
- Email: contact@sicara.com
- Location: Paris, France
- Website: https://www.sicara.com/
- Repositories: 36
- Profile: https://github.com/sicara
Citation (CITATION.cff)
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!
cff-version: 1.2.0
title: easyfsl
message: >-
If you use easyfsl in your research, please cite it
using these metadata.
type: software
authors:
- given-names: Etienne
family-names: Bennequin
email: etienneb@sicara.com
affiliation: Université Paris-Saclay
repository-code: 'https://github.com/sicara/easy-few-shot-learning'
abstract: >-
Ready-to-use code and tutorial notebooks to boost
your way into few-shot image classification.
license: MIT
GitHub Events
Total
- Issues event: 6
- Watch event: 193
- Issue comment event: 3
- Push event: 3
- Fork event: 21
Last Year
- Issues event: 6
- Watch event: 193
- Issue comment event: 3
- Push event: 3
- Fork event: 21
Committers
Last synced: 11 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| etienne | e****n@g****m | 136 |
| Diego Silva | d****m@g****m | 4 |
| Toubi | a****e@t****g | 4 |
| tnwei | 1****i | 1 |
| mgmalana | m****a@g****m | 1 |
| egarcol | g****1@h****m | 1 |
| dlfelps | d****s@g****m | 1 |
| Vihanga Ashinsana Wijayasekara | 9****W | 1 |
| Gen | 5****9 | 1 |
| Dmytro Durach | 9****h | 1 |
| Dave Moffat | d****f@p****k | 1 |
| Aml Hassan Esmil | A****4@f****g | 1 |
| Alan Q. Wang | 6****g | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 111
- Total pull requests: 49
- Average time to close issues: 2 months
- Average time to close pull requests: 4 days
- Total issue authors: 82
- Total pull request authors: 12
- Average comments per issue: 2.55
- Average comments per pull request: 0.29
- Merged pull requests: 46
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 7
- Pull requests: 0
- Average time to close issues: 2 days
- Average time to close pull requests: N/A
- Issue authors: 6
- Pull request authors: 0
- Average comments per issue: 0.43
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- shraddha291996 (8)
- vsantjr (4)
- ghos1y (3)
- cy2333ytu (3)
- ebennequin (3)
- TeddyPorfiris (2)
- ssx12042 (2)
- Kunika05 (2)
- HowCuteIsBee2002018 (2)
- karndeepsingh (2)
- deemoe404 (2)
- mzhadigerov (2)
- Anin1 (2)
- charurathour (2)
- haricash (2)
Pull Request Authors
- ebennequin (37)
- NMZ0429 (2)
- dlfelps (2)
- djmoffat (1)
- VihangaAW (1)
- diego91964 (1)
- mgmalana (1)
- tnwei (1)
- alanqrwang (1)
- Aml-Hassan-Abd-El-hamid (1)
- egarcol (1)
- durach (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 953 last-month
- Total dependent packages: 0
- Total dependent repositories: 4
- Total versions: 10
- Total maintainers: 1
pypi.org: easyfsl
Ready-to-use PyTorch code to boost your way into few-shot image classification
- Homepage: https://github.com/sicara/easy-few-shot-learning
- Documentation: https://easyfsl.readthedocs.io/
- License: MIT
-
Latest release: 1.5.0
published over 2 years ago
Rankings
Maintainers (1)
Dependencies
- black >=20.8b1
- jupyter >=1.0.0
- loguru >=0.5.3
- matplotlib >=3.3.4
- pandas >=1.1.0
- pylint ==2.8.2
- pytest ==6.2.2
- pytest-mock ==3.6.1
- tensorboard >=2.8.0
- torch >=1.9.0
- torchvision >=0.10.0
- tqdm >=4.56.0
- matplotlib >=3.0.0
- pandas >=1.1.0
- torch >=1.4.0
- torchvision >=0.7.0
- tqdm >=4.1.0