|
|
@@ -9,7 +9,7 @@ from modelscope.metainfo import Trainers |
|
|
|
from modelscope.models.multi_modal import MPlugForAllTasks |
|
|
|
from modelscope.msdatasets import MsDataset |
|
|
|
from modelscope.trainers import EpochBasedTrainer, build_trainer |
|
|
|
from modelscope.utils.constant import ModelFile |
|
|
|
from modelscope.utils.constant import ModelFile, Tasks |
|
|
|
from modelscope.utils.test_utils import test_level |
|
|
|
|
|
|
|
|
|
|
@@ -40,11 +40,12 @@ class TestFinetuneMPlug(unittest.TestCase): |
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
|
def test_trainer_with_caption(self): |
|
|
|
kwargs = dict( |
|
|
|
model='damo/mplug_image-captioning_coco_base_en', |
|
|
|
model='damo/mplug_backbone_base_en', |
|
|
|
train_dataset=self.train_dataset, |
|
|
|
eval_dataset=self.test_dataset, |
|
|
|
max_epochs=self.max_epochs, |
|
|
|
work_dir=self.tmp_dir) |
|
|
|
work_dir=self.tmp_dir, |
|
|
|
task=Tasks.image_captioning) |
|
|
|
|
|
|
|
trainer: EpochBasedTrainer = build_trainer( |
|
|
|
name=Trainers.mplug, default_args=kwargs) |
|
|
@@ -52,9 +53,9 @@ class TestFinetuneMPlug(unittest.TestCase): |
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level') |
|
|
|
def test_trainer_with_caption_with_model_and_args(self): |
|
|
|
cache_path = snapshot_download( |
|
|
|
'damo/mplug_image-captioning_coco_base_en') |
|
|
|
model = MPlugForAllTasks.from_pretrained(cache_path) |
|
|
|
cache_path = snapshot_download('damo/mplug_backbone_base_en') |
|
|
|
model = MPlugForAllTasks.from_pretrained( |
|
|
|
cache_path, task=Tasks.image_captioning) |
|
|
|
kwargs = dict( |
|
|
|
cfg_file=os.path.join(cache_path, ModelFile.CONFIGURATION), |
|
|
|
model=model, |
|
|
@@ -74,11 +75,12 @@ class TestFinetuneMPlug(unittest.TestCase): |
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
|
def test_trainer_with_vqa(self): |
|
|
|
kwargs = dict( |
|
|
|
model='damo/mplug_visual-question-answering_coco_large_en', |
|
|
|
model='damo/mplug_backbone_base_en', |
|
|
|
train_dataset=self.train_dataset, |
|
|
|
eval_dataset=self.test_dataset, |
|
|
|
max_epochs=self.max_epochs, |
|
|
|
work_dir=self.tmp_dir) |
|
|
|
work_dir=self.tmp_dir, |
|
|
|
task=Tasks.visual_question_answering) |
|
|
|
|
|
|
|
trainer: EpochBasedTrainer = build_trainer( |
|
|
|
name=Trainers.mplug, default_args=kwargs) |
|
|
@@ -88,7 +90,8 @@ class TestFinetuneMPlug(unittest.TestCase): |
|
|
|
def test_trainer_with_vqa_with_model_and_args(self): |
|
|
|
cache_path = snapshot_download( |
|
|
|
'damo/mplug_visual-question-answering_coco_large_en') |
|
|
|
model = MPlugForAllTasks.from_pretrained(cache_path) |
|
|
|
model = MPlugForAllTasks.from_pretrained( |
|
|
|
cache_path, task=Tasks.visual_question_answering) |
|
|
|
kwargs = dict( |
|
|
|
cfg_file=os.path.join(cache_path, ModelFile.CONFIGURATION), |
|
|
|
model=model, |
|
|
@@ -108,11 +111,12 @@ class TestFinetuneMPlug(unittest.TestCase): |
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
|
def test_trainer_with_retrieval(self): |
|
|
|
kwargs = dict( |
|
|
|
model='damo/mplug_image-text-retrieval_flickr30k_large_en', |
|
|
|
model='damo/mplug_backbone_base_en', |
|
|
|
train_dataset=self.train_dataset, |
|
|
|
eval_dataset=self.test_dataset, |
|
|
|
max_epochs=self.max_epochs, |
|
|
|
work_dir=self.tmp_dir) |
|
|
|
work_dir=self.tmp_dir, |
|
|
|
task=Tasks.image_text_retrieval) |
|
|
|
|
|
|
|
trainer: EpochBasedTrainer = build_trainer( |
|
|
|
name=Trainers.mplug, default_args=kwargs) |
|
|
@@ -120,9 +124,9 @@ class TestFinetuneMPlug(unittest.TestCase): |
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level') |
|
|
|
def test_trainer_with_retrieval_with_model_and_args(self): |
|
|
|
cache_path = snapshot_download( |
|
|
|
'damo/mplug_image-text-retrieval_flickr30k_large_en') |
|
|
|
model = MPlugForAllTasks.from_pretrained(cache_path) |
|
|
|
cache_path = snapshot_download('damo/mplug_backbone_base_en') |
|
|
|
model = MPlugForAllTasks.from_pretrained( |
|
|
|
cache_path, task=Tasks.image_text_retrieval) |
|
|
|
kwargs = dict( |
|
|
|
cfg_file=os.path.join(cache_path, ModelFile.CONFIGURATION), |
|
|
|
model=model, |
|
|
|