-
Notifications
You must be signed in to change notification settings - Fork 36
/
__init__.py
executable file
·179 lines (171 loc) · 4.48 KB
/
__init__.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
from engine.config import default
from engine.datasets import dataset_classes
import argparse
parser = argparse.ArgumentParser()
###########################
# Directory Config (modify if using your own paths)
###########################
parser.add_argument(
"--data_dir",
type=str,
default=default.DATA_DIR,
help="where the dataset is saved",
)
parser.add_argument(
"--indices_dir",
type=str,
default=default.FEW_SHOT_DIR,
help="where the (few-shot) indices is saved",
)
parser.add_argument(
"--feature_dir",
type=str,
default=default.FEATURE_DIR,
help="where to save pre-extracted features",
)
parser.add_argument(
"--result_dir",
type=str,
default=default.RESULT_DIR,
help="where to save experiment results",
)
###########################
# Dataset Config (few_shot_split.py)
###########################
parser.add_argument(
"--dataset",
type=str,
default="",
choices=dataset_classes.keys(),
help="number of train shot",
)
parser.add_argument(
"--train-shot",
type=int,
default=1,
help="number of train shot",
)
parser.add_argument(
"--max-val-shot",
type=int,
default=4,
help="number of val shot is min(max_val_shot, train_shot)",
)
parser.add_argument(
"--seed",
type=int,
default=1,
help="seed number",
)
###########################
# Feature Extraction Config (features.py)
###########################
parser.add_argument(
"--clip-encoder",
type=str,
default="RN50",
choices=["ViT-B/16", "ViT-B/32", "RN50", "RN101"],
help="specify the clip encoder to use",
)
parser.add_argument(
"--image-layer-idx",
type=int,
default=0,
choices=[0, 1, -1],
help="specify how many image encoder layers to finetune. 0 means none. -1 means full finetuning.",
)
parser.add_argument(
"--text-layer-idx",
type=int,
default=0,
choices=[0, 1, -1],
help="specify how many text encoder layers to finetune. 0 means none. -1 means full finetuning.",
)
parser.add_argument(
"--text-augmentation",
type=str,
default='hand_crafted',
choices=['hand_crafted', # tip_adapter selected
'classname', # plain class name
'vanilla', # a photo of a {cls}.
'template_mining' # examples of best zero-shot templates for few-shot val set
],
help="specify the text augmentation to use.",
)
parser.add_argument(
"--image-augmentation",
type=str,
default='none',
choices=['none', # only a single center crop
'flip', # add random flip view
'randomcrop', # add random crop view
],
help="specify the image augmentation to use.",
)
parser.add_argument(
"--image-views",
type=int,
default=1,
help="if image-augmentation is not None, then specify the number of extra views.",
)
parser.add_argument(
"--test-batch-size",
type=int,
default=32,
help="batch size for test (feature extraction and evaluation)",
)
parser.add_argument(
"--num-workers",
type=int,
default=0,
help="number of workers for dataloader",
)
###########################
# Training Config (train.py)
###########################
parser.add_argument(
"--modality",
type=str,
default="cross_modal",
choices=["cross_modal", # half batch image, half batch text
"uni_modal", # whole batch image
],
help="whether or not to perform cross-modal training (ie. half batch is image, half batch is text)",
)
parser.add_argument(
"--classifier_head",
type=str,
default="linear",
choices=["linear", # linear classifier
"adapter", # 2-layer MLP with 0.2 residual ratio following CLIP-adapter + linear classifier
],
help="classifier head architecture",
)
parser.add_argument(
"--classifier_init",
type=str,
default="zeroshot",
choices=["zeroshot", # zero-shot/one-shot-text-based initialization
"random", # random initialization
],
help="classifier head initialization",
)
parser.add_argument(
"--logit",
type=float,
default=4.60517, # CLIP's default logit scaling
choices=[4.60517, # CLIP's default logit scaling
4.0, # for partial finetuning
],
help="logit scale (exp(logit) is the inverse softmax temperature)",
)
parser.add_argument(
"--hyperparams",
type=str,
default="linear",
choices=["linear", # linear hyper
"adapter", # adapter hyper
"partial", # partial hyper
],
help="hyperparams sweep",
)