You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_multi_modal_embedding.py 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. import numpy as np
  4. from modelscope.models import Model
  5. from modelscope.pipelines import pipeline
  6. from modelscope.utils.constant import Tasks
  7. from modelscope.utils.test_utils import test_level
  8. class MultiModalEmbeddingTest(unittest.TestCase):
  9. model_id = 'damo/multi-modal_clip-vit-large-patch14-chinese_multi-modal-embedding'
  10. test_text = {'text': '一张风景图'}
  11. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  12. def test_run(self):
  13. pipe_line_multi_modal_embedding = pipeline(
  14. Tasks.multi_modal_embedding, model=self.model_id)
  15. test_str_embedding = pipe_line_multi_modal_embedding(
  16. self.test_text)['text_embedding']
  17. print(np.sum(np.abs(test_str_embedding)))
  18. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  19. def test_run_with_model_from_modelhub(self):
  20. model = Model.from_pretrained(self.model_id)
  21. pipe_line_multi_modal_embedding = pipeline(
  22. task=Tasks.multi_modal_embedding, model=model)
  23. test_str_embedding = pipe_line_multi_modal_embedding(
  24. self.test_text)['text_embedding']
  25. print(np.sum(np.abs(test_str_embedding)))
  26. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  27. def test_run_with_model_name(self):
  28. pipe_line_multi_modal_embedding = pipeline(
  29. task=Tasks.multi_modal_embedding, model=self.model_id)
  30. test_str_embedding = pipe_line_multi_modal_embedding(
  31. self.test_text)['text_embedding']
  32. print(np.sum(np.abs(test_str_embedding)))
  33. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  34. def test_run_with_default_model(self):
  35. pipe_line_multi_modal_embedding = pipeline(
  36. task=Tasks.multi_modal_embedding)
  37. test_str_embedding = pipe_line_multi_modal_embedding(
  38. self.test_text)['text_embedding']
  39. print(np.sum(np.abs(test_str_embedding)))
  40. if __name__ == '__main__':
  41. unittest.main()