MCPcopy Index your code
hub / github.com/modelscope/modelscope / __init__

Method __init__

modelscope/preprocessors/multi_modal.py:449–490  ·  view source on GitHub ↗

Preprocess data for the model `VLDocForDocVLEmbedding`. Args: model_dir (str): model path in model hub. mode (str): model mode, in ('train', 'eval', 'inference').

(self,
                 model_dir: str,
                 mode: str = ModeKeys.INFERENCE,
                 *args,
                 **kwargs)

Source from the content-addressed store, hash-verified

447class VLDocPreprocessor(Preprocessor):
448
449 def __init__(self,
450 model_dir: str,
451 mode: str = ModeKeys.INFERENCE,
452 *args,
453 **kwargs):
454 """Preprocess data for the model `VLDocForDocVLEmbedding`.
455
456 Args:
457 model_dir (str): model path in model hub.
458 mode (str): model mode, in ('train', 'eval', 'inference').
459 """
460 super().__init__(*args, **kwargs)
461
462 self.model_dir = model_dir
463 self.mode = mode
464
465 model_cfg_path = osp.join(model_dir, 'config.json')
466 with open(model_cfg_path, 'r', encoding='utf-8') as f:
467 model_cfg = json.load(f)
468
469 from modelscope.models.multi_modal.vldoc.tokenization import VLDocXLMTokenizer
470 tokenizer_path = osp.join(model_dir, ModelFile.TOKENIZER_FOLDER)
471 self.tokenizer = VLDocXLMTokenizer.from_pretrained(tokenizer_path)
472
473 from modelscope.models.multi_modal.vldoc.processing import Processor, ImageProcessor
474 self.img_proc = ImageProcessor(
475 do_preprocess=True,
476 do_resize=True,
477 image_size={
478 'height': model_cfg['image_size'][0],
479 'width': model_cfg['image_size'][1],
480 },
481 do_normalize=True,
482 apply_ocr=False)
483 self.proc = Processor(
484 max_seq_length=model_cfg['max_seq_length'],
485 max_block_num=model_cfg['max_block_num'],
486 img_processor=self.img_proc,
487 tokenizer=self.tokenizer,
488 width=model_cfg['image_size'][1],
489 height=model_cfg['image_size'][0],
490 )
491
492 def __call__(self, input: Dict[str, Any], *args,
493 **kwargs) -> Dict[str, Any]:

Callers

nothing calls this directly

Calls 5

ImageProcessorClass · 0.90
ProcessorClass · 0.90
__init__Method · 0.45
loadMethod · 0.45
from_pretrainedMethod · 0.45

Tested by

no test coverage detected