🚀 InternVideo2-Chat-8B
このモデルは、InternVideo2に埋め込まれたセマンティクスをさらに豊かにし、人間とのコミュニケーションにおける使いやすさを向上させるために開発されました。InternVideo2をVideoLLMに組み込み、LLMとビデオBLIPを用いて調整しています。VideoChatの段階的学習スキームを採用し、InternVideo2をビデオエンコーダーとして使用し、オープンソースのLLMと通信するためのビデオブリップをトレーニングします。トレーニング中にはビデオエンコーダーも更新されます。詳細なトレーニング方法はVideoChatに記載されています。
このモデルのBaseLLMはMistral-7Bです。使用する前に、Mistral-7Bのアクセス許可を取得していることを確認してください。まだ取得していない場合は、Mistral-7Bにアクセスして許可を取得し、HF_token
を環境変数に追加してください。
[📂 GitHub] [📜 Tech Report] [🗨️ Chat Demo]
🚀 クイックスタート
モデルの使用方法
- このプロジェクトとBaseLLMのアクセス許可を申請します。
- HFユーザーアクセストークンを環境変数に設定します。
export HF_TOKEN=hf_....
"hf_"で始まるトークンの取得方法がわからない場合は、How to Get HF User access Tokenを参照してください。
3. transformers >= 4.39.0
と peft==0.5.0
がインストールされていることを確認します。
pip install transformers==4.39.1
pip install peft==0.5.0
pip install timm easydict einops
pip_requirements から必要なPythonパッケージをインストールします。
4. ビデオ入力で推論を行います。
import os
token = os.environ['HF_TOKEN']
import torch
tokenizer = AutoTokenizer.from_pretrained('OpenGVLab/InternVideo2-Chat-8B', trust_remote_code=True, use_fast=False)
from transformers import AutoTokenizer, AutoModel
model = AutoModel.from_pretrained(
'OpenGVLab/InternVideo2-Chat-8B',
torch_dtype=torch.bfloat16,
trust_remote_code=True).cuda()
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.Resize(224, interpolation=transforms.InterpolationMode.BICUBIC),
transforms.CenterCrop(224),
transforms.Normalize(mean, std)
])
frames = vr.get_batch(frame_indices)
frames = frames.permute(0, 3, 1, 2)
frames = transform(frames)
T_, C, H, W = frames.shape
if return_msg:
fps = float(vr.get_avg_fps())
sec = ", ".join([str(round(f / fps, 1)) for f in frame_indices])
msg = f"The video contains {len(frame_indices)} frames sampled at {sec} seconds."
return frames, msg
else:
return frames
video_path = "yoga.mp4"
video_tensor = load_video(video_path, num_segments=8, return_msg=False)
video_tensor = video_tensor.to(model.device)
chat_history= []
response, chat_history = model.chat(tokenizer, '', 'describe the action step by step.', media_type='video', media_tensor=video_tensor, chat_history= chat_history, return_history=True,generation_config={'do_sample':False})
print(response)
response, chat_history = model.chat(tokenizer, '', 'What is she wearing?', media_type='video', media_tensor=video_tensor, chat_history= chat_history, return_history=True,generation_config={'do_sample':False})
print(response)
✨ 主な機能
このモデルは、InternVideo2をベースに構築され、ビデオとの対話型理解を強化しています。ビデオに対する自然言語の質問に回答することができ、ビデオの内容を説明することも可能です。
📦 インストール
上記の「クイックスタート」セクションで説明した手順に従って、必要なパッケージをインストールしてください。
💻 使用例
基本的な使用法
上記の「クイックスタート」セクションのコードを参照してください。このコードでは、ビデオを入力として与え、モデルにビデオの内容を説明させたり、ビデオ内の人物が何を着ているかを尋ねたりすることができます。
📈 性能
✏️ 引用
この研究があなたの研究に役立った場合は、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ライセンスの下で公開されています。
⚠️ 重要提示
このモデルを使用して、人間の被験者に危害を与える実験を行わないことに同意する必要があります。
💡 使用建议
モデルを使用する前に、必ずBaseLLMのアクセス許可を取得し、環境変数にHF_token
を設定してください。