Files
modelscope/tests/pipelines/test_image_depth_estimation_marigold.py
Ranqing 1ade52df17 upload marigold monocular depth estimation core files (#703)
* upload marigold monocular depth estimation core files

* fix lint

* remove unused files.

* update marigold model files

* update marigold core files to fix review comments

* fix lint

* fix lint

* fix lint

* format code

* format code

---------

Co-authored-by: 葭润 <ranqing.rq@alibaba-inc.com>
Co-authored-by: wenmeng zhou <wenmeng.zwm@alibaba-inc.com>
2024-03-05 11:21:29 +08:00

43 lines
1.7 KiB
Python

# Copyright (c) Alibaba, Inc. and its affiliates.
import os
import unittest
from modelscope.hub.snapshot_download import snapshot_download
from modelscope.outputs import OutputKeys
from modelscope.pipelines import pipeline
from modelscope.pipelines.cv import ImageDepthEstimationMarigoldPipeline
from modelscope.utils.constant import Tasks
from modelscope.utils.test_utils import test_level
class ImageDepthEstimationMarigoldTest(unittest.TestCase):
def setUp(self) -> None:
self.task = Tasks.image_depth_estimation
self.model_id = 'Damo_XR_Lab/cv_marigold_monocular-depth-estimation'
self.image = 'data/in-the-wild_example/example_0.jpg'
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_model_name(self):
marigold = pipeline(task=self.task, model=self.model_id)
input_path = os.path.join(marigold.model, self.image)
result = marigold(input=input_path)
depth_vis = result[OutputKeys.DEPTHS_COLOR]
depth_vis.save('result_modelname.jpg')
print('Test run with model name ok.')
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_by_direct_model_download(self):
cache_path = snapshot_download(self.model_id)
marigold_pipe = ImageDepthEstimationMarigoldPipeline(cache_path)
marigold_pipe.group_key = self.task
input_path = os.path.join(cache_path, self.image)
result = marigold_pipe(input=input_path)
depth_vis = result[OutputKeys.DEPTHS_COLOR]
depth_vis.save('result_snapshot.jpg')
print('Test run with snapshot ok.')
if __name__ == '__main__':
unittest.main()