Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
* text=auto

*.py text eol=lf
*.yaml text eol=lf
*.yml text eol=lf
*.md text eol=lf
*.txt text eol=lf

*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.pdf binary
*.pt binary
*.pth binary
*.tar binary
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ celerybeat.pid

# Environments
.env
.env.*
!.env.example
.venv
env/
venv/
Expand Down Expand Up @@ -135,3 +137,14 @@ dmypy.json
.idea/
.vscode/
results/
results_smoke/

data/
pretrain/
tools/

# Model checkpoints and local experiment artifacts
*.ckpt
*.pt
*.pth
*.tar
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# [LibFewShot](https://arxiv.org/abs/2109.04898)
Make few-shot learning easy.


[LibFewShot: A Comprehensive Library for Few-shot Learning](https://www.computer.org/csdl/journal/tp/5555/01/10239698/1Qck3o85t60).
Wenbin Li, Ziyi Wang, Xuesong Yang, Chuanqi Dong, Pinzhuo Tian, Tiexin Qin, Jing Huo, Yinghuan Shi, Lei Wang, Yang Gao, Jiebo Luo. In TPAMI 2023.<br>
<img src='flowchart.png' width=1000/>
Expand Down Expand Up @@ -49,6 +48,32 @@ Please refer to [install.md](https://libfewshot-en.readthedocs.io/en/latest/inst

Complete tutorials can be found at [document](https://libfewshot-en.readthedocs.io/en/latest/)([中文文档](https://libfewshot-en.readthedocs.io/zh_CN/latest/index.html)).

## Command-line Usage

All standard entry points are config-driven; no local experiment path is
embedded in the scripts.

Train a model:

```bash
python run_trainer.py --config ./config/proto.yaml
```

Evaluate a result directory (the saved `config.yaml` is loaded automatically):

```bash
python run_test.py --result-path ./results/your-experiment
```

Resume training:

```bash
python run_trainer_resume.py --result-path ./results/your-experiment
```

Dataset paths and other common settings can still be overridden on the command
line. For example: `--data_root ./data/miniImageNet--ravi --n_gpu 1`.

## Reproduction
We provide some validated configs in [reproduce](./reproduce/), please refer to `./reproduce/<Method_Name>/README.md` for further infomations. The meanings of the symbols are as follows:

Expand Down
6 changes: 6 additions & 0 deletions config/backbones/resnet10.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
backbone:
name: resnet10
kwargs:
avg_pool: True
is_flatten: True
is_feature: False
2 changes: 1 addition & 1 deletion config/boil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ includes:
way_num: 5
shot_num: 5
query_num: 15
data_root: /data/wzy/miniImageNet--ravi
data_root: ./data/miniImageNet--ravi
image_size: 84
use_memory: False
augment: True
Expand Down
4 changes: 4 additions & 0 deletions config/classifiers/LDC.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
classifier:
name: LDC
kwargs:
paper_mode: true
14 changes: 14 additions & 0 deletions config/classifiers/LDPNet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
classifier:
name: LDPNet
kwargs:
lamba1: 1.0
lamba2: 0.15
momentum: 0.998
beta: 0.5
query_aug_times: 1
use_lr_classifier: True
transductive: False
transductive_iter: 7
transductive_k: 10
lr_max_iter: 1000
local_query_crops: 0
2 changes: 1 addition & 1 deletion config/frn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ augment_method: DeepBdcAugment

# pre_training: True
# data_root: /data/fewshot/miniImageNet--ravi/
data_root: /data/fewshot/tiered_imagenet/
data_root: ./data/tiered_imagenet
backbone:
name: resnet12
kwargs:
Expand Down
3 changes: 2 additions & 1 deletion config/headers/data.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
data_root: /data/fewshot/miniImageNet--ravi
data_root: ./data/miniImageNet--ravi
image_size: 84
use_memory: False
augment: True
augment_times: 1
augment_times_query: 1
workers: 8 # number of workers for dataloader in all threads
pin_memory: True
dataloader_num: 1
62 changes: 62 additions & 0 deletions config/ldc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
includes:
- headers/data.yaml
- headers/device.yaml
- headers/misc.yaml
- headers/model.yaml
- headers/optimizer.yaml
- classifiers/LDC.yaml
- backbones/Conv64F.yaml

# LDC paper-mode example. Change these fields when switching datasets/shots.
# The author repository can also be selected with the LDC_ROOT environment variable.
ldc_root: ../LDC
data_root: ./data/EuroSAT
dataset_name: eurosat
path_prefix: "2750"

clip_model: RN50
device: cuda
device_ids: 0
n_gpu: 1
seed: 2024
deterministic: True

shot_num: 1
way_num: 10
query_num: 1
test_way: 10
test_shot: 1
test_query: 1
episode_size: 1
train_episode: 1
test_episode: 1

epoch: 50
batch_size: 64
eval_batch_size: 64
workers: 0
num_workers: 0
pin_memory: False
image_size: 224

lr: 0.001
weight_decay: 0.0001
eps: 0.0001
fuse_type: 2
loss_lambda:
- 1.0
- 1.0
- 1.0
- 1.0
- 1.0

optimizer:
name: AdamW
kwargs:
lr: 0.0001
weight_decay: 0.0001

lr_scheduler:
name: CosineAnnealingLR
kwargs:
T_max: 50
70 changes: 70 additions & 0 deletions config/ldp_net.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
includes:
- headers/data.yaml
- headers/device.yaml
- headers/misc.yaml
- headers/model.yaml
- headers/optimizer.yaml
- classifiers/LDPNet.yaml
- backbones/resnet10.yaml

classifier:
name: LDPNet
kwargs:
lamba1: 1.0
lamba2: 0.15
momentum: 0.998
beta: 0.5
query_aug_times: 1
use_lr_classifier: True
transductive: False
transductive_iter: 7
transductive_k: 10
lr_max_iter: 1000
local_query_crops: 6

data_root: ./data/miniImageNet--ravi
image_size: 224
augment: True
augment_times: 1
augment_times_query: 1
augment_method: S2M2Augment
ldp_local_crops: 6
ldp_local_size: 96
use_memory: False
workers: 4
pin_memory: False

device_ids: 0
n_gpu: 1
seed: 1111
deterministic: True
epoch: 100
val_per_epoch: 101
way_num: 5
shot_num: 5
query_num: 15
test_way: 5
test_shot: 5
test_query: 15
episode_size: 1
train_episode: 100
test_episode: 600

pretrain_path: ./pretrain/399.tar
result_root: ./results
save_interval: 10
save_part:
- emb_func
test_checkpoint: model_last.pth

optimizer:
name: Adam
kwargs:
lr: 0.001
other: ~

lr_scheduler:
name: StepLR
kwargs:
gamma: 1.0
step_size: 100
4 changes: 2 additions & 2 deletions config/matchingnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ backbone:
avg_pool: True
is_flatten: True

pretrain_path: /data1/student/stx/ML/FSL/pretrained/IfslPretrain-miniImageNet-resnet12-5-1-Jun-02-2024-19-27-07/checkpoints/emb_func_best.pth
pretrain_path: ./pretrain/IfslPretrain-miniImageNet-resnet12/emb_func_best.pth
classifier:
name: DMatchingNet
kwargs:
Expand Down Expand Up @@ -58,4 +58,4 @@ classifier:
use_x_only: False
normalize_before_center: False
normalize_d: False
normalize_ed: False
normalize_ed: False
2 changes: 1 addition & 1 deletion config/metal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ includes:
- headers/model.yaml
- headers/optimizer.yaml

data_root: /data/Libfewshot/tiered_imagenet
data_root: ./data/tiered_imagenet
way_num: 5
shot_num: 1

Expand Down
Loading