-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1031c34
commit 206913a
Showing
13 changed files
with
264 additions
and
37 deletions.
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
33 changes: 33 additions & 0 deletions
33
baselines/fedvssl/fedvssl/conf/mmcv_conf/finetuning/model_r3d18.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,33 @@ | ||
model = dict( | ||
type='TSN', | ||
backbone=dict( | ||
type='R3D', | ||
depth=18, | ||
num_stages=4, | ||
stem=dict( | ||
temporal_kernel_size=3, | ||
temporal_stride=1, | ||
in_channels=3, | ||
with_pool=False, | ||
), | ||
down_sampling=[False, True, True, True], | ||
channel_multiplier=1.0, | ||
bottleneck_multiplier=1.0, | ||
with_bn=True, | ||
zero_init_residual=False, | ||
pretrained=None, | ||
), | ||
st_module=dict( | ||
spatial_type='avg', | ||
temporal_size=2, # 16//8 | ||
spatial_size=7), | ||
cls_head=dict( | ||
with_avg_pool=False, | ||
temporal_feature_size=1, | ||
spatial_feature_size=1, | ||
dropout_ratio=0.5, | ||
in_channels=512, | ||
init_std=0.001, | ||
num_classes=101 | ||
) | ||
) |
10 changes: 10 additions & 0 deletions
10
baselines/fedvssl/fedvssl/conf/mmcv_conf/finetuning/r3d_18_ucf101/finetune_ucf101.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,10 @@ | ||
_base_ = ['../model_r3d18.py', | ||
'../runtime_ucf101.py'] | ||
|
||
work_dir = './finetune_ucf101/' | ||
|
||
model = dict( | ||
backbone=dict( | ||
pretrained='./model_pretrained.pth', | ||
), | ||
) |
10 changes: 10 additions & 0 deletions
10
baselines/fedvssl/fedvssl/conf/mmcv_conf/finetuning/r3d_18_ucf101/test_ucf101.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,10 @@ | ||
_base_ = ['../model_r3d18.py', | ||
'../runtime_ucf101.py'] | ||
|
||
work_dir = './finetune_ucf101/' | ||
|
||
model = dict( | ||
backbone=dict( | ||
pretrained='/finetune/ucf101/epoch_150.pth', | ||
), | ||
) |
133 changes: 133 additions & 0 deletions
133
baselines/fedvssl/fedvssl/conf/mmcv_conf/finetuning/runtime_ucf101.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,133 @@ | ||
dist_params = dict(backend='nccl') | ||
log_level = 'INFO' | ||
load_from = None | ||
resume_from = None | ||
syncbn = True | ||
|
||
train_cfg = None | ||
test_cfg = None | ||
evaluation = dict(interval=10) | ||
|
||
data = dict( | ||
videos_per_gpu=4, # total batch size 8*4 == 32 | ||
workers_per_gpu=4, | ||
train=dict( | ||
type='TSNDataset', | ||
name='ucf101_train_split1', | ||
data_source=dict( | ||
type='JsonClsDataSource', | ||
ann_file='ucf101/annotations/train_split_1.json', | ||
), | ||
backend=dict( | ||
type='ZipBackend', | ||
zip_fmt='ucf101/zips/{}.zip', | ||
frame_fmt='img_{:05d}.jpg', | ||
), | ||
frame_sampler=dict( | ||
type='RandomFrameSampler', | ||
num_clips=1, | ||
clip_len=16, | ||
strides=2, | ||
temporal_jitter=False | ||
), | ||
test_mode=False, | ||
transform_cfg=[ | ||
dict(type='GroupScale', scales=[(149, 112), (171, 128), (192, 144)]), | ||
dict(type='GroupFlip', flip_prob=0.35), | ||
dict(type='RandomBrightness', prob=0.20, delta=32), | ||
dict(type='RandomContrast', prob=0.20, delta=0.20), | ||
dict(type='RandomHueSaturation', prob=0.20, hue_delta=12, saturation_delta=0.1), | ||
dict(type='GroupRandomCrop', out_size=112), | ||
dict( | ||
type='GroupToTensor', | ||
switch_rgb_channels=True, | ||
div255=True, | ||
mean=(0.485, 0.456, 0.406), | ||
std=(0.229, 0.224, 0.225) | ||
) | ||
] | ||
), | ||
val=dict( | ||
type='TSNDataset', | ||
name='ucf101_test_split1', | ||
data_source=dict( | ||
type='JsonClsDataSource', | ||
ann_file='ucf101/annotations/test_split_1.json', | ||
), | ||
backend=dict( | ||
type='ZipBackend', | ||
zip_fmt='ucf101/zips/{}.zip', | ||
frame_fmt='img_{:05d}.jpg', | ||
), | ||
frame_sampler=dict( | ||
type='UniformFrameSampler', | ||
num_clips=10, | ||
clip_len=16, | ||
strides=2, | ||
temporal_jitter=False | ||
), | ||
test_mode=True, | ||
transform_cfg=[ | ||
dict(type='GroupScale', scales=[(171, 128)]), | ||
dict(type='GroupCenterCrop', out_size=112), | ||
dict( | ||
type='GroupToTensor', | ||
switch_rgb_channels=True, | ||
div255=True, | ||
mean=(0.485, 0.456, 0.406), | ||
std=(0.229, 0.224, 0.225) | ||
) | ||
] | ||
), | ||
test=dict( | ||
type='TSNDataset', | ||
name='ucf101_test_split1', | ||
data_source=dict( | ||
type='JsonClsDataSource', | ||
ann_file='ucf101/annotations/test_split_1.json', | ||
), | ||
backend=dict( | ||
type='ZipBackend', | ||
zip_fmt='ucf101/zips/{}.zip', | ||
frame_fmt='img_{:05d}.jpg', | ||
), | ||
frame_sampler=dict( | ||
type='UniformFrameSampler', | ||
num_clips=10, | ||
clip_len=16, | ||
strides=2, | ||
temporal_jitter=False | ||
), | ||
test_mode=True, | ||
transform_cfg=[ | ||
dict(type='GroupScale', scales=[(171, 128)]), | ||
dict(type='GroupCenterCrop', out_size=112), | ||
dict( | ||
type='GroupToTensor', | ||
switch_rgb_channels=True, | ||
div255=True, | ||
mean=(0.485, 0.456, 0.406), | ||
std=(0.229, 0.224, 0.225) | ||
) | ||
] | ||
), | ||
) | ||
|
||
# optimizer | ||
total_epochs = 150 | ||
optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=5e-4) | ||
optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) | ||
# learning policy | ||
lr_config = dict( | ||
policy='step', | ||
step=[60, 120] | ||
) | ||
checkpoint_config = dict(interval=1, max_keep_ckpts=1, create_symlink=False) | ||
workflow = [('train', 50)] | ||
log_config = dict( | ||
interval=10, | ||
hooks=[ | ||
dict(type='TextLoggerHook'), | ||
dict(type='TensorboardLoggerHook'), | ||
] | ||
) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions
3
...conf/r3d_18_ucf101/pretraining_for_ucf.py → ...ning/r3d_18_ucf101/pretraining_for_ucf.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
14 changes: 0 additions & 14 deletions
14
baselines/fedvssl/fedvssl/conf/mmcv_conf/r3d_18_kinetics/finetune_ucf101_for_kinetics.py
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
baselines/fedvssl/fedvssl/conf/mmcv_conf/r3d_18_ucf101/finetune_ucf101_for_ucf.py
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
import argparse | ||
from collections import OrderedDict | ||
import numpy as np | ||
import torch | ||
from mmengine.config import Config | ||
from flwr.common import parameters_to_ndarrays | ||
from .CtP.pyvrl.builder import build_model | ||
|
||
|
||
def args_parser(): | ||
"""Parse arguments to pre-process pre-trained SSL model for fine-tuning.""" | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument( | ||
"--cfg_path", | ||
default="fedvssl/conf/mmcv_conf/finetuning/r3d_18_ucf101/finetune_ucf101.py", | ||
type=str, | ||
help="Path of config file for fine-tuning.", | ||
) | ||
parser.add_argument( | ||
"--pretrained_model_path", | ||
default="", | ||
type=str, | ||
help="Path of pre-trained SSL model.", | ||
) | ||
|
||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
args = args_parser() | ||
|
||
# Load config file | ||
cfg = Config.fromfile(args.cfg_path) | ||
cfg.model.backbone["pretrained"] = None | ||
|
||
# Build a model using the config file | ||
model = build_model(cfg.model) | ||
|
||
# Conversion of the format of pre-trained SSL model from .npz files to .pth format. | ||
params = np.load(args.pretrained_model_path, allow_pickle=True) | ||
params = params["arr_0"].item() | ||
params = parameters_to_ndarrays(params) | ||
params_dict = zip(model.state_dict().keys(), params) | ||
state_dict = { | ||
"state_dict": OrderedDict( | ||
{k: torch.from_numpy(v) for k, v in params_dict} | ||
) | ||
} | ||
torch.save(state_dict, "./model_pretrained.pth") |