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_depth_estimation.py 1.2 kB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. import cv2
  4. import numpy as np
  5. from modelscope.outputs import OutputKeys
  6. from modelscope.pipelines import pipeline
  7. from modelscope.utils.constant import Tasks
  8. from modelscope.utils.cv.image_utils import depth_to_color
  9. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  10. from modelscope.utils.test_utils import test_level
  11. class ImageDepthEstimationTest(unittest.TestCase, DemoCompatibilityCheck):
  12. def setUp(self) -> None:
  13. self.task = 'image-depth-estimation'
  14. self.model_id = 'damo/cv_newcrfs_image-depth-estimation_indoor'
  15. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  16. def test_image_depth_estimation(self):
  17. input_location = 'data/test/images/image_depth_estimation.jpg'
  18. estimator = pipeline(Tasks.image_depth_estimation, model=self.model_id)
  19. result = estimator(input_location)
  20. depths = result[OutputKeys.DEPTHS]
  21. depth_viz = depth_to_color(depths[0].squeeze().cpu().numpy())
  22. cv2.imwrite('result.jpg', depth_viz)
  23. print('test_image_depth_estimation DONE')
  24. if __name__ == '__main__':
  25. unittest.main()