Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,109 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- video
|
| 7 |
+
- audio
|
| 8 |
+
- language
|
| 9 |
+
- multimodal
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# LongVU
|
| 13 |
+
|
| 14 |
+
This repository contains the model weight of TDC-Qwen2-7B as presented in [Multimodal Long Video Modeling Based on Temporal Dynamic Context](https://arxiv.org/abs/2504.10443).
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Use
|
| 18 |
+
|
| 19 |
+
We provide the simple inference code for using our model. For more details, you could refer to [Github](https://github.com/Hoar012/TDC-Video)
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
import numpy as np
|
| 23 |
+
import torch
|
| 24 |
+
from tdc.builder import load_pretrained_model
|
| 25 |
+
from tdc.constants import (
|
| 26 |
+
DEFAULT_IMAGE_TOKEN,
|
| 27 |
+
IMAGE_TOKEN_INDEX,
|
| 28 |
+
)
|
| 29 |
+
from tdc.conversation import conv_templates, SeparatorStyle
|
| 30 |
+
from tdc.mm_datautils import (
|
| 31 |
+
KeywordsStoppingCriteria,
|
| 32 |
+
process_images,
|
| 33 |
+
tokenizer_image_token,
|
| 34 |
+
)
|
| 35 |
+
from decord import cpu, VideoReader
|
| 36 |
+
from utils.processor import Processor
|
| 37 |
+
|
| 38 |
+
tokenizer, model, image_processor, context_len = load_pretrained_model(
|
| 39 |
+
"checkpoints/TDC-Qwen2-7B", None, "cambrian_qwen",
|
| 40 |
+
)
|
| 41 |
+
audio_processor = Processor("checkpoints/audio_encoder/whisper-large-v3")
|
| 42 |
+
|
| 43 |
+
model.eval()
|
| 44 |
+
model.cuda()
|
| 45 |
+
video_path = "./examples/video1.mp4"
|
| 46 |
+
audio_path = "./examples/audio1.wav"
|
| 47 |
+
instruction = qs = "Describe this video in detail, what can you see and hear?"
|
| 48 |
+
|
| 49 |
+
vr = VideoReader(video_path, ctx=cpu(0), num_threads=1)
|
| 50 |
+
fps = float(vr.get_avg_fps())
|
| 51 |
+
frame_indices = np.array([i for i in range(0, len(vr), round(fps),)])
|
| 52 |
+
video = []
|
| 53 |
+
for frame_index in frame_indices:
|
| 54 |
+
img = vr[frame_index].asnumpy()
|
| 55 |
+
video.append(img)
|
| 56 |
+
video = np.stack(video)
|
| 57 |
+
image_sizes = [video[0].shape[:2]]
|
| 58 |
+
video = process_images(video, image_processor, model.config)
|
| 59 |
+
video = [item.unsqueeze(0) for item in video]
|
| 60 |
+
|
| 61 |
+
if audio_path is not None:
|
| 62 |
+
audio_data = {
|
| 63 |
+
"audio": [{'audio_file': audio_path, 'start_time': None, 'end_time': None}]
|
| 64 |
+
}
|
| 65 |
+
audio = audio_processor(audio_data)
|
| 66 |
+
else:
|
| 67 |
+
audio = None
|
| 68 |
+
|
| 69 |
+
qs = DEFAULT_IMAGE_TOKEN + "\n" + qs
|
| 70 |
+
conv = conv_templates["qwen"].copy()
|
| 71 |
+
conv.append_message(conv.roles[0], qs)
|
| 72 |
+
conv.append_message(conv.roles[1], None)
|
| 73 |
+
prompt = conv.get_prompt()
|
| 74 |
+
|
| 75 |
+
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(model.device)
|
| 76 |
+
stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
|
| 77 |
+
keywords = [stop_str]
|
| 78 |
+
stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)
|
| 79 |
+
|
| 80 |
+
with torch.inference_mode():
|
| 81 |
+
output_ids = model.generate(
|
| 82 |
+
input_ids,
|
| 83 |
+
images=video,
|
| 84 |
+
image_sizes=image_sizes,
|
| 85 |
+
do_sample=True,
|
| 86 |
+
temperature=0.2,
|
| 87 |
+
max_new_tokens=128,
|
| 88 |
+
use_cache=True,
|
| 89 |
+
stopping_criteria=[stopping_criteria],
|
| 90 |
+
prompt=instruction,
|
| 91 |
+
audio=audio
|
| 92 |
+
)
|
| 93 |
+
pred = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
|
| 94 |
+
print(pred)
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
# Citation
|
| 98 |
+
|
| 99 |
+
```
|
| 100 |
+
@misc{hao2025multimodallongvideomodeling,
|
| 101 |
+
title={Multimodal Long Video Modeling Based on Temporal Dynamic Context},
|
| 102 |
+
author={Haoran Hao and Jiaming Han and Yiyuan Zhang and Xiangyu Yue},
|
| 103 |
+
year={2025},
|
| 104 |
+
eprint={2504.10443},
|
| 105 |
+
archivePrefix={arXiv},
|
| 106 |
+
primaryClass={cs.CV},
|
| 107 |
+
url={https://arxiv.org/abs/2504.10443},
|
| 108 |
+
}
|
| 109 |
+
```
|