
InternVL
开源接近GPT-4o的多模态对话模型,图像理解与对话一步到位。
项目预览
项目数据
项目介绍
Star 增长趋势
本站每日记录该项目 GitHub 星标变化,观测越久曲线越完整
数据来源:GitHub API 逐日快照 · 收录于 2026-08-09 · 当前星标 ★ 10167
使用教程
ℹ 本教程由 AI 依据该项目 README 整理,个别步骤可能需要按你的环境微调。
环境要求
- Python 环境(README 示例为 Python 代码)
- 已安装 PyTorch(torch)与 transformers(PyTorch 版)
- 已安装 Pillow(PIL)用于读取图片
- NVIDIA GPU + CUDA 环境(示例代码使用 .cuda() 与 bfloat16)
- 可访问 HuggingFace 下载 OpenGVLab 系列权重
安装与启动步骤
-
1准备运行环境
README 未给出安装命令,需自备 Python 与 NVIDIA GPU/CUDA;示例全程使用 .cuda() 和 bfloat16,纯 CPU 或显卡不支持 bf16 时无法直接跑通。
-
2安装依赖库
示例依赖 torch、transformers 与 Pillow,请按其官方文档自行安装对应 CUDA 版本;README 未提供 pip 安装命令,此处不代填。
-
3准备示例图片
在代码所在目录创建 examples/ 目录并放入 image1.jpg;跨模态检索示例还需要 image2.jpg、image3.jpg,缺文件会直接报错。
-
4提取视觉特征
用 InternViT-6B 对单张图片提取视觉特征。注意 README 中 image_processor 用的是 V1-5,模型用的是 V2_5,请照原文填写。
import torch from PIL import Image from transformers import AutoModel, CLIPImageProcessor model = AutoModel.from_pretrained( 'OpenGVLab/InternViT-6B-448px-V2_5', torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, trust_remote_code=True).cuda().eval() image = Image.open('./examples/image1.jpg').convert('RGB') image_processor = CLIPImageProcessor.from_pretrained('OpenGVLab/InternViT-6B-448px-V1-5') pixel_values = image_processor(images=image, return_tensors='pt').pixel_values pixel_values = pixel_values.to(torch.bfloat16).cuda() outputs = model(pixel_values) -
5跨模态检索编码
用 InternVL-14B 分别编码三张图片与中英日三条文本,做图文检索。README 节选在此处被截断,后续计算相似度的代码请对照原文补全。
import torch from PIL import Image from transformers import AutoModel, CLIPImageProcessor from transformers import AutoTokenizer model = AutoModel.from_pretrained( 'OpenGVLab/InternVL-14B-224px', torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, trust_remote_code=True).cuda().eval() image_processor = CLIPImageProcessor.from_pretrained('OpenGVLab/InternVL-14B-224px') tokenizer = AutoTokenizer.from_pretrained( 'OpenGVLab/InternVL-14B-224px', use_fast=False, add_eos_token=True) tokenizer.pad_token_id = 0 images = [ Image.open('./examples/image1.jpg').convert('RGB'), Image.open('./examples/image2.jpg').convert('RGB'), Image.open('./examples/image3.jpg').convert('RGB') ] prefix = 'summarize:' texts = [ prefix + 'a photo of a red panda', prefix + '一张熊猫的照片', prefix + '二匹の猫の写真' ] pixel_values = image_processor(images=images, return_tensors='pt').pixel_values pixel_values = pixel_values.to(torch.bfloat16).cuda() input_ids = tokenizer(texts, return_tensors='pt', max_length=80, truncation=True, padding='max_length').input_ids.cuda()
关键配置
| 配置项 | 必填 | 说明 | 示例 |
|---|---|---|---|
model(from_pretrained 的模型 ID) | 是 | 指定从 HuggingFace 加载的权重仓库 | OpenGVLab/InternViT-6B-448px-V2_5 |
image_processor 模型 ID | 是 | 图像预处理器的来源仓库,需与模型匹配 | OpenGVLab/InternViT-6B-448px-V1-5 |
torch_dtype | 否 | 权重加载精度,示例统一使用 bfloat16 | torch.bfloat16 |
trust_remote_code | 是 | 允许执行模型仓库自带的自定义代码 | True |
tokenizer.pad_token_id | 否 | 检索示例中把填充 token 设为 0 | 0 |
max_length | 否 | 文本 tokenize 时的最大长度,示例为 80 | 80 |
如何确认成功
脚本无报错跑完,拿到 outputs/pixel_values/input_ids 等张量,即说明模型加载与推理正常;本质检只在代码层面验证,README 未给出服务端口或界面。
常见问题
Q:需要多大显存才能跑?
A:README 未给出显存要求。示例用 InternViT-6B 和 InternVL-14B 级别的权重并以 bfloat16 加载,参数量较大,建议使用大显存 NVIDIA 显卡,显存不足可改用更小的模型版本。
Q:提示 examples/image1.jpg 不存在怎么办?
A:说明缺少示例图片。README 未提供图片下载方式,请自备图片并放到运行目录下的 examples/ 目录,文件名为 image1.jpg(检索示例还需 image2.jpg、image3.jpg)。
Q:为什么 image_processor 和模型 ID 版本号不一致?
A:这是 README 原文写法(模型为 InternViT-6B-448px-V2_5,处理器为 V1-5)。请先照原文填写,若加载报错可再对照项目文档确认匹配关系。
Q:没有 GPU 能运行吗?
A:示例代码显式调用了 .cuda() 并转成 bfloat16,需要 CUDA 环境;README 未提供 CPU 运行示例,纯 CPU 环境需自行改造代码,未见官方说明。
注意事项
- README 节选中只给出了 HuggingFace 上的 Python 调用示例,没有 pip 安装命令、也没给 git clone 步骤,相关命令请以项目官方文档为准。
- 代码依赖 CUDA 与 bfloat16 支持,纯 CPU 或老显卡可能无法直接运行。
- 首次运行会从 HuggingFace 下载数 GB 级权重,注意网络与磁盘空间;README 未说明是否需要登录或配置镜像。
- README 中的跨模态检索示例在节选里被截断,缺少后续相似度计算部分,请对照原文补全后再运行。
核心亮点
- 性能接近 GPT-4o,在多项视觉-语言基准上领先开源同类模型
- 提供多种模型规模,从 1B 到 40B+,适配不同硬件场景
- 支持高分辨率图像输入,细节理解能力强,适合文档、图表等场景
不足之处
- 模型参数量大,推理资源需求高,普通开发者难以本地部署
- 文档和社区支持尚在完善,中文资料相对较少
适用场景
- 企业级多模态内容审核与理解
- 智能客服中的图像与文档问答
- 学术研究中的视觉-语言模型对比与二次开发
替代项目
LLaVA、Qwen-VL、CogVLM
同类项目推荐
z80ai
开源
让8位老电脑跑起AI聊天,复古硬件也能玩转大模型
Z80-μLM is a 2-bit quantized language model small enough to run on an 8-bit Z80 pro···
Nitro-1
开源
一步生成高清图,让扩散模型快如闪电
This repo provides a working re-implementation of Latent Adversarial Diffusion Disti···
open_clip
开源
开源复现 CLIP,训练微调零样本多模态模型
An open source implementation of CLIP.
DOFA
开源
一个模型看懂多种卫星数据,跨模态遥感分析不再难
Code for Neural Plasticity-Inspired Foundation Model for Observing the Earth Crossin···
SwiftDiffusion
开源
在苹果设备上原生运行 Stable Diffusion,打造本地 AI 画图应用
Stable Diffusion implementation using CoreML, PyTorch and SwiftUI
BlossomLM
开源
开源对话模型+训练数据,一键复现你的专属AI助手
A powerful, open-source large language model, including the training data.
llm.pdf
开源
打开 PDF 就能和 AI 聊天,不用装任何环境
Run LLMs inside a PDF file.
TabPFN
开源
几行代码搞定表格数据预测,小样本也能媲美调优后的 XGBoost。
⚡ TabPFN: Foundation Model for Tabular Data ⚡
recurrent-interface-network-pyto···
开源
单模型搞定图像视频生成,告别级联网络
Implementation of Recurrent Interface Network (RIN), for highly efficient generation···