模型介绍
内容详情
替代品
模型简介
该模型采用渐进式学习方案,结合视频BLIP和开源LLM,支持高清视频输入和长上下文处理,适用于视频内容理解和对话任务。
模型特点
高清视频处理
支持高清视频输入,通过特殊处理技术提升视频内容理解质量
长上下文支持
基础LLM支持100万token的长上下文窗口,适合处理长视频内容
渐进式学习
采用VideoChat中的渐进式学习方案,优化视频编码器与语言模型的交互
模型能力
视频内容理解
视频内容描述生成
视频问答
视频事件因果关系分析
视频物体细节识别
使用案例
视频内容分析
视频内容描述
对视频内容进行逐步描述,识别关键事件和物体
准确识别视频中的动作序列和关键物体
视频问答
回答关于视频内容的特定问题
基于视频内容提供准确的答案
人机交互
视频对话系统
基于视频内容与用户进行自然语言交互
流畅的视频相关对话体验
license: mit pipeline_tag: video-text-to-text extra_gated_prompt: >- 您同意不使用该模型进行对人类受试者造成伤害的实验。 extra_gated_fields: 姓名: text 公司/组织: text 国家: text 电子邮箱: text
InternVideo2-Chat-8B-InternLM2.5
为了进一步丰富InternVideo2中嵌入的语义并提升其在人机交互中的友好性,我们通过将InternVideo2整合到一个带有大型语言模型(LLM)和视频BLIP的VideoLLM中来进行调优。我们采用VideoChat中的渐进式学习方案,使用InternVideo2作为视频编码器,并训练一个视频BLIP来与开源LLM进行交互。在训练过程中,视频编码器会进行更新。详细的训练方法参见VideoChat。该模型经过高清训练。
该模型的基础LLM是InternLM2.5-7B,支持100万token的长上下文窗口。
📈 性能表现
模型 | MVBench | VideoMME(不含子项) |
---|---|---|
InternVideo2-Chat-8B | 60.3 | 41.9 |
InternVideo2-Chat-8B-HD | 65.4 | 46.1 |
InternVideo2-Chat-8B-HD-F16 | 67.5 | 49.4 |
InternVideo2-Chat-8B-InternLM | 61.9 | 49.1 |
🚀 如何使用该模型
- 确保安装
transformers >= 4.38.0, peft==0.5.0
从pip_requirements安装必要的Python包
- 使用视频输入进行推理
import os
import torch
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained('OpenGVLab/InternVideo2_Chat_8B_InternLM2_5',
trust_remote_code=True,
use_fast=False,)
if torch.cuda.is_available():
model = AutoModel.from_pretrained(
'OpenGVLab/InternVideo2_Chat_8B_InternLM2_5',
torch_dtype=torch.bfloat16,
trust_remote_code=True).cuda()
else:
model = AutoModel.from_pretrained(
'OpenGVLab/InternVideo2_Chat_8B_InternLM2_5',
torch_dtype=torch.bfloat16,
trust_remote_code=True)
from decord import VideoReader, cpu
from PIL import Image
import numpy as np
import numpy as np
import decord
from decord import VideoReader, cpu
import torch.nn.functional as F
import torchvision.transforms as T
from torchvision.transforms import PILToTensor
from torchvision import transforms
from torchvision.transforms.functional import InterpolationMode
decord.bridge.set_bridge("torch")
def get_index(num_frames, num_segments):
seg_size = float(num_frames - 1) / num_segments
start = int(seg_size / 2)
offsets = np.array([
start + int(np.round(seg_size * idx)) for idx in range(num_segments)
])
return offsets
def load_video(video_path, num_segments=8, return_msg=False, resolution=224, hd_num=4, padding=False):
vr = VideoReader(video_path, ctx=cpu(0), num_threads=1)
num_frames = len(vr)
frame_indices = get_index(num_frames, num_segments)
mean = (0.485, 0.456, 0.406)
std = (0.229, 0.224, 0.225)
transform = transforms.Compose([
transforms.Lambda(lambda x: x.float().div(255.0)),
transforms.Normalize(mean, std)
])
frames = vr.get_batch(frame_indices)
frames = frames.permute(0, 3, 1, 2)
if padding:
frames = HD_transform_padding(frames.float(), image_size=resolution, hd_num=hd_num)
else:
frames = HD_transform_no_padding(frames.float(), image_size=resolution, hd_num=hd_num)
frames = transform(frames)
# print(frames.shape)
T_, C, H, W = frames.shape
sub_img = frames.reshape(
1, T_, 3, H//resolution, resolution, W//resolution, resolution
).permute(0, 3, 5, 1, 2, 4, 6).reshape(-1, T_, 3, resolution, resolution).contiguous()
glb_img = F.interpolate(
frames.float(), size=(resolution, resolution), mode='bicubic', align_corners=False
).to(sub_img.dtype).unsqueeze(0)
frames = torch.cat([sub_img, glb_img]).unsqueeze(0)
if return_msg:
fps = float(vr.get_avg_fps())
sec = ", ".join([str(round(f / fps, 1)) for f in frame_indices])
# 开头和结尾需要添加空格
msg = f"视频包含{len(frame_indices)}帧,采样于{sec}秒。"
return frames, msg
else:
return frames
def HD_transform_padding(frames, image_size=224, hd_num=6):
def _padding_224(frames):
_, _, H, W = frames.shape
tar = int(np.ceil(H / 224) * 224)
top_padding = (tar - H) // 2
bottom_padding = tar - H - top_padding
left_padding = 0
right_padding = 0
padded_frames = F.pad(
frames,
pad=[left_padding, right_padding, top_padding, bottom_padding],
mode='constant', value=255
)
return padded_frames
_, _, H, W = frames.shape
trans = False
if W < H:
frames = frames.flip(-2, -1)
trans = True
width, height = H, W
else:
width, height = W, H
ratio = width / height
scale = 1
while scale * np.ceil(scale / ratio) <= hd_num:
scale += 1
scale -= 1
new_w = int(scale * image_size)
new_h = int(new_w / ratio)
resized_frames = F.interpolate(
frames, size=(new_h, new_w),
mode='bicubic',
align_corners=False
)
padded_frames = _padding_224(resized_frames)
if trans:
padded_frames = padded_frames.flip(-2, -1)
return padded_frames
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 HD_transform_no_padding(frames, image_size=224, hd_num=6, fix_ratio=(2,1)):
min_num = 1
max_num = hd_num
_, _, orig_height, orig_width = frames.shape
aspect_ratio = orig_width / orig_height
# 计算现有视频的宽高比
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])
# 找到最接近目标宽高比的比例
if fix_ratio:
target_aspect_ratio = fix_ratio
else:
target_aspect_ratio = find_closest_aspect_ratio(
aspect_ratio, target_ratios, orig_width, orig_height, image_size)
# 计算目标宽度和高度
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]
# 调整帧大小
resized_frame = F.interpolate(
frames, size=(target_height, target_width),
mode='bicubic', align_corners=False
)
return resized_frame
video_path = "yoga.mp4"
# 从视频中均匀采样8帧
video_tensor = load_video(video_path, num_segments=8, return_msg=False, resolution=224, hd_num=6)
video_tensor = video_tensor.to(model.device)
chat_history = []
response, chat_history = model.chat(tokenizer, '', '逐步描述视频内容',instruction= "仔细观察视频,注意事件的因果关系和顺序、物体的细节和运动,以及人物的动作和姿势。根据你的观察,选择最准确回答问题的选项。\n", media_type='video', media_tensor=video_tensor, chat_history= chat_history, return_history=True,generation_config={'do_sample':False,'max_new_tokens':512,})
print(response)
✏️ 引用
如果这项工作对您的研究有所帮助,请考虑引用InternVideo和VideoChat。
@article{wang2024internvideo2,
title={Internvideo2: Scaling video foundation models for multimodal video understanding},
author={Wang, Yi and Li, Kunchang and Li, Xinhao and Yu, Jiashuo and He, Yinan and Wang, Chenting and Chen, Guo and Pei, Baoqi and Zheng, Rongkun and Xu, Jilan and Wang, Zun and others},
journal={arXiv preprint arXiv:2403.15377},
year={2024}
}
@article{li2023videochat,
title={Videochat: Chat-centric video understanding},
author={Li, KunChang and He, Yinan and Wang, Yi and Li, Yizhuo and Wang, Wenhai and Luo, Ping and Wang, Yali and Wang, Limin and Qiao, Yu},
journal={arXiv preprint arXiv:2305.06355},
year={2023}
}
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
AIbase是一个专注于MCP服务的平台,为AI开发者提供高质量的模型上下文协议服务,助力AI应用开发。
简体中文