Internvideo2 Chat 8B InternLM2 5
模型概述
該模型採用漸進式學習方案,結合視頻BLIP和開源LLM,支持高清視頻輸入和長上下文處理,適用於視頻內容理解和對話任務。
模型特點
高清視頻處理
支持高清視頻輸入,通過特殊處理技術提升視頻內容理解質量
長上下文支持
基礎LLM支持100萬token的長上下文窗口,適合處理長視頻內容
漸進式學習
採用VideoChat中的漸進式學習方案,優化視頻編碼器與語言模型的交互
模型能力
視頻內容理解
視頻內容描述生成
視頻問答
視頻事件因果關係分析
視頻物體細節識別
使用案例
視頻內容分析
視頻內容描述
對視頻內容進行逐步描述,識別關鍵事件和物體
準確識別視頻中的動作序列和關鍵物體
視頻問答
回答關於視頻內容的特定問題
基於視頻內容提供準確的答案
人機交互
視頻對話系統
基於視頻內容與用戶進行自然語言交互
流暢的視頻相關對話體驗
🚀 InternVideo2-Chat-8B-InternLM2.5
本項目旨在進一步豐富 InternVideo2 嵌入的語義信息,並提升其在人機交互中的易用性。通過將 InternVideo2 與大語言模型(LLM)和視頻 BLIP 相結合,融入到一個視頻大語言模型(VideoLLM)中進行微調。採用 VideoChat 中的漸進式學習方案,以 InternVideo2 作為視頻編碼器,並訓練一個視頻 BLIP 用於與開源大語言模型進行交互。在訓練過程中,視頻編碼器會得到更新。詳細的訓練方法可參考 VideoChat。該模型經過高清訓練。
此模型的基礎大語言模型為 InternLM2.5-7B,具有 100 萬長上下文窗口。
✨ 主要特性
- 結合 InternVideo2、大語言模型和視頻 BLIP,豐富語義信息,提升人機交互易用性。
- 採用漸進式學習方案,訓練過程中更新視頻編碼器。
- 經過高清訓練,具有更好的性能。
📈 性能表現
模型 | 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])
# " " should be added in the start and end
msg = f"The video contains {len(frame_indices)} frames sampled at {sec} seconds."
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
# calculate the existing video 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
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)
# 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 frames
resized_frame = F.interpolate(
frames, size=(target_height, target_width),
mode='bicubic', align_corners=False
)
return resized_frame
video_path = "yoga.mp4"
# sample uniformly 8 frames from the video
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, '', 'Describe the video step by step',instruction= "Carefully watch the video and pay attention to the cause and sequence of events, the detail and movement of objects, and the action and pose of persons. Based on your observations, select the best option that accurately addresses the question.\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}
}
📄 許可證
本項目採用 MIT 許可證。
⚠️ 重要提示
你需同意不使用該模型進行對人類受試者造成傷害的實驗。
💡 使用建議
在使用模型時,請確保輸入的視頻格式和參數符合代碼要求,以獲得更好的效果。
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