test_bmn.py 2.17 KB
Newer Older
unknown's avatar
unknown committed
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
59
60
61
62
63
64
65
66
67
68
# Copyright (c) OpenMMLab. All rights reserved.
import platform

import numpy as np
import pytest
import torch

from mmaction.models import build_localizer
from ..base import get_localizer_cfg


@pytest.mark.skipif(platform.system() == 'Windows', reason='Windows mem limit')
def test_bmn_train():
    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(3, 400, 100).cuda()
        gt_bbox = np.array([[[0.1, 0.3], [0.375, 0.625]]] * 3)
        losses = localizer_bmn(raw_feature, gt_bbox)
        assert isinstance(losses, dict)

    else:
        localizer_bmn = build_localizer(model_cfg.model)
        raw_feature = torch.rand(3, 400, 100)
        gt_bbox = torch.Tensor([[[0.1, 0.3], [0.375, 0.625]]] * 3)
        losses = localizer_bmn(raw_feature, gt_bbox)
        assert isinstance(losses, dict)


@pytest.mark.skipif(platform.system() == 'Windows', reason='Windows mem limit')
def test_bmn_test():
    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()
        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)
        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)