-
Notifications
You must be signed in to change notification settings - Fork 206
/
dino_deit_small_p16_8xb32_100e_jpg.py
196 lines (178 loc) · 5.11 KB
/
dino_deit_small_p16_8xb32_100e_jpg.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
_base_ = 'configs/base.py'
total_epochs = 100
# model settings
model_output_dim = 65536
model = dict(
type='DINO',
pretrained=False,
train_preprocess=[
'randomGrayScale', 'gaussianBlur', 'solarize'
], # 2+6 view, has different augment pipeline, dino is complex
backbone=dict(
type='PytorchImageModelWrapper',
# model_name='pit_xs_distilled_224',
# swin(dynamic)
# model_name = 'dynamic_swin_tiny_p4_w7_224',
# model_name = 'dynamic_swin_small_p4_w7_224',
# model_name = 'dynamic_swin_base_p4_w7_224',
# deit(224)
model_name='dynamic_deit_small_p16',
# xcit(224)
# model_name='xcit_small_12_p16',
# model_name='xcit_medium_24_p16',
# model_name='xcit_large_24_p8',
# resnet
# model_name = 'resnet50',
# model_name = 'resnet18',
# model_name = 'resnet34',
# model_name = 'resnet101',
),
# swav need mulit crop ,doesn't support vit based model
neck=dict(type='DINONeck', in_dim=384, out_dim=model_output_dim),
config=dict(
# dino head setting
# momentum_teacher = 0.9995, #0.9995 for batchsize=256
use_bn_in_head=False,
norm_last_layer=True,
drop_path_rate=0.1,
use_tfrecord_input=False,
# dino loss settding
out_dim=model_output_dim,
local_crops_number=8,
warmup_teacher_temp=0.04, # temperature for sharp softmax
teacher_temp=0.04,
warmup_teacher_temp_epochs=0,
epochs=total_epochs,
))
data_train_list = 'imagenet_raw/meta/train.txt'
data_train_root = 'imagenet_raw/'
img_norm_cfg = dict(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
train_pipeline1 = [
dict(
type='RandomResizedCrop',
size=224,
scale=(0.4, 1.),
interpolation=3, # Image.BICUBIC
),
dict(type='RandomHorizontalFlip', p=0.5),
dict(
type='RandomAppliedTrans',
transforms=[
dict(
type='ColorJitter',
brightness=0.4,
contrast=0.4,
saturation=0.2,
hue=0.1)
],
p=0.8),
dict(type='RandomGrayscale', p=0.2),
dict(
type='RandomAppliedTrans',
transforms=[dict(type='GaussianBlur', kernel_size=23)],
p=1.0),
dict(type='ToTensor'),
dict(type='Normalize', **img_norm_cfg),
dict(type='Collect', keys=['img'])
]
train_pipeline2 = [
dict(
type='RandomResizedCrop',
size=224,
scale=(0.4, 1.),
interpolation=3, # Image.BICUBIC
),
dict(type='RandomHorizontalFlip', p=0.5),
dict(
type='RandomAppliedTrans',
transforms=[
dict(
type='ColorJitter',
brightness=0.4,
contrast=0.4,
saturation=0.2,
hue=0.1)
],
p=0.8),
dict(type='RandomGrayscale', p=0.2),
dict(
type='RandomAppliedTrans',
transforms=[dict(type='GaussianBlur', kernel_size=23)],
p=0.1),
dict(
type='RandomAppliedTrans',
transforms=[dict(type='Solarization', threshold=130)],
p=0.2),
dict(type='ToTensor'),
dict(type='Normalize', **img_norm_cfg),
dict(type='Collect', keys=['img'])
]
train_pipeline3 = [
dict(
type='RandomResizedCrop',
size=96,
scale=(0.05, 0.4),
interpolation=3, # Image.BICUBIC
),
dict(type='RandomHorizontalFlip', p=0.5),
dict(
type='RandomAppliedTrans',
transforms=[
dict(
type='ColorJitter',
brightness=0.4,
contrast=0.4,
saturation=0.2,
hue=0.1)
],
p=0.8),
dict(type='RandomGrayscale', p=0.2),
dict(
type='RandomAppliedTrans',
transforms=[dict(type='GaussianBlur', kernel_size=23)],
p=0.5),
dict(type='ToTensor'),
dict(type='Normalize', **img_norm_cfg),
dict(type='Collect', keys=['img'])
]
data = dict(
imgs_per_gpu=32, # total 32*8=256
workers_per_gpu=8,
drop_last=True,
train=dict(
type='MultiViewDataset',
data_source=dict(
type='SSLSourceImageList',
list_file=data_train_list,
root=data_train_root),
num_views=[1, 1, 8],
pipelines=[train_pipeline1, train_pipeline2, train_pipeline3]))
custom_hooks = [
dict(
type='DINOHook',
momentum_teacher=0.996, # 0.9995 for bs=256
weight_decay=0.04,
weight_decay_end=0.4,
)
]
# optimizer
optimizer = dict(type='AdamW', lr=9.375e-4)
optimizer_config = dict(
grad_clip=dict(max_norm=3),
ignore_key=['last_layer'],
ignore_key_epoch=[1], # in dino, freeze_last_layer in first 1 epoch
# update_interval=2
)
# learning policy
lr_config = dict(
policy='CosineAnnealing',
min_lr=1e-6,
warmup='linear',
warmup_iters=10,
warmup_ratio=0.001,
warmup_by_epoch=True)
checkpoint_config = dict(interval=10)
load_from = None
# export config drop dino neck
export = dict(export_neck=False)
# checkpoint_sync_export=True