2023-02-09 09:05:35 +00:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
2023-03-01 12:05:57 +08:00
|
|
|
import os
|
2023-02-09 09:05:35 +00:00
|
|
|
import unittest
|
|
|
|
|
|
2023-02-14 11:47:49 +00:00
|
|
|
import torch
|
|
|
|
|
|
2023-02-09 09:05:35 +00:00
|
|
|
from modelscope.hub.snapshot_download import snapshot_download
|
2023-03-01 12:05:57 +08:00
|
|
|
from modelscope.msdatasets import MsDataset
|
2023-02-09 09:05:35 +00:00
|
|
|
from modelscope.outputs import OutputKeys
|
|
|
|
|
from modelscope.pipelines import pipeline
|
2023-03-08 16:23:58 +08:00
|
|
|
from modelscope.utils.constant import DownloadMode, Tasks
|
2023-02-09 09:05:35 +00:00
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2023-05-22 10:53:18 +08:00
|
|
|
class NeRFReconAccTest(unittest.TestCase):
|
2023-02-09 09:05:35 +00:00
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.model_id = 'damo/cv_nerf-3d-reconstruction-accelerate_damo'
|
2023-03-01 12:05:57 +08:00
|
|
|
data_dir = MsDataset.load(
|
2023-03-08 16:23:58 +08:00
|
|
|
'nerf_recon_dataset',
|
|
|
|
|
namespace='damo',
|
|
|
|
|
split='train',
|
|
|
|
|
download_mode=DownloadMode.FORCE_REDOWNLOAD
|
|
|
|
|
).config_kwargs['split_config']['train']
|
2023-03-01 12:05:57 +08:00
|
|
|
nerf_synthetic_dataset = os.path.join(data_dir, 'nerf_synthetic')
|
|
|
|
|
blender_scene = 'lego'
|
|
|
|
|
self.data_dir = os.path.join(nerf_synthetic_dataset, blender_scene)
|
|
|
|
|
self.render_dir = 'exp'
|
2023-02-09 09:05:35 +00:00
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
2023-02-14 11:47:49 +00:00
|
|
|
@unittest.skipIf(not torch.cuda.is_available(), 'cuda unittest only')
|
2023-02-09 09:05:35 +00:00
|
|
|
def test_run_by_direct_model_download(self):
|
|
|
|
|
snapshot_path = snapshot_download(self.model_id)
|
|
|
|
|
print('snapshot_path: {}'.format(snapshot_path))
|
|
|
|
|
nerf_recon_acc = pipeline(
|
|
|
|
|
Tasks.nerf_recon_acc,
|
|
|
|
|
model=snapshot_path,
|
2023-03-01 12:05:57 +08:00
|
|
|
data_type='blender',
|
2023-02-09 09:05:35 +00:00
|
|
|
)
|
|
|
|
|
|
2023-03-01 12:05:57 +08:00
|
|
|
nerf_recon_acc(
|
|
|
|
|
dict(data_dir=self.data_dir, render_dir=self.render_dir))
|
2023-02-09 09:05:35 +00:00
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
2023-02-14 11:47:49 +00:00
|
|
|
@unittest.skipIf(not torch.cuda.is_available(), 'cuda unittest only')
|
2023-02-09 09:05:35 +00:00
|
|
|
def test_run_modelhub(self):
|
2023-03-01 12:05:57 +08:00
|
|
|
nerf_recon_acc = pipeline(
|
|
|
|
|
Tasks.nerf_recon_acc,
|
|
|
|
|
model=self.model_id,
|
|
|
|
|
data_type='blender',
|
|
|
|
|
)
|
2023-02-09 09:05:35 +00:00
|
|
|
|
2023-03-01 12:05:57 +08:00
|
|
|
nerf_recon_acc(
|
|
|
|
|
dict(data_dir=self.data_dir, render_dir=self.render_dir))
|
2023-02-09 09:05:35 +00:00
|
|
|
print('facefusion.test_run_modelhub done')
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
2023-02-14 11:47:49 +00:00
|
|
|
@unittest.skipIf(not torch.cuda.is_available(), 'cuda unittest only')
|
2023-02-09 09:05:35 +00:00
|
|
|
def test_run_modelhub_default_model(self):
|
|
|
|
|
nerf_recon_acc = pipeline(Tasks.nerf_recon_acc)
|
2023-03-01 12:05:57 +08:00
|
|
|
nerf_recon_acc(
|
|
|
|
|
dict(data_dir=self.data_dir, render_dir=self.render_dir))
|
2023-02-09 09:05:35 +00:00
|
|
|
print('facefusion.test_run_modelhub_default_model done')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|