New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Support Mixup and Cutmix for Recognizers. #681
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
55be548
add todo list
irvingzhang0512 bd0fd7e
codes of mixup/cutmix/register/recognizers
irvingzhang0512 a71aa6e
add unittest
irvingzhang0512 cab1eda
add demo config
irvingzhang0512 5952d58
fix unittest
irvingzhang0512 54f651e
remove toto list
irvingzhang0512 1b5bdf9
update changelog
irvingzhang0512 ff68dd9
Merge branch 'master' into mixup
irvingzhang0512 7a38fea
fix unittest and training bug
irvingzhang0512 bf13717
fix
irvingzhang0512 86c06b4
fix unittest
irvingzhang0512 0618906
add todo
irvingzhang0512 3a7bacf
remove useless codes
irvingzhang0512 1b2cac9
update comments
irvingzhang0512 eea8ee4
update docs
irvingzhang0512 cd3e437
fix
irvingzhang0512 1f887ca
fix a bug
irvingzhang0512 f31eaf5
update configs
irvingzhang0512 8e3e48c
update sthv1 training results
irvingzhang0512 0c8af1f
Merge branch 'master' into mixup
irvingzhang0512 95ce916
add tsn config and modify default alpha value
irvingzhang0512 0735ef7
fix lint
irvingzhang0512 60a6b15
add unittest
irvingzhang0512 5bf768b
fix tin sthv2 config
irvingzhang0512 e79c5da
update links
kennymckormick 60915ea
remove useless docs
irvingzhang0512 749de3e
Merge branch 'master' into mixup
irvingzhang0512 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
configs/recognition/tsm/tsm_r50_cutmix_1x1x8_50e_sthv1_rgb.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
_base_ = [ | ||
'../../_base_/schedules/sgd_tsm_50e.py', '../../_base_/default_runtime.py' | ||
] | ||
|
||
# model settings | ||
# model settings# model settings | ||
model = dict( | ||
type='Recognizer2D', | ||
backbone=dict( | ||
type='ResNetTSM', | ||
pretrained='torchvision://resnet50', | ||
depth=50, | ||
norm_eval=False, | ||
shift_div=8), | ||
cls_head=dict( | ||
type='TSMHead', | ||
num_classes=174, | ||
in_channels=2048, | ||
spatial_type='avg', | ||
consensus=dict(type='AvgConsensus', dim=1), | ||
dropout_ratio=0.5, | ||
init_std=0.001, | ||
is_shift=True), | ||
# model training and testing settings | ||
train_cfg=dict( | ||
blending=dict(type='CutmixBlending', num_classes=174, alpha=.2)), | ||
test_cfg=dict(average_clips='prob')) | ||
|
||
# dataset settings | ||
dataset_type = 'RawframeDataset' | ||
data_root = 'data/sthv1/rawframes' | ||
data_root_val = 'data/sthv1/rawframes' | ||
ann_file_train = 'data/sthv1/sthv1_train_list_rawframes.txt' | ||
ann_file_val = 'data/sthv1/sthv1_val_list_rawframes.txt' | ||
ann_file_test = 'data/sthv1/sthv1_val_list_rawframes.txt' | ||
img_norm_cfg = dict( | ||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) | ||
train_pipeline = [ | ||
dict(type='SampleFrames', clip_len=1, frame_interval=1, num_clips=8), | ||
dict(type='RawFrameDecode'), | ||
dict(type='Resize', scale=(-1, 256)), | ||
dict( | ||
type='MultiScaleCrop', | ||
input_size=224, | ||
scales=(1, 0.875, 0.75, 0.66), | ||
random_crop=False, | ||
max_wh_scale_gap=1, | ||
num_fixed_crops=13), | ||
dict(type='Resize', scale=(224, 224), keep_ratio=False), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='FormatShape', input_format='NCHW'), | ||
dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), | ||
dict(type='ToTensor', keys=['imgs', 'label']) | ||
] | ||
val_pipeline = [ | ||
dict( | ||
type='SampleFrames', | ||
clip_len=1, | ||
frame_interval=1, | ||
num_clips=8, | ||
test_mode=True), | ||
dict(type='RawFrameDecode'), | ||
dict(type='Resize', scale=(-1, 256)), | ||
dict(type='CenterCrop', crop_size=224), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='FormatShape', input_format='NCHW'), | ||
dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), | ||
dict(type='ToTensor', keys=['imgs']) | ||
] | ||
test_pipeline = [ | ||
dict( | ||
type='SampleFrames', | ||
clip_len=1, | ||
frame_interval=1, | ||
num_clips=8, | ||
twice_sample=True, | ||
test_mode=True), | ||
dict(type='RawFrameDecode'), | ||
dict(type='Resize', scale=(-1, 256)), | ||
dict(type='ThreeCrop', crop_size=256), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='FormatShape', input_format='NCHW'), | ||
dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), | ||
dict(type='ToTensor', keys=['imgs']) | ||
] | ||
data = dict( | ||
videos_per_gpu=8, | ||
workers_per_gpu=4, | ||
train=dict( | ||
type=dataset_type, | ||
ann_file=ann_file_train, | ||
data_prefix=data_root, | ||
filename_tmpl='{:05}.jpg', | ||
pipeline=train_pipeline), | ||
val=dict( | ||
type=dataset_type, | ||
ann_file=ann_file_val, | ||
data_prefix=data_root_val, | ||
filename_tmpl='{:05}.jpg', | ||
pipeline=val_pipeline), | ||
test=dict( | ||
type=dataset_type, | ||
ann_file=ann_file_test, | ||
data_prefix=data_root_val, | ||
filename_tmpl='{:05}.jpg', | ||
pipeline=test_pipeline)) | ||
evaluation = dict( | ||
interval=2, metrics=['top_k_accuracy', 'mean_class_accuracy']) | ||
|
||
# optimizer | ||
optimizer = dict(weight_decay=0.0005) | ||
|
||
# runtime settings | ||
work_dir = './work_dirs/tsm_r50_cutmix_1x1x8_50e_sthv1_rgb/' |
114 changes: 114 additions & 0 deletions
114
configs/recognition/tsm/tsm_r50_mixup_1x1x8_50e_sthv1_rgb.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
_base_ = [ | ||
'../../_base_/schedules/sgd_tsm_50e.py', '../../_base_/default_runtime.py' | ||
] | ||
|
||
# model settings | ||
# model settings# model settings | ||
model = dict( | ||
type='Recognizer2D', | ||
backbone=dict( | ||
type='ResNetTSM', | ||
pretrained='torchvision://resnet50', | ||
depth=50, | ||
norm_eval=False, | ||
shift_div=8), | ||
cls_head=dict( | ||
type='TSMHead', | ||
num_classes=174, | ||
in_channels=2048, | ||
spatial_type='avg', | ||
consensus=dict(type='AvgConsensus', dim=1), | ||
dropout_ratio=0.5, | ||
init_std=0.001, | ||
is_shift=True), | ||
# model training and testing settings | ||
train_cfg=dict( | ||
blending=dict(type='MixupBlending', num_classes=174, alpha=.2)), | ||
test_cfg=dict(average_clips='prob')) | ||
|
||
# dataset settings | ||
dataset_type = 'RawframeDataset' | ||
data_root = 'data/sthv1/rawframes' | ||
data_root_val = 'data/sthv1/rawframes' | ||
ann_file_train = 'data/sthv1/sthv1_train_list_rawframes.txt' | ||
ann_file_val = 'data/sthv1/sthv1_val_list_rawframes.txt' | ||
ann_file_test = 'data/sthv1/sthv1_val_list_rawframes.txt' | ||
img_norm_cfg = dict( | ||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) | ||
train_pipeline = [ | ||
dict(type='SampleFrames', clip_len=1, frame_interval=1, num_clips=8), | ||
dict(type='RawFrameDecode'), | ||
dict(type='Resize', scale=(-1, 256)), | ||
dict( | ||
type='MultiScaleCrop', | ||
input_size=224, | ||
scales=(1, 0.875, 0.75, 0.66), | ||
random_crop=False, | ||
max_wh_scale_gap=1, | ||
num_fixed_crops=13), | ||
dict(type='Resize', scale=(224, 224), keep_ratio=False), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='FormatShape', input_format='NCHW'), | ||
dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), | ||
dict(type='ToTensor', keys=['imgs', 'label']) | ||
] | ||
val_pipeline = [ | ||
dict( | ||
type='SampleFrames', | ||
clip_len=1, | ||
frame_interval=1, | ||
num_clips=8, | ||
test_mode=True), | ||
dict(type='RawFrameDecode'), | ||
dict(type='Resize', scale=(-1, 256)), | ||
dict(type='CenterCrop', crop_size=224), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='FormatShape', input_format='NCHW'), | ||
dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), | ||
dict(type='ToTensor', keys=['imgs']) | ||
] | ||
test_pipeline = [ | ||
dict( | ||
type='SampleFrames', | ||
clip_len=1, | ||
frame_interval=1, | ||
num_clips=8, | ||
twice_sample=True, | ||
test_mode=True), | ||
dict(type='RawFrameDecode'), | ||
dict(type='Resize', scale=(-1, 256)), | ||
dict(type='ThreeCrop', crop_size=256), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='FormatShape', input_format='NCHW'), | ||
dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), | ||
dict(type='ToTensor', keys=['imgs']) | ||
] | ||
data = dict( | ||
videos_per_gpu=8, | ||
workers_per_gpu=4, | ||
train=dict( | ||
type=dataset_type, | ||
ann_file=ann_file_train, | ||
data_prefix=data_root, | ||
filename_tmpl='{:05}.jpg', | ||
pipeline=train_pipeline), | ||
val=dict( | ||
type=dataset_type, | ||
ann_file=ann_file_val, | ||
data_prefix=data_root_val, | ||
filename_tmpl='{:05}.jpg', | ||
pipeline=val_pipeline), | ||
test=dict( | ||
type=dataset_type, | ||
ann_file=ann_file_test, | ||
data_prefix=data_root_val, | ||
filename_tmpl='{:05}.jpg', | ||
pipeline=test_pipeline)) | ||
evaluation = dict( | ||
interval=2, metrics=['top_k_accuracy', 'mean_class_accuracy']) | ||
|
||
# optimizer | ||
optimizer = dict(weight_decay=0.0005) | ||
|
||
# runtime settings | ||
work_dir = './work_dirs/tsm_r50_mixup_1x1x8_50e_sthv1_rgb/' |
110 changes: 110 additions & 0 deletions
110
configs/recognition/tsn/tsn_r50_video_mixup_1x1x8_100e_kinetics400_rgb.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
_base_ = [ | ||
'../../_base_/schedules/sgd_100e.py', '../../_base_/default_runtime.py' | ||
] | ||
|
||
# model settings | ||
model = dict( | ||
type='Recognizer2D', | ||
backbone=dict( | ||
type='ResNet', | ||
pretrained='torchvision://resnet50', | ||
depth=50, | ||
norm_eval=False), | ||
cls_head=dict( | ||
type='TSNHead', | ||
num_classes=400, | ||
in_channels=2048, | ||
spatial_type='avg', | ||
consensus=dict(type='AvgConsensus', dim=1), | ||
dropout_ratio=0.4, | ||
init_std=0.01), | ||
# model training and testing settings | ||
# train_cfg=dict( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
# blending=dict(type="CutmixBlending", num_classes=400, alpha=.2)), | ||
train_cfg=dict( | ||
blending=dict(type='MixupBlending', num_classes=400, alpha=.2)), | ||
test_cfg=dict(average_clips=None)) | ||
|
||
# dataset settings | ||
dataset_type = 'VideoDataset' | ||
data_root = 'data/kinetics400/videos_train' | ||
data_root_val = 'data/kinetics400/videos_val' | ||
ann_file_train = 'data/kinetics400/kinetics400_train_list_videos.txt' | ||
ann_file_val = 'data/kinetics400/kinetics400_val_list_videos.txt' | ||
ann_file_test = 'data/kinetics400/kinetics400_val_list_videos.txt' | ||
img_norm_cfg = dict( | ||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) | ||
train_pipeline = [ | ||
dict(type='DecordInit'), | ||
dict(type='SampleFrames', clip_len=1, frame_interval=1, num_clips=8), | ||
dict(type='DecordDecode'), | ||
dict( | ||
type='MultiScaleCrop', | ||
input_size=224, | ||
scales=(1, 0.875, 0.75, 0.66), | ||
random_crop=False, | ||
max_wh_scale_gap=1), | ||
dict(type='Resize', scale=(224, 224), keep_ratio=False), | ||
dict(type='Flip', flip_ratio=0.5), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='FormatShape', input_format='NCHW'), | ||
dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), | ||
dict(type='ToTensor', keys=['imgs', 'label']) | ||
] | ||
val_pipeline = [ | ||
dict(type='DecordInit'), | ||
dict( | ||
type='SampleFrames', | ||
clip_len=1, | ||
frame_interval=1, | ||
num_clips=8, | ||
test_mode=True), | ||
dict(type='DecordDecode'), | ||
dict(type='Resize', scale=(-1, 256)), | ||
dict(type='CenterCrop', crop_size=224), | ||
dict(type='Flip', flip_ratio=0), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='FormatShape', input_format='NCHW'), | ||
dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), | ||
dict(type='ToTensor', keys=['imgs']) | ||
] | ||
test_pipeline = [ | ||
dict(type='DecordInit'), | ||
dict( | ||
type='SampleFrames', | ||
clip_len=1, | ||
frame_interval=1, | ||
num_clips=25, | ||
test_mode=True), | ||
dict(type='DecordDecode'), | ||
dict(type='Resize', scale=(-1, 256)), | ||
dict(type='ThreeCrop', crop_size=256), | ||
dict(type='Flip', flip_ratio=0), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='FormatShape', input_format='NCHW'), | ||
dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), | ||
dict(type='ToTensor', keys=['imgs']) | ||
] | ||
data = dict( | ||
videos_per_gpu=32, | ||
workers_per_gpu=4, | ||
train=dict( | ||
type=dataset_type, | ||
ann_file=ann_file_train, | ||
data_prefix=data_root, | ||
pipeline=train_pipeline), | ||
val=dict( | ||
type=dataset_type, | ||
ann_file=ann_file_val, | ||
data_prefix=data_root_val, | ||
pipeline=val_pipeline), | ||
test=dict( | ||
type=dataset_type, | ||
ann_file=ann_file_test, | ||
data_prefix=data_root_val, | ||
pipeline=test_pipeline)) | ||
evaluation = dict( | ||
interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) | ||
|
||
# runtime settings | ||
work_dir = './work_dirs/tsn_r50_video_mixup_1x1x8_100e_kinetics400_rgb/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate