[6d389a]: / tests / test_models / test_localizers / test_bmn.py

Download this file

57 lines (50 with data), 1.8 kB

 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
# Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from mmaction.models import build_localizer
from ..base import get_localizer_cfg
def test_bmn():
model_cfg = get_localizer_cfg(
'bmn/bmn_400x100_2x8_9e_activitynet_feature.py')
if torch.cuda.is_available():
localizer_bmn = build_localizer(model_cfg.model).cuda()
raw_feature = torch.rand(8, 400, 100).cuda()
gt_bbox = np.array([[[0.1, 0.3], [0.375, 0.625]]] * 8)
losses = localizer_bmn(raw_feature, gt_bbox)
assert isinstance(losses, dict)
# Test forward test
video_meta = [
dict(
video_name='v_test',
duration_second=100,
duration_frame=960,
feature_frame=960)
]
with torch.no_grad():
one_raw_feature = torch.rand(1, 400, 100).cuda()
localizer_bmn(
one_raw_feature,
gt_bbox=None,
video_meta=video_meta,
return_loss=False)
else:
localizer_bmn = build_localizer(model_cfg.model)
raw_feature = torch.rand(8, 400, 100)
gt_bbox = torch.Tensor([[[0.1, 0.3], [0.375, 0.625]]] * 8)
losses = localizer_bmn(raw_feature, gt_bbox)
assert isinstance(losses, dict)
# Test forward test
video_meta = [
dict(
video_name='v_test',
duration_second=100,
duration_frame=960,
feature_frame=960)
]
with torch.no_grad():
one_raw_feature = torch.rand(1, 400, 100)
localizer_bmn(
one_raw_feature,
gt_bbox=None,
video_meta=video_meta,
return_loss=False)