Safemotion Lib
Loading...
Searching...
No Matches
smaction
runner
mmaction_pytorch_runner.py
Go to the documentation of this file.
1
from
mmengine.dataset
import
pseudo_collate
2
from
.mmaction_base_runner
import
MMActionBaseRunner
3
4
from
smaction.utils.transforms
import
*
5
import
smaction.utils.action_utils
as
utils
6
import
torch
7
8
#skeleton, image, fusion 버전으로 분리 필요
9
class
MMActionPyTorchRunner
(
MMActionBaseRunner
):
10
def
__init__
(self, model_cfg, model_checkpoint, device='cuda', input_type='PoseC3D', k=60, img_shape=None, use_valid_check=False, use_dummy_pose=False):
11
"""
12
input:
13
model_cfg :
14
model_checkpoint :
15
device :
16
"""
17
super().
__init__
(model_cfg=model_cfg, model_checkpoint=model_checkpoint, device=device)
18
self.
input_func
= get_action_input_func(input_type)
19
self.
img_shape
= img_shape
20
self.
k
= k
#self.model.cfg.test_pipeline[0]['clip_len']
21
self.
use_valid_check
= use_valid_check
22
self.
use_dummy_pose
= use_dummy_pose
23
24
25
def
make_action_input
(self, pose_list, img_shape):
26
if
img_shape
is
None
:
27
img_shape = self.
img_shape
28
29
data = self.
input_func
(pose_list, img_shape)
30
31
data = self.
test_pipeline
(data)
32
data = pseudo_collate([data])
33
34
return
data
35
36
def
run_recognizer
(self, pose_results, img_shape=None):
37
if
self.
use_valid_check
and
not
utils.check_valid(pose_results, self.
k
):
38
return
None
39
40
if
self.
use_dummy_pose
:
41
pose_results = utils.insert_dummy_pose(pose_results)
42
43
data = self.
make_action_input
make_action_input
(pose_results, img_shape)
44
45
with
torch.no_grad():
46
result = self.
model
.test_step(data)[0]
47
48
action_labels = result.pred_labels.item.cpu().numpy()
49
scores = result.pred_scores.item.cpu().numpy()
50
51
return
{
'action_labels'
:action_labels,
'scores'
:scores}
mmaction_base_runner.MMActionBaseRunner
Definition
mmaction_base_runner.py:8
mmaction_base_runner.MMActionBaseRunner.make_action_input
make_action_input(self, *args, **kwargs)
Definition
mmaction_base_runner.py:20
mmaction_base_runner.MMActionBaseRunner.test_pipeline
test_pipeline
Definition
mmaction_base_runner.py:17
mmaction_base_runner.MMActionBaseRunner.model
model
Definition
mmaction_base_runner.py:12
mmaction_pytorch_runner.MMActionPyTorchRunner
Definition
mmaction_pytorch_runner.py:9
mmaction_pytorch_runner.MMActionPyTorchRunner.__init__
__init__(self, model_cfg, model_checkpoint, device='cuda', input_type='PoseC3D', k=60, img_shape=None, use_valid_check=False, use_dummy_pose=False)
Definition
mmaction_pytorch_runner.py:10
mmaction_pytorch_runner.MMActionPyTorchRunner.run_recognizer
run_recognizer(self, pose_results, img_shape=None)
Definition
mmaction_pytorch_runner.py:36
mmaction_pytorch_runner.MMActionPyTorchRunner.img_shape
img_shape
Definition
mmaction_pytorch_runner.py:19
mmaction_pytorch_runner.MMActionPyTorchRunner.use_dummy_pose
use_dummy_pose
Definition
mmaction_pytorch_runner.py:22
mmaction_pytorch_runner.MMActionPyTorchRunner.make_action_input
make_action_input(self, pose_list, img_shape)
Definition
mmaction_pytorch_runner.py:25
mmaction_pytorch_runner.MMActionPyTorchRunner.input_func
input_func
Definition
mmaction_pytorch_runner.py:18
mmaction_pytorch_runner.MMActionPyTorchRunner.use_valid_check
use_valid_check
Definition
mmaction_pytorch_runner.py:21
mmaction_pytorch_runner.MMActionPyTorchRunner.k
k
Definition
mmaction_pytorch_runner.py:20
transforms
Generated by
1.10.0