forked from open-mmlab/mmaction2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransrank_ucf_r3d_rotate_mlp_200e.py
126 lines (118 loc) · 4.05 KB
/
transrank_ucf_r3d_rotate_mlp_200e.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
# model settings
trans = ['1x', '2x', 'rev']
org_len = 48
tgt_len = 16
loss_cfg = dict(type='MultiMRLoss', num_trans=len(trans), replicas=len(trans), strategy='pair', margin=2.)
img_norm_cfg = dict(
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False)
t_trans_pipeline = [
dict(type='ColorJitter', brightness=(0.5,1.5), contrast=(0.5,1.5), saturation=(0.5,1.5), hue=(-0.1,0.1)),
dict(type='Normalize', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375])
]
sample_cfg = [
dict(type='normal', clip_len=16, frame_interval=2),
dict(type='normal', clip_len=16, frame_interval=4),
dict(type='rev', clip_len=16, frame_interval=2),
]
aux_loss_cfg = dict(type='CrossEntropyLoss', loss_weight=0.5)
model = dict(
type='TransReg',
backbone=dict(type='r3d_18'),
aux_cfg=dict(rotate=dict(num_classes=4, loss_cls=aux_loss_cfg)),
t_trans=dict(
type='T_Trans',
tgt_len=tgt_len,
trans=trans,
pipeline=t_trans_pipeline,
skip=True,
t_aug=False),
cls_head=dict(
type='I3DHead',
num_classes=len(trans),
in_channels=512,
spatial_type='avg',
mlp=[128],
mlp_bn=True,
dropout_ratio=0.,
loss_cls=loss_cfg,
init_std=0.01))
# dataset settings
dataset_type = 'VideoDataset'
# data_root is the folder that contains ucf101 videos
data_root = '/home/dhd/data/ucf101'
# ann_file is a list of training / testing samples, in the format of:
# path/to/video1.mp4 label_index
# path/to/video2.mp4 label_index
# ...
ann_file_train = f'data/ucf101/ucf101_train_1.txt'
ann_file_val = f'data/ucf101/ucf101_test_1.txt'
train_pipeline = [
dict(type='DecordInit'),
dict(type='CustomSampleFrames', sample_cfg=sample_cfg, with_taug=(0.8, 1.2)),
dict(type='DecordDecode'),
dict(type='RandomResizedCrop', clip_wise=True),
dict(type='Resize', scale=(112, 112), keep_ratio=False),
dict(type='Flip', flip_ratio=0.5),
dict(type='RandomRotate', clip_wise=False),
dict(type='FormatShape', input_format='NCTHW'),
dict(type='ToTensor', keys=['imgs', 'label', 'rotate_label']),
dict(type='Collect', keys=['imgs', 'label'], meta_keys=['rotate_label']),
]
val_pipeline = [
dict(type='DecordInit'),
dict(type='CustomSampleFrames', sample_cfg=sample_cfg, with_taug=(0.8, 1.2), test_mode=True),
dict(type='DecordDecode'),
dict(type='Resize', scale=(-1, 112)),
dict(type='CenterCrop', crop_size=112),
dict(type='RandomRotate', clip_wise=False),
dict(type='Normalize', **img_norm_cfg),
dict(type='FormatShape', input_format='NCTHW'),
dict(type='ToTensor', keys=['imgs', 'label', 'rotate_label']),
dict(type='Collect', keys=['imgs', 'label'], meta_keys=['rotate_label']),
]
test_pipeline = val_pipeline
data = dict(
videos_per_gpu=8,
workers_per_gpu=2,
val_dataloader=dict(videos_per_gpu=1),
test_dataloader=dict(videos_per_gpu=1),
train=dict(
type='RepeatDataset',
times=10,
dataset=dict(
type=dataset_type,
ann_file=ann_file_train,
data_prefix=data_root,
pipeline=train_pipeline)),
val=dict(
type='EvalTTrans',
num_trans=len(trans),
dataset=dict(
type=dataset_type,
ann_file=ann_file_val,
data_prefix=data_root,
pipeline=val_pipeline)))
data['test'] = data['val']
# optimizer
optimizer = dict(
type='SGD', lr=0.1, momentum=0.9,
weight_decay=0.0001) # this lr is used for 8 gpus
optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2))
# learning policy
lr_config = dict(policy='CosineAnnealing', min_lr=0, by_epoch=False)
total_epochs = 20
checkpoint_config = dict(interval=1)
evaluation = dict(
interval=1, metrics=['top_k_accuracy'], save_eval=True)
log_config = dict(
interval=20,
hooks=[
dict(type='TextLoggerHook'),
])
# runtime settings
dist_params = dict(backend='nccl')
log_level = 'INFO'
work_dir = f'./work_dirs/transrank_ucf_r3d_rotate_mlp_20e'
load_from = None
resume_from = None
workflow = [('train', 1)]