图像理解功能详解
核心特点
- 高分辨率支持:最高可处理4K分辨率图像
- 细节捕捉能力:能识别图像中的微小细节
- 多图分析比较:可同时处理多张图片并进行对比
操作步骤
- 准备图像文件:将需要分析的图片放入本地目录
- 加载模型和tokenizer
- 构建查询语句和图像路径
- 使用模型进行推理
- 获取并解析返回结果
示例代码:
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained('internlm/internlm-xcomposer2d5-7b', trust_remote_code=True).cuda().eval()
tokenizer = AutoTokenizer.from_pretrained('internlm/internlm-xcomposer2d5-7b', trust_remote_code=True)
query = "详细分析这张图片"
image = ['examples/dubai.png']
response, _ = model.chat(tokenizer, query, image, do_sample=False, num_beams=3)
print(response)
该功能适用于图像标注、内容审核、商品分析等多种应用场景。
本答案来源于文章《InternLM-XComposer:输出超长文本与图像视频理解的多模态大模型》