mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-01 19:49:03 +02:00
[to #42322933] 1230: add hand detection
This commit is contained in:
3
data/test/images/hand_detection.jpg
Normal file
3
data/test/images/hand_detection.jpg
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:44b225eaff012bd016fcfe8a3dbeace93fd418164f40e4b5f5b9f0d76f39097b
|
||||
size 308635
|
||||
@@ -216,6 +216,7 @@ class Pipelines(object):
|
||||
image_portrait_enhancement = 'gpen-image-portrait-enhancement'
|
||||
image_to_image_generation = 'image-to-image-generation'
|
||||
image_object_detection_auto = 'yolox_image-object-detection-auto'
|
||||
hand_detection = 'yolox-pai_hand-detection'
|
||||
skin_retouching = 'unet-skin-retouching'
|
||||
tinynas_classification = 'tinynas-classification'
|
||||
tinynas_detection = 'tinynas-detection'
|
||||
|
||||
@@ -15,6 +15,8 @@ from .base import EasyCVPipeline
|
||||
@PIPELINES.register_module(
|
||||
Tasks.image_object_detection,
|
||||
module_name=Pipelines.image_object_detection_auto)
|
||||
@PIPELINES.register_module(
|
||||
Tasks.image_object_detection, module_name=Pipelines.hand_detection)
|
||||
class EasyCVDetectionPipeline(EasyCVPipeline):
|
||||
"""Pipeline for easycv detection task."""
|
||||
|
||||
|
||||
@@ -461,7 +461,7 @@ def show_image_object_detection_auto_result(img_path,
|
||||
lineType=8)
|
||||
cv2.putText(
|
||||
img,
|
||||
label, (int((box[0] + box[2]) * 0.5), int(box[1])),
|
||||
label, (int(box[0]), int(box[3])),
|
||||
1,
|
||||
1.0, (0, 255, 0),
|
||||
thickness=1,
|
||||
|
||||
30
tests/pipelines/test_hand_detection.py
Normal file
30
tests/pipelines/test_hand_detection.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
import unittest
|
||||
|
||||
from modelscope.pipelines import pipeline
|
||||
from modelscope.utils.constant import Tasks
|
||||
from modelscope.utils.demo_utils import DemoCompatibilityCheck
|
||||
from modelscope.utils.test_utils import test_level
|
||||
|
||||
|
||||
class ObjectDetectionTest(unittest.TestCase, DemoCompatibilityCheck):
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.task = Tasks.image_object_detection
|
||||
self.model_id = 'damo/cv_yolox-pai_hand-detection'
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_hand_detection_pipeline(self):
|
||||
test_image = 'data/test/images/hand_detection.jpg'
|
||||
|
||||
hand_detection = pipeline(self.task, model=self.model_id)
|
||||
|
||||
result = hand_detection(test_image)
|
||||
hand_detection.show_result(test_image, result,
|
||||
'hand_detection_ret.jpg')
|
||||
|
||||
print(f'hand detection result={result}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
64
tests/trainers/easycv/test_easycv_trainer_hand_detection.py
Normal file
64
tests/trainers/easycv/test_easycv_trainer_hand_detection.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
import glob
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import torch
|
||||
|
||||
from modelscope.metainfo import Trainers
|
||||
from modelscope.msdatasets import MsDataset
|
||||
from modelscope.trainers import build_trainer
|
||||
from modelscope.utils.constant import DownloadMode, LogKeys, Tasks
|
||||
from modelscope.utils.logger import get_logger
|
||||
from modelscope.utils.test_utils import test_level
|
||||
|
||||
|
||||
class EasyCVTrainerTestHandDetection(unittest.TestCase):
|
||||
model_id = 'damo/cv_yolox-pai_hand-detection'
|
||||
|
||||
def setUp(self):
|
||||
self.logger = get_logger()
|
||||
self.logger.info(('Testing %s.%s' %
|
||||
(type(self).__name__, self._testMethodName)))
|
||||
|
||||
def _train(self, tmp_dir):
|
||||
cfg_options = {'train.max_epochs': 2}
|
||||
|
||||
trainer_name = Trainers.easycv
|
||||
|
||||
train_dataset = MsDataset.load(
|
||||
dataset_name='hand_detection_dataset', split='subtrain')
|
||||
eval_dataset = MsDataset.load(
|
||||
dataset_name='hand_detection_dataset', split='subtrain')
|
||||
|
||||
kwargs = dict(
|
||||
model=self.model_id,
|
||||
train_dataset=train_dataset,
|
||||
eval_dataset=eval_dataset,
|
||||
work_dir=tmp_dir,
|
||||
cfg_options=cfg_options)
|
||||
|
||||
trainer = build_trainer(trainer_name, kwargs)
|
||||
trainer.train()
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_trainer_single_gpu(self):
|
||||
temp_file_dir = tempfile.TemporaryDirectory()
|
||||
tmp_dir = temp_file_dir.name
|
||||
if not os.path.exists(tmp_dir):
|
||||
os.makedirs(tmp_dir)
|
||||
|
||||
self._train(tmp_dir)
|
||||
|
||||
results_files = os.listdir(tmp_dir)
|
||||
json_files = glob.glob(os.path.join(tmp_dir, '*.log.json'))
|
||||
self.assertEqual(len(json_files), 1)
|
||||
self.assertIn(f'{LogKeys.EPOCH}_2.pth', results_files)
|
||||
|
||||
temp_file_dir.cleanup()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user