DocOwl2
Go to file
xxl 707e9fd50f first commit 2024-12-26 10:13:27 +08:00
examples first commit 2024-12-26 10:13:27 +08:00
.gitattributes Add .gitattributes 2024-12-26 09:22:53 +08:00
README.md first commit 2024-12-26 10:13:27 +08:00
config.json first commit 2024-12-26 10:13:27 +08:00
configuration.json first commit 2024-12-26 10:13:27 +08:00
configuration_mplug_docowl.py first commit 2024-12-26 10:13:27 +08:00
constants.py first commit 2024-12-26 10:13:27 +08:00
generation_config.json first commit 2024-12-26 10:13:27 +08:00
model.safetensors first commit 2024-12-26 10:13:27 +08:00
modeling_llama2_mam.py first commit 2024-12-26 10:13:27 +08:00
modeling_mplug_docowl.py first commit 2024-12-26 10:13:27 +08:00
preprocessor_config.json first commit 2024-12-26 10:13:27 +08:00
processor.py first commit 2024-12-26 10:13:27 +08:00
special_tokens_map.json first commit 2024-12-26 10:13:27 +08:00
tokenizer.model first commit 2024-12-26 10:13:27 +08:00
tokenizer_config.json first commit 2024-12-26 10:13:27 +08:00
visual_compressor.py first commit 2024-12-26 10:13:27 +08:00
visual_encoder.py first commit 2024-12-26 10:13:27 +08:00

README.md

frameworks license tasks
Pytorch
Apache License 2.0
document-understanding

mPLUG-DocOwl2

Introduction

mPLUG-DocOwl2 is a state-of-the-art Multimodal LLM for OCR-free Multi-page Document Understanding.

Through a compressing module named High-resolution DocCompressor, each page is encoded with just 324 tokens.

Github: mPLUG-DocOwl

SDK下载

#安装ModelScope
pip install modelscope
#SDK模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('iic/DocOwl2')

Git下载

#Git模型下载
git clone https://www.modelscope.cn/iic/DocOwl2.git

Quickstart

import torch
import os
from modelscope import AutoTokenizer, AutoModel
from icecream import ic
import time
class DocOwlInfer():
    def __init__(self, ckpt_path):
        self.tokenizer = AutoTokenizer.from_pretrained(ckpt_path, use_fast=False)
        self.model = AutoModel.from_pretrained(ckpt_path, trust_remote_code=True, low_cpu_mem_usage=True, torch_dtype=torch.float16, device_map='auto')
        self.model.init_processor(tokenizer=self.tokenizer, basic_image_size=504, crop_anchors='grid_12')
        
    def inference(self, images, query):
        messages = [{'role': 'USER', 'content': '<|image|>'*len(images)+query}]
        answer = self.model.chat(messages=messages, images=images, tokenizer=self.tokenizer)
        return answer
docowl = DocOwlInfer(ckpt_path='$your_model_local_dir')
images = [
        '$your_model_local_dir'+'/examples/docowl2_page0.png',
        '$your_model_local_dir'+'/examples/docowl2_page1.png',
        '$your_model_local_dir'+'/examples/docowl2_page2.png',
        '$your_model_local_dir'+'/examples/docowl2_page3.png',
        '$your_model_local_dir'+'/examples/docowl2_page4.png',
        '$your_model_local_dir'+'/examples/docowl2_page5.png',
    ]
answer = docowl.inference(images, query='what is this paper about? provide detailed information.')
answer = docowl.inference(images, query='what is the third page about? provide detailed information.')