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_image_reid_person.py 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. from PIL import Image
  4. from modelscope.outputs import OutputKeys
  5. from modelscope.pipelines import pipeline
  6. from modelscope.utils.constant import Tasks
  7. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  8. from modelscope.utils.test_utils import test_level
  9. class ImageReidPersonTest(unittest.TestCase, DemoCompatibilityCheck):
  10. def setUp(self) -> None:
  11. self.input_location = 'data/test/images/image_reid_person.jpg'
  12. self.model_id = 'damo/cv_passvitb_image-reid-person_market'
  13. self.task = Tasks.image_reid_person
  14. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  15. def test_image_reid_person(self):
  16. image_reid_person = pipeline(
  17. Tasks.image_reid_person, model=self.model_id)
  18. result = image_reid_person(self.input_location)
  19. assert result and OutputKeys.IMG_EMBEDDING in result
  20. print(
  21. f'The shape of img embedding is: {result[OutputKeys.IMG_EMBEDDING].shape}'
  22. )
  23. print(f'The img embedding is: {result[OutputKeys.IMG_EMBEDDING]}')
  24. @unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
  25. def test_image_reid_person_with_image(self):
  26. image_reid_person = pipeline(
  27. Tasks.image_reid_person, model=self.model_id)
  28. img = Image.open(self.input_location)
  29. result = image_reid_person(img)
  30. assert result and OutputKeys.IMG_EMBEDDING in result
  31. print(
  32. f'The shape of img embedding is: {result[OutputKeys.IMG_EMBEDDING].shape}'
  33. )
  34. print(f'The img embedding is: {result[OutputKeys.IMG_EMBEDDING]}')
  35. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  36. def test_image_reid_person_with_default_model(self):
  37. image_reid_person = pipeline(Tasks.image_reid_person)
  38. result = image_reid_person(self.input_location)
  39. assert result and OutputKeys.IMG_EMBEDDING in result
  40. print(
  41. f'The shape of img embedding is: {result[OutputKeys.IMG_EMBEDDING].shape}'
  42. )
  43. print(f'The img embedding is: {result[OutputKeys.IMG_EMBEDDING]}')
  44. @unittest.skip('demo compatibility test is only enabled on a needed-basis')
  45. def test_demo_compatibility(self):
  46. self.compatibility_check()
  47. if __name__ == '__main__':
  48. unittest.main()