-
Notifications
You must be signed in to change notification settings - Fork 148
/
Makefile
128 lines (108 loc) · 3.85 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Checks
lint:
pylint easyfsl scripts
test:
pytest easyfsl
isort:
isort easyfsl scripts
isort-check:
isort easyfsl scripts --check
black:
black easyfsl scripts
black-check:
black easyfsl scripts --check
mypy:
mypy easyfsl scripts
# Install
dev-install:
pip install -r dev_requirements.txt
# Download data
# Google Drive sometimes blocks wget downloads. If this recipe doesn't work, download the archive manually from https://docs.google.com/uc?export=download&id=1GDr1OkoXdhaXWGA8S3MAq3a522Tak-nx
download-cub:
mkdir -p data/CUB
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1GDr1OkoXdhaXWGA8S3MAq3a522Tak-nx' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1GDr1OkoXdhaXWGA8S3MAq3a522Tak-nx" -O data/CUB/images.tgz
rm -rf /tmp/cookies.txt
tar --exclude='._*' -zxvf data/CUB/images.tgz -C data/CUB/
# Benchmarks
BATCH_SIZE=1024
NUM_WORKERS=12
MODEL_CHECKPOINTS_DIR=data/models
DEVICE=cuda
extract-mini-imagenet-features-with-resnet12:
python -m scripts.predict_embeddings \
feat_resnet12 \
${MODEL_CHECKPOINTS_DIR}/feat_resnet12_mini_imagenet.pth \
mini_imagenet \
--device=${DEVICE} \
--num-workers=${NUM_WORKERS} \
--batch-size=${BATCH_SIZE}
extract-features-with-resnet12-trained-on-tiered-imagenet:
for target_dataset in cub tiered_imagenet fungi; do \
python -m scripts.predict_embeddings \
feat_resnet12 \
${MODEL_CHECKPOINTS_DIR}/feat_resnet12_tiered_imagenet.pth \
$${target_dataset} \
--device=${DEVICE} \
--num-workers=${NUM_WORKERS} \
--batch-size=${BATCH_SIZE}; \
done; \
extract-all-features-with-resnet12:
make extract-mini-imagenet-features-with-resnet12 ; \
make extract-features-with-resnet12-trained-on-tiered-imagenet ; \
benchmark-mini-imagenet:
for n_shot in 1 5; do \
for method in bd_cspn prototypical_networks simple_shot tim finetune laplacian_shot pt_map transductive_finetuning; do \
python -m scripts.benchmark_methods \
$${method} \
data/features/mini_imagenet/test/feat_resnet12_mini_imagenet.parquet.gzip \
--config="default" \
--n-shot=$${n_shot} \
--device=${DEVICE} \
--num-workers=${NUM_WORKERS}; \
done; \
python -m scripts.benchmark_methods \
feat \
data/features/mini_imagenet/test/feat_resnet12_mini_imagenet.parquet.gzip \
--config="resnet12_mini_imagenet" \
--n-shot=$${n_shot} \
--device=${DEVICE} \
--num-workers=${NUM_WORKERS}; \
done
benchmark-tiered-imagenet:
for n_shot in 1 5; do \
for method in bd_cspn prototypical_networks simple_shot tim finetune laplacian_shot pt_map transductive_finetuning; do \
python -m scripts.benchmark_methods \
$${method} \
data/features/tiered_imagenet/test/feat_resnet12_tiered_imagenet.parquet.gzip \
--config="default" \
--n-shot=$${n_shot} \
--device=${DEVICE} \
--num-workers=${NUM_WORKERS}; \
done; \
python -m scripts.benchmark_methods \
feat \
data/features/tiered_imagenet/test/feat_resnet12_tiered_imagenet.parquet.gzip \
--config="resnet12_tiered_imagenet" \
--n-shot=$${n_shot} \
--device=${DEVICE} \
--num-workers=${NUM_WORKERS}; \
done
# Hyperparameter search
extract-mini-imagenet-val-features-with-resnet12:
python -m scripts.predict_embeddings \
feat_resnet12 \
${MODEL_CHECKPOINTS_DIR}/feat_resnet12_mini_imagenet.pth \
mini_imagenet \
--split=val \
--device=${DEVICE} \
--num-workers=${NUM_WORKERS} \
--batch-size=${BATCH_SIZE}
hyperparameter-search:
for method in tim finetune pt_map laplacian_shot transductive_finetuning; do \
python -m scripts.hyperparameter_search \
$${method} \
data/features/mini_imagenet/val/feat_resnet12_mini_imagenet.parquet.gzip \
--n-shot=5 \
--device=${DEVICE} \
--num-workers=${NUM_WORKERS}; \
done;