Internvl 2 5 HiCo R16
InternVideo2.5 是一個基於 InternVL2.5 構建的視頻多模態大語言模型(MLLM),通過長且豐富的上下文(LRC)建模進行了增強,能夠感知細粒度細節並捕捉長時態結構。
下載量 1,914
發布時間 : 1/23/2025
模型概述
InternVideo2.5 是一個視頻多模態大語言模型,通過直接偏好優化(TPO)進行密集視覺任務標註,以及通過自適應分層令牌壓縮(HiCo)實現緊湊的時空表示,顯著提升了現有 MLLM 的能力。
模型特點
長且豐富的上下文(LRC)建模
通過 LRC 建模增強,能夠感知細粒度細節並捕捉長時態結構。
自適應分層令牌壓縮(HiCo)
實現緊湊的時空表示,提升模型效率。
直接偏好優化(TPO)
通過密集視覺任務標註優化模型性能。
模型能力
視頻理解
多模態推理
長視頻分析
細粒度細節感知
使用案例
視頻分析
視頻內容描述
詳細描述視頻內容,包括場景、人物和動作。
高準確率的視頻內容理解
長視頻結構分析
捕捉長視頻中的時態結構和關鍵事件。
59.6 的準確率(LongVideoBench)
多模態任務
多模態推理
結合視頻和文本信息進行復雜推理。
74.0 的準確率(MVBench)
🚀 📕InternVL2.5_HiCo_R16⚡
InternVL2.5_HiCo_R16 是基於 InternVideo2.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
使用模型
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/InternVL_2_5_HiCo_R16'
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModel.from_pretrained(model_path, trust_remote_code=True).half().cuda()
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 構建,增強了長而豐富上下文(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
💻 使用示例
基礎用法
# 上述使用模型部分的代碼即為基礎用法示例
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
# 後續代碼保持不變
高級用法
文檔中未明確提及高級用法相關代碼,若有高級場景需求,可根據模型特性和基礎用法進行拓展。
📈 性能表現
模型 | MVBench | LongVideoBench | VideoMME(無字幕) |
---|---|---|---|
InternVL2.5_HiCo_R16 | 74.0 | 59.6 | 64.9 |
📚 詳細文檔
✏️ 引用信息
@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}
}
@article{li2024videochatflash,
title={VideoChat-Flash: Hierarchical Compression for Long-Context Video Modeling},
author={Li, Xinhao and Wang, Yi and Yu, Jiashuo and Zeng, Xiangyu and Zhu, Yuhan and Huang, Haian and Gao, Jianfei and Li, Kunchang and He, Yinan and Wang, Chenting and others},
journal={arXiv preprint arXiv:2501.00574},
year={2024}
}
📄 許可證
本項目採用 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