TripletMAML implements a novel few-shot learning approach by integrating triplet-loss-based metric learning within the Model-Agnostic Meta-Learning (MAML) framework. This repository supports both classification and retrieval tasks while providing reproducible, transparent, and well-documented experiments.
- Citation
- Overview
- Features
- Installation & Dependencies
- Dataset Preparation
- Usage
- Directory Structure
- Detailed Documentation
- Permanent Links & Reproducibility
If you find TripletMAML useful in your research, please use the following BibTeX entry for citation.
@misc{gulcu2025tripletmaml,
author = {Ayla Gülcü, Zeki Kuş, İsmail Taha Samed Özkan and Osman Furkan Karakuş},
title = {TripletMAML: A metric-based model-agnostic meta-learning algorithm for few-shot classification},
howpublished = {\url{https://github.com/aylagulcu/TripletMAML}},
journal = {The Visual Computer}
year = {2025}
}TripletMAML leverages the strengths of both meta-learning and metric-based learning to tackle the challenges of few-shot classification. By incorporating a triplet loss into the MAML framework, the algorithm learns robust and discriminative feature representations even when data is scarce. This repository includes:
- Classification Tasks: Training and evaluation scripts for few-shot classification.
- Retrieval Tasks: Scripts to test the retrieval capability using learned embeddings.
- Interactive Experimentation: A Jupyter Notebook for task control and hyperparameter tuning.
- Few-Shot Learning: Designed specifically for few-shot scenarios.
- Metric-Based Learning: Uses triplet loss to improve representation learning.
- Meta-Learning Framework: Builds on MAML for fast adaptation to new tasks.
- Comprehensive Dataset Support: Includes scripts and instructions for Omniglot, MiniImageNet, CUB-200-2011, and CIFAR Few-Shot.
- Detailed Documentation: Clear instructions, algorithm details, and permanent link assurance for reproducibility.
- Operating System: Ubuntu 20.04 LTS is recommended.
- Python Version: 3.9.7 (Anaconda distribution is suggested).
python== 3.9.7learn2learn== 0.1.7numpy== 1.20.3pytorch== 1.10.2 (compatible with py3.9_cuda11.3_cudnn8.2.0_0)scikit-learn== 1.2.0
git clone https://github.com/aylagulcu/TripletMAML.git
cd TripletMAML
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt| Dataset | Download | Download Needed |
|---|---|---|
| Omniglot | download | NO |
| MiniImageNet | download | NO |
| CUB-200-2011 | download | YES |
| CIFAR Few-Shot | download | YES |
- for Omniglot
TripletOmniglot.py Files will handle downloading automatically if download mode is set as True. - for MiniImageNet
./data/MiniImageNet/MiniImageNet_downloader.py will handle downloading test-train-validation files accordingly. No needed to install another dataset. - for CUB-200-2011
CUB-200-2011 files are needed to be downloaded from given link. Then replaced into corresponding folder which is ./data/CUB/ Choose the generator of your preference so they can create the test-train-validation files accordingly. - for CIFAR Few-Shot
CIFAR Few-Shot files are needed to be downloaded from given link. Then replaced into corresponding folder which is ./data/CIFARFS100/ First run the processor then you can use generator to create the test-train-validation files accordingly.
python TripletMAML/maml_triplet_train_test_val.pypython TripletMAML/maml_triplet_test_retrieval.pyOpen:
TripletMAML/TaskControl.ipynb|—— .gitignore
|—— data
| |—— Generators
| |—— CIFARFS100
| |—— CIFARFS100_generator.py
| |—— CIFARFS100_processor.py
| |—— CUB
| |—— CUB_BB_NoResize_generator.py
| |—— CUB_BB_Resize_generator.py
| |—— CUB_NoBB_generator.py
| |—— Flowers
| |—— Flowers_generator.py
| |—— MiniImageNet
| |—— MiniImageNet_downloader.py
|—— HPO
| |—— backbone.py
| |—— de.py
| |—— losses.py
| |—— model.py
| |—— rs.py
| |—— train.py
| |—— Triplets
| |—— TripletCUB.py
| |—— TripletFlowers.py
| |—— TripletFSCIFAR100.py
| |—— TripletMiniImageNet.py
| |—— TripletOmniglot.py
| |—— __init__.py
|—— TripletMAML
| |—— backbone.py
| |—— losses.py
| |—— maml_triplet_test_retrieval.py
| |—— maml_triplet_train_test_val.py
| |—— TaskControl.ipynb
| |—— Triplets
| |—— TripletCUB.py
| |—— TripletFlowers.py
| |—— TripletFSCIFAR100.py
| |—— TripletMiniImageNet.py
| |—— TripletOmniglot.py
| |—— __init__.py
- Triplet Loss: Enhances feature separability across classes.
- MAML: Allows quick adaptation using meta-learning.
- Integration: Triplet loss is incorporated in the inner loop of MAML.
backbone.py: Defines the neural network architecture.losses.py: Implements the triplet loss.maml_triplet_train_test_val.py: Training and validation logic.maml_triplet_test_retrieval.py: Retrieval evaluation logic.
- Prepare dataset.
- Configure parameters in the relevant script.
- Run the experiment (see Usage section).
All dataset and code links are verified to be permanent. This documentation is designed for full reproducibility by other researchers.
