-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-head.py
58 lines (35 loc) · 1.5 KB
/
add-head.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
#%%
from torch import nn
from torch.fx import symbolic_trace
altered_backbone = torch.load("altered-backbone-ep200.pt")
altered_backbone
# %% Build head
conv_5 = nn.Conv3d(192, 432, kernel_size=(1, 1, 1), stride=(1, 1, 1), bias=False)
conv_5_bn = nn.BatchNorm3d(432, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
conv_5_relu = nn.ReLU(inplace=True)
avg_pool = nn.AvgPool3d(kernel_size=[4, 5, 5], stride=1, padding=0)
lin_5 = nn.Conv3d(432, 2048, kernel_size=(1, 1, 1), stride=(1, 1, 1), bias=False)
lin_5_relu = nn.ReLU(inplace=True)
projection = nn.Linear(in_features=2048, out_features=128, bias=True)
# %%
from collections import OrderedDict
x3d_head = nn.Sequential(OrderedDict([
('conv_5', nn.Conv3d(192, 432, kernel_size=(1, 1, 1), stride=(1, 1, 1), bias=False)),
('conv_5_bn', nn.BatchNorm3d(432, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)),
('conv_5_relu', nn.ReLU(inplace=True)),
('avg_pool', nn.AvgPool3d(kernel_size=[4, 5, 5], stride=1, padding=0)),
('lin_5', nn.Conv3d(432, 2048, kernel_size=(1, 1, 1), stride=(1, 1, 1), bias=False)),
('lin_5_relu', nn.ReLU(inplace=True)),
('projection', nn.Linear(in_features=2048, out_features=128, bias=True)),
])
)
x3d_head
# %%
model_hub = torch.hub.load('facebookresearch/pytorchvideo', 'x3d_xs', pretrained=False)
model_hub
# %%
x3d_head_hub = model_hub.blocks[5]
# %%
input_head = torch.zeros(192, 4, 6, 6)
x3d_head_hub(input_head[None, ...]).shape
# %%