2022-07-26 14:09:18 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from modelscope.models import Model
|
|
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
2022-09-08 14:08:51 +08:00
|
|
|
from modelscope.utils.demo_utils import DemoCompatibilityCheck
|
2022-07-26 14:09:18 +08:00
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2022-09-08 14:08:51 +08:00
|
|
|
class GEMMMultiModalEmbeddingTest(unittest.TestCase, DemoCompatibilityCheck):
|
|
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.task = Tasks.generative_multi_modal_embedding
|
|
|
|
|
self.model_id = 'damo/multi-modal_gemm-vit-large-patch14_generative-multi-modal-embedding'
|
|
|
|
|
|
2022-07-26 14:09:18 +08:00
|
|
|
test_input = {
|
|
|
|
|
'image': 'data/test/images/generative_multimodal.jpg',
|
|
|
|
|
'text':
|
|
|
|
|
'interior design of modern living room with fireplace in a new house',
|
|
|
|
|
'captioning': False
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 12:22:17 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
2022-07-26 14:09:18 +08:00
|
|
|
def test_run(self):
|
|
|
|
|
generative_multi_modal_embedding_pipeline = pipeline(
|
|
|
|
|
Tasks.generative_multi_modal_embedding, model=self.model_id)
|
|
|
|
|
output = generative_multi_modal_embedding_pipeline(self.test_input)
|
|
|
|
|
print(output)
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_run_with_default_model(self):
|
|
|
|
|
generative_multi_modal_embedding_pipeline = pipeline(
|
|
|
|
|
task=Tasks.generative_multi_modal_embedding)
|
|
|
|
|
output = generative_multi_modal_embedding_pipeline(self.test_input)
|
|
|
|
|
print(output)
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_from_modelhub(self):
|
|
|
|
|
model = Model.from_pretrained(self.model_id)
|
|
|
|
|
generative_multi_modal_embedding_pipeline = pipeline(
|
|
|
|
|
task=Tasks.generative_multi_modal_embedding, model=model)
|
|
|
|
|
output = generative_multi_modal_embedding_pipeline(self.test_input)
|
|
|
|
|
print(output)
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_run_with_output_captioning(self):
|
|
|
|
|
generative_multi_modal_embedding_pipeline = pipeline(
|
|
|
|
|
task=Tasks.generative_multi_modal_embedding, model=self.model_id)
|
|
|
|
|
test_input = {'image': self.test_input['image'], 'captioning': True}
|
|
|
|
|
output = generative_multi_modal_embedding_pipeline(test_input)
|
|
|
|
|
print(output)
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_run_with_output_only_image(self):
|
|
|
|
|
generative_multi_modal_embedding_pipeline = pipeline(
|
|
|
|
|
task=Tasks.generative_multi_modal_embedding, model=self.model_id)
|
|
|
|
|
test_input = {'image': self.test_input['image'], 'captioning': False}
|
|
|
|
|
output = generative_multi_modal_embedding_pipeline(test_input)
|
|
|
|
|
print(output)
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_run_with_output_only_text(self):
|
|
|
|
|
generative_multi_modal_embedding_pipeline = pipeline(
|
|
|
|
|
task=Tasks.generative_multi_modal_embedding, model=self.model_id)
|
|
|
|
|
test_input = {'text': self.test_input['text']}
|
|
|
|
|
output = generative_multi_modal_embedding_pipeline(test_input)
|
|
|
|
|
print(output)
|
|
|
|
|
|
2022-09-09 14:56:15 +08:00
|
|
|
@unittest.skip('demo compatibility test is only enabled on a needed-basis')
|
2022-09-08 14:08:51 +08:00
|
|
|
def test_demo_compatibility(self):
|
|
|
|
|
self.compatibility_check()
|
|
|
|
|
|
2022-07-26 14:09:18 +08:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|