Safemotion Lib
Loading...
Searching...
No Matches
smaction
models
heads
i3d_head.py
Go to the documentation of this file.
1
import
torch
2
import
torch.nn
as
nn
3
4
class
I3DHead
(nn.Module):
5
"""
6
3차원 텐서를 입력으로 클래스 스코어를 출력하는 기능의 모듈
7
입력 텐서를 풀링하여 1차월의 텐서로 변환하고 fc 연산을 적용해서 클래스 스코어를 출력함
8
args:
9
in_channels (int) : 입력 텐서의 채널 수
10
num_classes (int) : 클래스 수, 출력 텐서의 채널 수
11
dropout_ratio (float) : 드랍아웃 비율을 설정하는 파라미터
12
input_key (str) : inference에 사용하는 입력데이터의 키값
13
"""
14
def
__init__
(self, in_channels, num_classes, dropout_ratio, input_key):
15
super().
__init__
()
16
17
self.
dropout_ratio
= dropout_ratio
18
self.
input_key
= input_key
19
20
self.
fc_cls
= nn.Linear(in_channels, num_classes)
21
self.
avg_pool
= nn.AdaptiveAvgPool3d((1, 1, 1))
22
23
if
self.
dropout_ratio
!= 0:
24
self.
dropout
= nn.Dropout(p=self.
dropout_ratio
)
25
else
:
26
self.
dropout
=
None
27
28
29
def
forward
(self, feat_dict):
30
"""
31
args:
32
sample (dict)) : 입력 데이터, self.input_key에 해당하는 키가 있어야함
33
self.input_key의 아이템은 Tensor 타입 -> shape (B, in_channels, T, H, W)
34
B : 배치 크기
35
T : 시간
36
37
return (Tensor):
38
1차원 특징 벡터 -> shape (B, num_classes)
39
"""
40
x = feat_dict[self.
input_key
]
41
x = self.
avg_pool
(x)
42
43
if
self.
dropout
is
not
None
:
44
x = self.
dropout
(x)
45
46
x = x.view(x.shape[0], -1)
47
cls_score = self.
fc_cls
(x)
48
49
return
cls_score
50
i3d_head.I3DHead
Definition
i3d_head.py:4
i3d_head.I3DHead.input_key
input_key
Definition
i3d_head.py:18
i3d_head.I3DHead.fc_cls
fc_cls
Definition
i3d_head.py:20
i3d_head.I3DHead.dropout_ratio
dropout_ratio
Definition
i3d_head.py:17
i3d_head.I3DHead.avg_pool
avg_pool
Definition
i3d_head.py:21
i3d_head.I3DHead.dropout
dropout
Definition
i3d_head.py:24
i3d_head.I3DHead.forward
forward(self, feat_dict)
Definition
i3d_head.py:29
i3d_head.I3DHead.__init__
__init__(self, in_channels, num_classes, dropout_ratio, input_key)
Definition
i3d_head.py:14
torch.nn
Generated by
1.10.0