2022-09-20 17:49:31 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
|
2022-07-27 22:29:13 +08:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
2023-01-09 21:33:42 +08:00
|
|
|
from modelscope.utils.regress_test_utils import MsRegressTool
|
2022-07-27 22:29:13 +08:00
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2023-05-14 23:41:40 +08:00
|
|
|
class GeneralImageClassificationTest(unittest.TestCase):
|
2022-09-08 14:08:51 +08:00
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.task = Tasks.image_classification
|
|
|
|
|
self.model_id = 'damo/cv_vit-base_image-classification_Dailylife-labels'
|
2023-01-09 21:33:42 +08:00
|
|
|
self.regress_tool = MsRegressTool(baseline=False)
|
2022-07-27 22:29:13 +08:00
|
|
|
|
2022-08-06 12:22:17 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
2022-07-27 22:29:13 +08:00
|
|
|
def test_run_ImageNet(self):
|
|
|
|
|
general_image_classification = pipeline(
|
2022-08-02 22:24:28 +08:00
|
|
|
Tasks.image_classification,
|
2022-07-27 22:29:13 +08:00
|
|
|
model='damo/cv_vit-base_image-classification_ImageNet-labels')
|
|
|
|
|
result = general_image_classification('data/test/images/bird.JPEG')
|
|
|
|
|
print(result)
|
|
|
|
|
|
2022-08-06 12:22:17 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
2022-07-27 22:29:13 +08:00
|
|
|
def test_run_Dailylife(self):
|
|
|
|
|
general_image_classification = pipeline(
|
2022-08-02 22:24:28 +08:00
|
|
|
Tasks.image_classification,
|
2022-07-27 22:29:13 +08:00
|
|
|
model='damo/cv_vit-base_image-classification_Dailylife-labels')
|
2023-01-09 21:33:42 +08:00
|
|
|
with self.regress_tool.monitor_module_single_forward(
|
|
|
|
|
general_image_classification.model,
|
|
|
|
|
'vit_base_image_classification'):
|
|
|
|
|
result = general_image_classification('data/test/images/bird.JPEG')
|
2022-07-27 22:29:13 +08:00
|
|
|
print(result)
|
|
|
|
|
|
2022-12-02 14:46:49 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_nextvit(self):
|
|
|
|
|
nexit_image_classification = pipeline(
|
|
|
|
|
Tasks.image_classification,
|
|
|
|
|
model='damo/cv_nextvit-small_image-classification_Dailylife-labels'
|
|
|
|
|
)
|
|
|
|
|
result = nexit_image_classification('data/test/images/bird.JPEG')
|
|
|
|
|
print(result)
|
|
|
|
|
|
2023-01-09 06:56:05 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_convnext(self):
|
|
|
|
|
convnext_image_classification = pipeline(
|
|
|
|
|
Tasks.image_classification,
|
|
|
|
|
model='damo/cv_convnext-base_image-classification_garbage')
|
|
|
|
|
result = convnext_image_classification('data/test/images/banana.jpg')
|
|
|
|
|
print(result)
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_beitv2(self):
|
|
|
|
|
beitv2_image_classification = pipeline(
|
|
|
|
|
Tasks.image_classification,
|
|
|
|
|
model=
|
|
|
|
|
'damo/cv_beitv2-base_image-classification_patch16_224_pt1k_ft22k_in1k'
|
|
|
|
|
)
|
|
|
|
|
result = beitv2_image_classification('data/test/images/bird.JPEG')
|
|
|
|
|
print(result)
|
|
|
|
|
|
2023-09-26 21:15:41 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 2,
|
|
|
|
|
'skip test for timm compatbile need 0.5.4')
|
2023-01-16 10:02:34 +00:00
|
|
|
def test_run_easyrobust(self):
|
|
|
|
|
robust_image_classification = pipeline(
|
|
|
|
|
Tasks.image_classification, model='aaig/easyrobust-models')
|
|
|
|
|
result = robust_image_classification('data/test/images/bird.JPEG')
|
|
|
|
|
print(result)
|
|
|
|
|
|
2023-01-10 07:42:24 +08:00
|
|
|
def test_run_bnext(self):
|
|
|
|
|
nexit_image_classification = pipeline(
|
|
|
|
|
Tasks.image_classification,
|
|
|
|
|
model='damo/cv_bnext-small_image-classification_ImageNet-labels')
|
|
|
|
|
result = nexit_image_classification('data/test/images/bird.JPEG')
|
|
|
|
|
print(result)
|
|
|
|
|
|
2022-08-06 12:22:17 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
2022-08-02 22:24:28 +08:00
|
|
|
def test_run_Dailylife_default(self):
|
|
|
|
|
general_image_classification = pipeline(Tasks.image_classification)
|
2022-07-27 22:29:13 +08:00
|
|
|
result = general_image_classification('data/test/images/bird.JPEG')
|
|
|
|
|
print(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|