论文 | 详细描述 | 模型权重 | 模型权重(wise model)
Monkey 提出了一种训练高效的方法,无需从头预训练即可将输入分辨率能力有效提升至 896 x 1344 像素。为了弥合简单文本标签与高输入分辨率之间的差距,我们提出了一种多级描述生成方法,该方法能自动提供丰富信息,引导模型学习场景与物体间的上下文关联。通过这两种设计的协同作用,我们的模型在多个基准测试中取得了优异成绩。将我们的模型与包括 GPT4V 在内的多种大型多模态模型(LMM)进行对比,结果表明,我们的模型通过关注文本信息并捕捉图像中的细微细节,在图像描述任务中展现出良好性能;其提升的输入分辨率也使其在含密集文本的文档图像上表现卓越。
conda create -n monkey python=3.9
conda activate monkey
git clone https://github.com/Yuliang-Liu/Monkey.git
cd ./Monkey
pip install -r requirements.txt在2023年11月14日之前,我们观察到对于某些随机图片,Monkey 能够取得比 GPT4V 更准确的结果。
我们还提供了原始演示的源代码和模型权重,允许您自定义某些参数以获得更独特的体验。具体操作如下:
demo.py 文件中的 DEFAULT_CKPT_PATH="pathto/Monkey" 为您的模型权重路径。python demo.pypython demo.py -c echo840/Monkey我们开源了通过多级描述生成方法生成的数据。您可以在Detailed Caption下载。
我们在 evaluate_vqa.py 文件中提供了针对14个视觉问答(VQA)数据集的评估代码,方便快速验证结果。具体操作如下:
sys.path.append("pathto/Monkey") 为您的模型权重路径。以 ESTVQA 为例:
├── data
| ├── estvqa
| ├── test_image
| ├── {image_path0}
| ├── {image_path1}
| ·
| ·
| ├── estvqa.jsonl.jsonl 文件每行格式示例:{"image": "data/estvqa/test_image/011364.jpg", "question": "What is this store?", "answer": "pizzeria", "question_id": 0}ds_collections:ds_collections = {
'estvqa_test': {
'test': 'data/estvqa/estvqa.jsonl',
'metric': 'anls',
'max_new_tokens': 100,
},
...
}bash eval/eval.sh 'EVAL_PTH' 'SAVE_NAME'我们还提供了Monkey的模型定义和训练代码,您可以在上方进行查看。您可以通过执行finetune_ds_debug.sh来运行训练代码。
注意: 请指定您的训练数据路径,该数据应为一个包含对话列表的json文件。
from transformers import AutoModelForCausalLM, AutoTokenizer
checkpoint = "echo840/Monkey"
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map='cuda', trust_remote_code=True).eval()
tokenizer = AutoTokenizer.from_pretrained(checkpoint, trust_remote_code=True)
tokenizer.padding_side = 'left'
tokenizer.pad_token_id = tokenizer.eod_id
img_path = ""
question = ""
query = f'<img>{img_path}</img> {question} Answer: ' #VQA
# query = f'<img>{img_path}</img> Generate the detailed caption in English: ' #detailed caption
input_ids = tokenizer(query, return_tensors='pt', padding='longest')
attention_mask = input_ids.attention_mask
input_ids = input_ids.input_ids
pred = model.generate(
input_ids=input_ids.cuda(),
attention_mask=attention_mask.cuda(),
do_sample=False,
num_beams=1,
max_new_tokens=512,
min_new_tokens=1,
length_penalty=1,
num_return_sequences=1,
output_hidden_states=True,
use_cache=True,
pad_token_id=tokenizer.eod_id,
eos_token_id=tokenizer.eod_id,
)
response = tokenizer.decode(pred[0][input_ids.size(1):].cpu(), skip_special_tokens=True).strip()
print(response)如果您希望引用此处发布的基准测试结果,请使用以下 BibTeX 条目:
@article{li2023monkey,
title={Monkey: Image Resolution and Text Label Are Important Things for Large Multi-modal Models},
author={Li, Zhang and Yang, Biao and Liu, Qiang and Ma, Zhiyin and Zhang, Shuo and Yang, Jingxu and Sun, Yabo and Liu, Yuliang and Bai, Xiang},
journal={arXiv preprint arXiv:2311.06607},
year={2023}
}如果你觉得Monkey很可爱,请为它点亮星标。这对我们来说将是莫大的鼓励。
Qwen-VL:我们基于此代码库进行开发。感谢Qwen的作者们提供了该框架。
我们欢迎各位提出宝贵建议,帮助我们改进Monkey。如有任何疑问,请联系刘育梁博士:ylliu@hust.edu.cn。如果您有任何有趣的发现,也欢迎通过邮件或提交issue与我们分享。谢谢!