mmdeploy/tests/test_codebase/test_mmdet/test_mmdet_utils.py
hanrui1sensetime 308e28fcb0
[Enhancement] Support Object Detection and Instance Segmentation for ort trt ncnn and openvino in mmdet 2.0 (#786)
* support cascade (mask) rcnn

* fix docstring

* support SwinTransformer

* move dense_head support to this branch

* fix function names

* fix part of uts of mmdet

* fix for mmdet ut

* fix det model cfg for ut

* fix test_object_detection.py

* fix mmdet object_detection_model.py

* fix mmdet yolov3 ort ut

* fix part of uts

* fix cascade bbox head ut

* fix cascade bbox head ut

* remove useless ssd ncnn test

* fix ncnn wrapper

* fix openvino ut for reppoint head

* fix openvino cascade mask rcnn

* sync codes

* support roll

* remove unused pad

* fix yolox

* fix isort

* fix lint

* fix flake8

* reply for comments and fix failed ut

* fix sdk_export in dump_info

* fix temp hidden xlsx bugs

* fix mmdet regression test

* fix lint

* fix timer

* fix timecount side-effect

* adapt profile.py for mmdet 2.0

* hardcode report.txt for T4 benchmark test: temp version

* fix no-visualizer case

* fix backend_model

* fix android build

* adapt new mmdet 2.0 0825

* fix new 2.0

* fix test_mmdet_structures

* fix test_object_detection

* fix codebase import

* fix ut

* fix all mmdet uts

* fix det

* fix mmdet trt

* fix ncnn onnx optimize
2022-09-01 11:35:57 +08:00

65 lines
1.9 KiB
Python

# Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from mmengine import Config
from mmdeploy.codebase import import_codebase
from mmdeploy.codebase.mmdet import (clip_bboxes, get_post_processing_params,
pad_with_value,
pad_with_value_if_necessary)
from mmdeploy.utils import Codebase
import_codebase(Codebase.MMDET)
def test_clip_bboxes():
x1 = torch.rand(3, 2) * 224
y1 = torch.rand(3, 2) * 224
x2 = x1 * 2
y2 = y1 * 2
outs = clip_bboxes(x1, y1, x2, y2, [224, 224])
for out in outs:
assert int(out.max()) <= 224
def test_pad_with_value():
x = torch.rand(3, 2)
padded_x = pad_with_value(x, pad_dim=1, pad_size=4, pad_value=0)
assert np.allclose(
padded_x.shape, torch.Size([3, 6]), rtol=1e-03, atol=1e-05)
assert np.allclose(padded_x.sum(), x.sum(), rtol=1e-03, atol=1e-05)
def test_pad_with_value_if_necessary():
x = torch.rand(3, 2)
padded_x = pad_with_value_if_necessary(
x, pad_dim=1, pad_size=4, pad_value=0)
assert np.allclose(
padded_x.shape, torch.Size([3, 2]), rtol=1e-03, atol=1e-05)
assert np.allclose(padded_x.sum(), x.sum(), rtol=1e-03, atol=1e-05)
config_with_mmdet_params = Config(
dict(
codebase_config=dict(
type='mmdet',
task='ObjectDetection',
post_processing=dict(
score_threshold=0.05,
iou_threshold=0.5,
max_output_boxes_per_class=200,
pre_top_k=-1,
keep_top_k=100,
background_label_id=-1,
))))
def test_get_mmdet_params():
assert get_post_processing_params(config_with_mmdet_params) == dict(
score_threshold=0.05,
iou_threshold=0.5,
max_output_boxes_per_class=200,
pre_top_k=-1,
keep_top_k=100,
background_label_id=-1)