MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / get_name_convert_func

Function get_name_convert_func

slowfast/utils/c2_model_loading.py:9–120  ·  view source on GitHub ↗

Get the function to convert Caffe2 layer names to PyTorch layer names. Returns: (func): function to convert parameter name from Caffe2 format to PyTorch format.

()

Source from the content-addressed store, hash-verified

7
8
9def get_name_convert_func():
10 """
11 Get the function to convert Caffe2 layer names to PyTorch layer names.
12 Returns:
13 (func): function to convert parameter name from Caffe2 format to PyTorch
14 format.
15 """
16 pairs = [
17 # ------------------------------------------------------------
18 # 'nonlocal_conv3_1_theta_w' -> 's3.pathway0_nonlocal3.conv_g.weight'
19 [
20 r"^nonlocal_conv([0-9]+)_([0-9]+)_(.*)",
21 r"s\1.pathway0_nonlocal\2_\3",
22 ],
23 # 'theta' -> 'conv_theta'
24 [r"^(.*)_nonlocal([0-9]+)_(theta)(.*)", r"\1_nonlocal\2.conv_\3\4"],
25 # 'g' -> 'conv_g'
26 [r"^(.*)_nonlocal([0-9]+)_(g)(.*)", r"\1_nonlocal\2.conv_\3\4"],
27 # 'phi' -> 'conv_phi'
28 [r"^(.*)_nonlocal([0-9]+)_(phi)(.*)", r"\1_nonlocal\2.conv_\3\4"],
29 # 'out' -> 'conv_out'
30 [r"^(.*)_nonlocal([0-9]+)_(out)(.*)", r"\1_nonlocal\2.conv_\3\4"],
31 # 'nonlocal_conv4_5_bn_s' -> 's4.pathway0_nonlocal3.bn.weight'
32 [r"^(.*)_nonlocal([0-9]+)_(bn)_(.*)", r"\1_nonlocal\2.\3.\4"],
33 # ------------------------------------------------------------
34 # 't_pool1_subsample_bn' -> 's1_fuse.conv_f2s.bn.running_mean'
35 [r"^t_pool1_subsample_bn_(.*)", r"s1_fuse.bn.\1"],
36 # 't_pool1_subsample' -> 's1_fuse.conv_f2s'
37 [r"^t_pool1_subsample_(.*)", r"s1_fuse.conv_f2s.\1"],
38 # 't_res4_5_branch2c_bn_subsample_bn_rm' -> 's4_fuse.conv_f2s.bias'
39 [
40 r"^t_res([0-9]+)_([0-9]+)_branch2c_bn_subsample_bn_(.*)",
41 r"s\1_fuse.bn.\3",
42 ],
43 # 't_pool1_subsample' -> 's1_fuse.conv_f2s'
44 [
45 r"^t_res([0-9]+)_([0-9]+)_branch2c_bn_subsample_(.*)",
46 r"s\1_fuse.conv_f2s.\3",
47 ],
48 # ------------------------------------------------------------
49 # 'res4_4_branch_2c_bn_b' -> 's4.pathway0_res4.branch2.c_bn_b'
50 [
51 r"^res([0-9]+)_([0-9]+)_branch([0-9]+)([a-z])_(.*)",
52 r"s\1.pathway0_res\2.branch\3.\4_\5",
53 ],
54 # 'res_conv1_bn_' -> 's1.pathway0_stem.bn.'
55 [r"^res_conv1_bn_(.*)", r"s1.pathway0_stem.bn.\1"],
56 # 'conv1_xy_w_momentum' -> 's1.pathway0_stem.conv_xy.'
57 [r"^conv1_xy(.*)", r"s1.pathway0_stem.conv_xy\1"],
58 # 'conv1_w_momentum' -> 's1.pathway0_stem.conv.'
59 [r"^conv1_(.*)", r"s1.pathway0_stem.conv.\1"],
60 # 'res4_0_branch1_w' -> 'S4.pathway0_res0.branch1.weight'
61 [
62 r"^res([0-9]+)_([0-9]+)_branch([0-9]+)_(.*)",
63 r"s\1.pathway0_res\2.branch\3_\4",
64 ],
65 # 'res_conv1_' -> 's1.pathway0_stem.conv.'
66 [r"^res_conv1_(.*)", r"s1.pathway0_stem.conv.\1"],

Callers 4

load_checkpointFunction · 0.90
load_checkpointFunction · 0.90
load_checkpointFunction · 0.90
load_checkpointFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected