Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10680402master
| @@ -138,6 +138,19 @@ class ReferringVideoObjectSegmentationPipeline(Pipeline): | |||||
| video_np = rearrange(self.video, | video_np = rearrange(self.video, | ||||
| 't c h w -> t h w c').numpy() / 255.0 | '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 | # del video | ||||
| pred_masks_per_frame = rearrange( | pred_masks_per_frame = rearrange( | ||||
| torch.stack(inputs), 'q t 1 h w -> t q h w').numpy() | 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 | W, H = vid_frame.size | ||||
| draw = ImageDraw.Draw(vid_frame) | 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( | for i, (text_query, color) in enumerate( | ||||
| zip(self.text_queries, colors), start=1): | zip(self.text_queries, colors), start=1): | ||||
| w, h = draw.textsize(text_query, font=font) | w, h = draw.textsize(text_query, font=font) | ||||
| @@ -173,9 +180,6 @@ class ReferringVideoObjectSegmentationPipeline(Pipeline): | |||||
| fill=tuple(color) + (255, ), | fill=tuple(color) + (255, ), | ||||
| font=font) | font=font) | ||||
| masked_video.append(np.array(vid_frame)) | 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: | # generate and save the output clip: | ||||
| assert self.model.cfg.pipeline.output_path | assert self.model.cfg.pipeline.output_path | ||||
| @@ -14,7 +14,7 @@ class ReferringVideoObjectSegmentationTest(unittest.TestCase, | |||||
| self.task = Tasks.referring_video_object_segmentation | self.task = Tasks.referring_video_object_segmentation | ||||
| self.model_id = 'damo/cv_swin-t_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): | def test_referring_video_object_segmentation(self): | ||||
| input_location = 'data/test/videos/referring_video_object_segmentation_test_video.mp4' | input_location = 'data/test/videos/referring_video_object_segmentation_test_video.mp4' | ||||
| text_queries = [ | text_queries = [ | ||||
| @@ -31,7 +31,7 @@ class ReferringVideoObjectSegmentationTest(unittest.TestCase, | |||||
| else: | else: | ||||
| raise ValueError('process error') | 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): | def test_referring_video_object_segmentation_with_default_task(self): | ||||
| input_location = 'data/test/videos/referring_video_object_segmentation_test_video.mp4' | input_location = 'data/test/videos/referring_video_object_segmentation_test_video.mp4' | ||||
| text_queries = [ | text_queries = [ | ||||
| @@ -7,8 +7,8 @@ import zipfile | |||||
| from modelscope.hub.snapshot_download import snapshot_download | from modelscope.hub.snapshot_download import snapshot_download | ||||
| from modelscope.metainfo import Trainers | 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.msdatasets import MsDataset | ||||
| from modelscope.trainers import build_trainer | from modelscope.trainers import build_trainer | ||||
| from modelscope.utils.config import Config, ConfigDict | from modelscope.utils.config import Config, ConfigDict | ||||
| @@ -46,7 +46,6 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase): | |||||
| dataset_name=train_data_cfg.name, | dataset_name=train_data_cfg.name, | ||||
| split=train_data_cfg.split, | split=train_data_cfg.split, | ||||
| cfg=train_data_cfg.cfg, | cfg=train_data_cfg.cfg, | ||||
| namespace='damo', | |||||
| test_mode=train_data_cfg.test_mode) | test_mode=train_data_cfg.test_mode) | ||||
| assert next( | assert next( | ||||
| iter(self.train_dataset.config_kwargs['split_config'].values())) | iter(self.train_dataset.config_kwargs['split_config'].values())) | ||||
| @@ -55,14 +54,13 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase): | |||||
| dataset_name=test_data_cfg.name, | dataset_name=test_data_cfg.name, | ||||
| split=test_data_cfg.split, | split=test_data_cfg.split, | ||||
| cfg=test_data_cfg.cfg, | cfg=test_data_cfg.cfg, | ||||
| namespace='damo', | |||||
| test_mode=test_data_cfg.test_mode) | test_mode=test_data_cfg.test_mode) | ||||
| assert next( | assert next( | ||||
| iter(self.test_dataset.config_kwargs['split_config'].values())) | iter(self.test_dataset.config_kwargs['split_config'].values())) | ||||
| self.max_epochs = max_epochs | 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): | def test_trainer(self): | ||||
| kwargs = dict( | kwargs = dict( | ||||
| model=self.model_id, | model=self.model_id, | ||||
| @@ -77,11 +75,11 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase): | |||||
| results_files = os.listdir(trainer.work_dir) | results_files = os.listdir(trainer.work_dir) | ||||
| self.assertIn(f'{trainer.timestamp}.log.json', results_files) | 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): | def test_trainer_with_model_and_args(self): | ||||
| cache_path = snapshot_download(self.model_id) | cache_path = snapshot_download(self.model_id) | ||||
| model = MovieSceneSegmentationModel.from_pretrained(cache_path) | |||||
| model = ReferringVideoObjectSegmentation.from_pretrained(cache_path) | |||||
| kwargs = dict( | kwargs = dict( | ||||
| cfg_file=os.path.join(cache_path, ModelFile.CONFIGURATION), | cfg_file=os.path.join(cache_path, ModelFile.CONFIGURATION), | ||||
| model=model, | model=model, | ||||