Internvideo2 5 Chat 8B
InternVideo2.5是一款基于长且丰富上下文(LRC)建模增强的视频多模态大语言模型,构建于InternVL2.5之上,通过提升感知细粒度细节和捕捉长时序结构的能力,显著改进了现有MLLM模型。
下载量 8,265
发布时间 : 1/22/2025
模型简介
InternVideo2.5是一款视频多模态大语言模型,通过直接偏好优化(TPO)进行密集视觉任务标注,以及通过自适应分层令牌压缩(HiCo)实现紧凑的时空表示,显著提升了感知细粒度细节和捕捉长时序结构的能力。
模型特点
长且丰富上下文(LRC)建模
通过增强感知细粒度细节和捕捉长时序结构的能力,显著改进现有MLLM模型
直接偏好优化(TPO)
通过密集视觉任务标注提升模型性能
自适应分层令牌压缩(HiCo)
实现紧凑的时空表示,提高处理效率
模型能力
视频内容理解
视频文本生成
多模态推理
长视频处理
使用案例
视频内容分析
视频内容描述
对视频内容进行详细描述
生成准确、详细的视频描述文本
视频问答
回答关于视频内容的问题
准确回答关于视频中人物、动作、场景等问题
长视频处理
长视频摘要
对长视频内容进行摘要
生成简洁的长视频内容摘要
🚀 📕InternVideo2.5⚡
InternVideo2.5是一个视频多模态大语言模型(MLLM,基于InternVL2.5构建),增强了长且丰富上下文(LRC)建模能力。它通过直接偏好优化(TPO)进行密集视觉任务标注,以及通过自适应分层令牌压缩(HiCo)实现紧凑的时空表示,显著提升了现有MLLM感知细粒度细节和捕捉长形式时间结构的能力。
🚀 快速开始
安装依赖
首先,你需要安装 flash attention2 和其他一些模块。我们在下面提供了一个简单的安装示例:
pip install transformers==4.40.1
pip install av
pip install imageio
pip install decord
pip install opencv-python
pip install flash-attn --no-build-isolation
使用模型
import numpy as np
import torch
import torchvision.transforms as T
from decord import VideoReader, cpu
from PIL import Image
from torchvision.transforms.functional import InterpolationMode
from transformers import AutoModel, AutoTokenizer
# model setting
model_path = 'OpenGVLab/InternVideo2_5_Chat_8B'
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModel.from_pretrained(model_path, trust_remote_code=True).half().cuda().to(torch.bfloat16)
IMAGENET_MEAN = (0.485, 0.456, 0.406)
IMAGENET_STD = (0.229, 0.224, 0.225)
def build_transform(input_size):
MEAN, STD = IMAGENET_MEAN, IMAGENET_STD
transform = T.Compose([T.Lambda(lambda img: img.convert("RGB") if img.mode != "RGB" else img), T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC), T.ToTensor(), T.Normalize(mean=MEAN, std=STD)])
return transform
def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
best_ratio_diff = float("inf")
best_ratio = (1, 1)
area = width * height
for ratio in target_ratios:
target_aspect_ratio = ratio[0] / ratio[1]
ratio_diff = abs(aspect_ratio - target_aspect_ratio)
if ratio_diff < best_ratio_diff:
best_ratio_diff = ratio_diff
best_ratio = ratio
elif ratio_diff == best_ratio_diff:
if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
best_ratio = ratio
return best_ratio
def dynamic_preprocess(image, min_num=1, max_num=6, image_size=448, use_thumbnail=False):
orig_width, orig_height = image.size
aspect_ratio = orig_width / orig_height
# calculate the existing image aspect ratio
target_ratios = set((i, j) for n in range(min_num, max_num + 1) for i in range(1, n + 1) for j in range(1, n + 1) if i * j <= max_num and i * j >= min_num)
target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])
# find the closest aspect ratio to the target
target_aspect_ratio = find_closest_aspect_ratio(aspect_ratio, target_ratios, orig_width, orig_height, image_size)
# calculate the target width and height
target_width = image_size * target_aspect_ratio[0]
target_height = image_size * target_aspect_ratio[1]
blocks = target_aspect_ratio[0] * target_aspect_ratio[1]
# resize the image
resized_img = image.resize((target_width, target_height))
processed_images = []
for i in range(blocks):
box = ((i % (target_width // image_size)) * image_size, (i // (target_width // image_size)) * image_size, ((i % (target_width // image_size)) + 1) * image_size, ((i // (target_width // image_size)) + 1) * image_size)
# split the image
split_img = resized_img.crop(box)
processed_images.append(split_img)
assert len(processed_images) == blocks
if use_thumbnail and len(processed_images) != 1:
thumbnail_img = image.resize((image_size, image_size))
processed_images.append(thumbnail_img)
return processed_images
def load_image(image, input_size=448, max_num=6):
transform = build_transform(input_size=input_size)
images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
pixel_values = [transform(image) for image in images]
pixel_values = torch.stack(pixel_values)
return pixel_values
def get_index(bound, fps, max_frame, first_idx=0, num_segments=32):
if bound:
start, end = bound[0], bound[1]
else:
start, end = -100000, 100000
start_idx = max(first_idx, round(start * fps))
end_idx = min(round(end * fps), max_frame)
seg_size = float(end_idx - start_idx) / num_segments
frame_indices = np.array([int(start_idx + (seg_size / 2) + np.round(seg_size * idx)) for idx in range(num_segments)])
return frame_indices
def get_num_frames_by_duration(duration):
local_num_frames = 4
num_segments = int(duration // local_num_frames)
if num_segments == 0:
num_frames = local_num_frames
else:
num_frames = local_num_frames * num_segments
num_frames = min(512, num_frames)
num_frames = max(128, num_frames)
return num_frames
def load_video(video_path, bound=None, input_size=448, max_num=1, num_segments=32, get_frame_by_duration = False):
vr = VideoReader(video_path, ctx=cpu(0), num_threads=1)
max_frame = len(vr) - 1
fps = float(vr.get_avg_fps())
pixel_values_list, num_patches_list = [], []
transform = build_transform(input_size=input_size)
if get_frame_by_duration:
duration = max_frame / fps
num_segments = get_num_frames_by_duration(duration)
frame_indices = get_index(bound, fps, max_frame, first_idx=0, num_segments=num_segments)
for frame_index in frame_indices:
img = Image.fromarray(vr[frame_index].asnumpy()).convert("RGB")
img = dynamic_preprocess(img, image_size=input_size, use_thumbnail=True, max_num=max_num)
pixel_values = [transform(tile) for tile in img]
pixel_values = torch.stack(pixel_values)
num_patches_list.append(pixel_values.shape[0])
pixel_values_list.append(pixel_values)
pixel_values = torch.cat(pixel_values_list)
return pixel_values, num_patches_list
# evaluation setting
max_num_frames = 512
generation_config = dict(
do_sample=False,
temperature=0.0,
max_new_tokens=1024,
top_p=0.1,
num_beams=1
)
video_path = "your_video.mp4"
num_segments=128
with torch.no_grad():
pixel_values, num_patches_list = load_video(video_path, num_segments=num_segments, max_num=1, get_frame_by_duration=False)
pixel_values = pixel_values.to(torch.bfloat16).to(model.device)
video_prefix = "".join([f"Frame{i+1}: <image>\n" for i in range(len(num_patches_list))])
# single-turn conversation
question1 = "Describe this video in detail."
question = video_prefix + question1
output1, chat_history = model.chat(tokenizer, pixel_values, question, generation_config, num_patches_list=num_patches_list, history=None, return_history=True)
print(output1)
# multi-turn conversation
question2 = "How many people appear in the video?"
output2, chat_history = model.chat(tokenizer, pixel_values, question, generation_config, num_patches_list=num_patches_list, history=chat_history, return_history=True)
print(output2)
✨ 主要特性
InternVideo2.5基于InternVL2.5构建,增强了长且丰富上下文(LRC)建模能力,能显著提升感知细粒度细节和捕捉长形式时间结构的能力。通过直接偏好优化(TPO)进行密集视觉任务标注,以及自适应分层令牌压缩(HiCo)实现紧凑的时空表示。
📦 安装指南
你需要安装 flash attention2 和其他一些模块,安装示例如下:
pip install transformers==4.40.1
pip install av
pip install imageio
pip install decord
pip install opencv-python
pip install flash-attn --no-build-isolation
💻 使用示例
基础用法
上述代码展示了如何安装依赖和使用InternVideo2.5模型进行视频处理和对话。包括加载视频、处理像素值、进行单轮和多轮对话等操作。
📈 性能表现
模型 | MVBench | LongVideoBench | VideoMME(w/o sub) |
---|---|---|---|
InternVideo2.5 | 75.7 | 60.6 | 65.1 |
📚 详细文档
✏️ 引用
@article{wang2025internvideo,
title={InternVideo2.5: Empowering Video MLLMs with Long and Rich Context Modeling},
author={Wang, Yi and Li, Xinhao and Yan, Ziang and He, Yinan and Yu, Jiashuo and Zeng, Xiangyu and Wang, Chenting and Ma, Changlian and Huang, Haian and Gao, Jianfei and Dou, Min and Chen, Kai and Wang, Wenhai and Qiao, Yu and Wang, Yali and Wang, Limin},
journal={arXiv preprint arXiv:2501.12386},
year={2025}
}
📄 许可证
本项目采用Apache-2.0许可证。
Llava Video 7B Qwen2
Apache-2.0
LLaVA-视频模型是基于Qwen2语言模型的7B参数多模态模型,专注于视频理解任务,支持64帧视频输入。
视频生成文本
Transformers 英语

L
lmms-lab
34.28k
91
Llava NeXT Video 7B DPO Hf
LLaVA-NeXT-Video是一个开源多模态聊天机器人,通过视频和图像数据混合训练优化,具备优秀的视频理解能力。
视频生成文本
Transformers 英语

L
llava-hf
12.61k
9
Internvideo2 5 Chat 8B
Apache-2.0
InternVideo2.5是一款基于长且丰富上下文(LRC)建模增强的视频多模态大语言模型,构建于InternVL2.5之上,通过提升感知细粒度细节和捕捉长时序结构的能力,显著改进了现有MLLM模型。
视频生成文本
Transformers 英语

I
OpenGVLab
8,265
60
Cogvlm2 Llama3 Caption
其他
CogVLM2-Caption是一个视频描述生成模型,用于为CogVideoX模型生成训练数据。
视频生成文本
Transformers 英语

C
THUDM
7,493
95
Spacetimegpt
时空GPT是一个能够进行空间和时间推理的视频描述生成模型,能够分析视频帧并生成描述视频事件的句子。
视频生成文本
Transformers 英语

S
Neleac
2,877
33
Video R1 7B
Apache-2.0
Video-R1-7B是基于Qwen2.5-VL-7B-Instruct优化的多模态大语言模型,专注于视频推理任务,能够理解视频内容并回答相关问题。
视频生成文本
Transformers 英语

V
Video-R1
2,129
9
Internvl 2 5 HiCo R16
Apache-2.0
InternVideo2.5 是一个基于 InternVL2.5 构建的视频多模态大语言模型(MLLM),通过长且丰富的上下文(LRC)建模进行了增强,能够感知细粒度细节并捕捉长时态结构。
视频生成文本
Transformers 英语

I
OpenGVLab
1,914
3
Videollm Online 8b V1plus
MIT
VideoLLM-online是一个基于Llama-3-8B-Instruct的多模态大语言模型,专注于在线视频理解和视频-文本生成任务。
视频生成文本
Safetensors 英语
V
chenjoya
1,688
23
Videochat R1 7B
Apache-2.0
VideoChat-R1_7B 是一个基于 Qwen2.5-VL-7B-Instruct 的多模态视频理解模型,能够处理视频和文本输入,生成文本输出。
视频生成文本
Transformers 英语

V
OpenGVLab
1,686
7
Qwen2.5 Vl 7b Cam Motion Preview
其他
基于Qwen2.5-VL-7B-Instruct微调的摄像机运动分析模型,专注于视频中的摄像机运动分类和视频-文本检索任务
视频生成文本
Transformers

Q
chancharikm
1,456
10
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98