From 085acc64c8ebedd4f2f12cef3d7f10f2ee331260 Mon Sep 17 00:00:00 2001 From: "shuying.shu" Date: Thu, 10 Nov 2022 13:09:56 +0800 Subject: [PATCH] fix bug and change unittest mode Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10680402 --- ...ring_video_object_segmentation_pipeline.py | 22 +++++++++++-------- ...est_referring_video_object_segmentation.py | 4 ++-- ...rring_video_object_segmentation_trainer.py | 12 +++++----- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/modelscope/pipelines/cv/referring_video_object_segmentation_pipeline.py b/modelscope/pipelines/cv/referring_video_object_segmentation_pipeline.py index cfbf2607..f0a717a5 100644 --- a/modelscope/pipelines/cv/referring_video_object_segmentation_pipeline.py +++ b/modelscope/pipelines/cv/referring_video_object_segmentation_pipeline.py @@ -138,6 +138,19 @@ class ReferringVideoObjectSegmentationPipeline(Pipeline): video_np = rearrange(self.video, 't c h w -> t h w c').numpy() / 255.0 + # set font for text query in output video + if self.model.cfg.pipeline.output_font: + try: + font = ImageFont.truetype( + font=self.model.cfg.pipeline.output_font, + size=self.model.cfg.pipeline.output_font_size) + except OSError: + logger.error('can\'t open resource %s, load default font' + % self.model.cfg.pipeline.output_font) + font = ImageFont.load_default() + else: + font = ImageFont.load_default() + # del video pred_masks_per_frame = rearrange( torch.stack(inputs), 'q t 1 h w -> t q h w').numpy() @@ -158,12 +171,6 @@ class ReferringVideoObjectSegmentationPipeline(Pipeline): W, H = vid_frame.size draw = ImageDraw.Draw(vid_frame) - if self.model.cfg.pipeline.output_font: - font = ImageFont.truetype( - font=self.model.cfg.pipeline.output_font, - size=self.model.cfg.pipeline.output_font_size) - else: - font = ImageFont.load_default() for i, (text_query, color) in enumerate( zip(self.text_queries, colors), start=1): w, h = draw.textsize(text_query, font=font) @@ -173,9 +180,6 @@ class ReferringVideoObjectSegmentationPipeline(Pipeline): fill=tuple(color) + (255, ), font=font) masked_video.append(np.array(vid_frame)) - print(type(vid_frame)) - print(type(masked_video[0])) - print(masked_video[0].shape) # generate and save the output clip: assert self.model.cfg.pipeline.output_path diff --git a/tests/pipelines/test_referring_video_object_segmentation.py b/tests/pipelines/test_referring_video_object_segmentation.py index 4d8206b3..3e81d9c3 100644 --- a/tests/pipelines/test_referring_video_object_segmentation.py +++ b/tests/pipelines/test_referring_video_object_segmentation.py @@ -14,7 +14,7 @@ class ReferringVideoObjectSegmentationTest(unittest.TestCase, self.task = Tasks.referring_video_object_segmentation self.model_id = 'damo/cv_swin-t_referring_video-object-segmentation' - @unittest.skip('skip since the model is set to private for now') + @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') def test_referring_video_object_segmentation(self): input_location = 'data/test/videos/referring_video_object_segmentation_test_video.mp4' text_queries = [ @@ -31,7 +31,7 @@ class ReferringVideoObjectSegmentationTest(unittest.TestCase, else: raise ValueError('process error') - @unittest.skip('skip since the model is set to private for now') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_referring_video_object_segmentation_with_default_task(self): input_location = 'data/test/videos/referring_video_object_segmentation_test_video.mp4' text_queries = [ diff --git a/tests/trainers/test_referring_video_object_segmentation_trainer.py b/tests/trainers/test_referring_video_object_segmentation_trainer.py index 7b03eb4d..fb152954 100644 --- a/tests/trainers/test_referring_video_object_segmentation_trainer.py +++ b/tests/trainers/test_referring_video_object_segmentation_trainer.py @@ -7,8 +7,8 @@ import zipfile from modelscope.hub.snapshot_download import snapshot_download from modelscope.metainfo import Trainers -from modelscope.models.cv.movie_scene_segmentation import \ - MovieSceneSegmentationModel +from modelscope.models.cv.referring_video_object_segmentation import \ + ReferringVideoObjectSegmentation from modelscope.msdatasets import MsDataset from modelscope.trainers import build_trainer from modelscope.utils.config import Config, ConfigDict @@ -46,7 +46,6 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase): dataset_name=train_data_cfg.name, split=train_data_cfg.split, cfg=train_data_cfg.cfg, - namespace='damo', test_mode=train_data_cfg.test_mode) assert next( iter(self.train_dataset.config_kwargs['split_config'].values())) @@ -55,14 +54,13 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase): dataset_name=test_data_cfg.name, split=test_data_cfg.split, cfg=test_data_cfg.cfg, - namespace='damo', test_mode=test_data_cfg.test_mode) assert next( iter(self.test_dataset.config_kwargs['split_config'].values())) self.max_epochs = max_epochs - @unittest.skip('skip since the model is set to private for now') + @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') def test_trainer(self): kwargs = dict( model=self.model_id, @@ -77,11 +75,11 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase): results_files = os.listdir(trainer.work_dir) self.assertIn(f'{trainer.timestamp}.log.json', results_files) - @unittest.skip('skip since the model is set to private for now') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_trainer_with_model_and_args(self): cache_path = snapshot_download(self.model_id) - model = MovieSceneSegmentationModel.from_pretrained(cache_path) + model = ReferringVideoObjectSegmentation.from_pretrained(cache_path) kwargs = dict( cfg_file=os.path.join(cache_path, ModelFile.CONFIGURATION), model=model,