-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
84 lines (75 loc) · 3 KB
/
run.py
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
import sys
sys.path.append("./")
from experiments.config import DS_PRETRAIN_HPARAMS, DS_TEST_HPARAMS
from pretrain import run_pretrain as pretrain
from test_knn import run_bootstrap as test_knn
from train import run_bootstrap as train
def run_approach_experiments(ds_pretrain_hparams: dict, ds_test_hparams: dict):
for ds_name, ds_pretrain_config in ds_pretrain_hparams.items():
############################ PROPOSED APPROACH
# 1) First, pretrain
# VICReg pretrained using labeled bounding boxes
# and random patches (Custom CNN and Resnet34)
for model_type in ["CustomCNN", "Resnet34"]:
pretrain(
ds_name=ds_name,
supervised_data=True,
model_type=model_type,
**ds_pretrain_config,
)
pretrain(
ds_name=ds_name,
supervised_data=False,
model_type=model_type,
**ds_pretrain_config,
)
# 2) Then, test using KNN
for spc in [1, 5, 10, 15, 20, 25, 30]:
for model_type in ["CustomCNN", "Resnet34"]:
# VICReg pretrained using labeled bounding boxes
# and random patches (Custom CNN and Resnet34)
test_knn(
ds_name=ds_name,
samples_per_class=spc,
model_type=model_type,
pretrained=True,
checkpoint_path=ds_test_hparams[ds_name][
f"{model_type.lower()}_bboxes"
],
)
test_knn(
ds_name=ds_name,
samples_per_class=spc,
model_type=model_type,
pretrained=True,
checkpoint_path=ds_test_hparams[ds_name][
f"{model_type.lower()}_patches"
],
)
############################ END PROPOSED APPROACH
############################ BASELINE APPROACH
# Flatten and pretrained Resnet34 on ImageNet
test_knn(
ds_name=ds_name,
samples_per_class=spc,
model_type="Flatten",
)
test_knn(
ds_name=ds_name,
samples_per_class=spc,
model_type="Resnet34",
pretrained=True,
)
# Supervised learning (Custom CNN and Resnet34)
for model_type in ["CustomCNN", "Resnet34"]:
train(
ds_name=ds_name,
samples_per_class=spc,
model_type=model_type,
pretrained=False,
epochs=ds_pretrain_config["epochs"],
batch_size=ds_pretrain_config["batch_size"],
)
############################ END BASELINE APPROACH
if __name__ == "__main__":
run_approach_experiments(DS_PRETRAIN_HPARAMS, DS_TEST_HPARAMS)