-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-shot_chest.py
More file actions
89 lines (78 loc) · 2.38 KB
/
1-shot_chest.py
File metadata and controls
89 lines (78 loc) · 2.38 KB
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
_base_ = [
'../datasets/chest.py',
'../schedules/chest.py',
'mmpretrain::_base_/default_runtime.py',
'../custom_imports.py',
]
lr = 5e-3
vpl = 1
dataset = 'chest'
exp_num = 2
nshot = 1
run_name = f'dinov2-b_{vpl}_bs4_lr{lr}_{nshot}-shot_{dataset}_exp{exp_num}'
work_dir = f'work_dirs/chest/{nshot}-shot/{run_name}'
model = dict(
type='ImageClassifier',
backbone=dict(
type='PromptedViT',
prompt_length=vpl,
layer_scale_init_value=1e-5,
out_type='avg_all',
img_size=518,
patch_size=14,
arch='base',
init_cfg=dict(
type='Pretrained',
checkpoint=
'https://download.openmmlab.com/mmpretrain/v1.0/dinov2/vit-base-p14_dinov2-pre_3rdparty_20230426-ba246503.pth',
prefix='backbone'),
),
neck=None,
head=dict(
type='MultiLabelLinearClsHead',
num_classes=19,
in_channels=768,
))
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='NumpyToPIL', to_rgb=True),
dict(type='torchvision/RandomAffine', degrees=(-15, 15), translate=(0.05, 0.05), fill=128),
dict(type='PILToNumpy', to_bgr=True),
dict(
type='RandomResizedCrop',
scale=518,
crop_ratio_range=(0.9, 1.0),
backend='pillow',
interpolation='bicubic'),
dict(type='RandomFlip', prob=0.5, direction='horizontal'),
dict(type='PackInputs'),
]
test_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='Resize', scale=518, backend='pillow', interpolation='bicubic'),
dict(type='PackInputs'),
]
train_dataloader = dict(
batch_size=1,
dataset=dict(
ann_file=f'data_anns/MedFMC/{dataset}/{dataset}_{nshot}-shot_train_exp{exp_num}.txt',
pipeline=train_pipeline),
)
val_dataloader = dict(
batch_size=2,
dataset=dict(
ann_file=f'data_anns/MedFMC/{dataset}/{dataset}_{nshot}-shot_val_exp{exp_num}.txt',
pipeline=test_pipeline),
)
test_dataloader = dict(
batch_size=2,
dataset=dict(
ann_file=f'data_anns/MedFMC/{dataset}/test_WithLabel.txt',
pipeline=test_pipeline),
)
optim_wrapper = dict(optimizer=dict(lr=lr))
default_hooks = dict(
checkpoint=dict(type='CheckpointHook', interval=1, max_keep_ckpts=1, save_best="auto"),
logger=dict(interval=50),
)
visualizer = dict(type='Visualizer', vis_backends=[dict(type='TensorboardVisBackend')])