2022-08-27 10:48:56 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
import cv2
|
|
|
|
|
|
|
|
|
|
from modelscope.outputs import OutputKeys
|
|
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
|
|
|
|
from modelscope.utils.cv.image_utils import realtime_object_detection_bbox_vis
|
2022-09-08 14:08:51 +08:00
|
|
|
from modelscope.utils.demo_utils import DemoCompatibilityCheck
|
2022-08-27 10:48:56 +08:00
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2022-09-08 14:08:51 +08:00
|
|
|
class RealtimeObjectDetectionTest(unittest.TestCase, DemoCompatibilityCheck):
|
2022-08-27 10:48:56 +08:00
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.model_id = 'damo/cv_cspnet_image-object-detection_yolox'
|
|
|
|
|
self.model_nano_id = 'damo/cv_cspnet_image-object-detection_yolox_nano_coco'
|
|
|
|
|
self.test_image = 'data/test/images/keypoints_detect/000000438862.jpg'
|
2022-09-08 14:08:51 +08:00
|
|
|
self.task = Tasks.image_object_detection
|
2022-08-27 10:48:56 +08:00
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_modelhub(self):
|
|
|
|
|
realtime_object_detection = pipeline(
|
|
|
|
|
Tasks.image_object_detection, model=self.model_id)
|
|
|
|
|
|
|
|
|
|
image = cv2.imread(self.test_image)
|
|
|
|
|
result = realtime_object_detection(image)
|
|
|
|
|
if result:
|
|
|
|
|
bboxes = result[OutputKeys.BOXES].astype(int)
|
|
|
|
|
image = realtime_object_detection_bbox_vis(image, bboxes)
|
|
|
|
|
cv2.imwrite('rt_obj_out.jpg', image)
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError('process error')
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_nano(self):
|
|
|
|
|
realtime_object_detection = pipeline(
|
|
|
|
|
Tasks.image_object_detection, model=self.model_nano_id)
|
|
|
|
|
|
|
|
|
|
image = cv2.imread(self.test_image)
|
|
|
|
|
result = realtime_object_detection(image)
|
|
|
|
|
if result:
|
|
|
|
|
bboxes = result[OutputKeys.BOXES].astype(int)
|
|
|
|
|
image = realtime_object_detection_bbox_vis(image, bboxes)
|
|
|
|
|
cv2.imwrite('rtnano_obj_out.jpg', image)
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError('process error')
|
|
|
|
|
|
2022-09-08 14:08:51 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_demo_compatibility(self):
|
|
|
|
|
self.compatibility_check()
|
|
|
|
|
|
2022-08-27 10:48:56 +08:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|