Create README.md
#1
by
haozheqi
- opened
README.md
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: cc-by-nc-sa-4.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
base_model:
|
6 |
+
- lmms-lab/llava-onevision-qwen2-0.5b-ov
|
7 |
+
pipeline_tag: video-text-to-text
|
8 |
+
tags:
|
9 |
+
- Action
|
10 |
+
- Video
|
11 |
+
- MQA
|
12 |
+
- multimodal
|
13 |
+
metrics:
|
14 |
+
- accuracy
|
15 |
+
library_name: transformers
|
16 |
+
---
|
17 |
+
|
18 |
+
# LLaVAction-0.5B
|
19 |
+
|
20 |
+
## Model Summary
|
21 |
+
The LLaVAction-0.5B model is trained on EPIC-KITCHENS-100-MQA, based on Qwen2 language model with a context window of 32K tokens.
|
22 |
+
|
23 |
+
- **Project Page**: [https://mmathislab.github.io/llavaction/](https://mmathislab.github.io/llavaction/)
|
24 |
+
- **Paper**: For more details, please check our [paper](https://arxiv.org/abs/tbd)
|
25 |
+
- **Repository**: [https://github.com/AdaptiveMotorControlLab/LLaVAction](https://github.com/AdaptiveMotorControlLab/LLaVAction)
|
26 |
+
- **Point of Contact**: [Mackenzie Mathis](https://people.epfl.ch/mackenzie.mathis)
|
27 |
+
- **Languages**: English
|
28 |
+
-
|
29 |
+
## Use
|
30 |
+
|
31 |
+
### Intended use
|
32 |
+
The model was trained on EPIC-KITCHENS-100-MQA. It's intended to be used on videos that are similar to EPIC-KITCHENS-100.
|
33 |
+
|
34 |
+
|
35 |
+
**Feel free to share your generations in the Community tab!**
|
36 |
+
|
37 |
+
|
38 |
+
### Generation
|
39 |
+
We provide the simple generation process for using our model. For more details, you could refer to Github.
|
40 |
+
|
41 |
+
```python
|
42 |
+
!pip install llavaction
|
43 |
+
from llavaction.model.builder import load_pretrained_model
|
44 |
+
from llavaction.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token
|
45 |
+
from llavaction.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, IGNORE_INDEX
|
46 |
+
from llavaction.conversation import conv_templates, SeparatorStyle
|
47 |
+
from PIL import Image
|
48 |
+
import requests
|
49 |
+
import copy
|
50 |
+
import torch
|
51 |
+
import sys
|
52 |
+
import warnings
|
53 |
+
from decord import VideoReader, cpu
|
54 |
+
import numpy as np
|
55 |
+
warnings.filterwarnings("ignore")
|
56 |
+
def load_video(video_path, max_frames_num,fps=1,force_sample=False):
|
57 |
+
if max_frames_num == 0:
|
58 |
+
return np.zeros((1, 336, 336, 3))
|
59 |
+
vr = VideoReader(video_path, ctx=cpu(0),num_threads=1)
|
60 |
+
total_frame_num = len(vr)
|
61 |
+
video_time = total_frame_num / vr.get_avg_fps()
|
62 |
+
fps = round(vr.get_avg_fps()/fps)
|
63 |
+
frame_idx = [i for i in range(0, len(vr), fps)]
|
64 |
+
if len(frame_idx) > max_frames_num or force_sample:
|
65 |
+
sample_fps = max_frames_num
|
66 |
+
uniform_sampled_frames = np.linspace(0, total_frame_num - 1, sample_fps, dtype=int)
|
67 |
+
frame_idx = uniform_sampled_frames.tolist()
|
68 |
+
frame_time = [i/vr.get_avg_fps() for i in frame_idx]
|
69 |
+
spare_frames = vr.get_batch(frame_idx).asnumpy()
|
70 |
+
# import pdb;pdb.set_trace()
|
71 |
+
return spare_frames,frame_time,video_time
|
72 |
+
pretrained = "MLAdaptiveIntelligence/LLaVAction-0.5B"
|
73 |
+
model_name = "llava_qwen"
|
74 |
+
device = "cuda"
|
75 |
+
device_map = "auto"
|
76 |
+
tokenizer, model, image_processor, max_length = load_pretrained_model(pretrained, None, model_name, torch_dtype="bfloat16", device_map=device_map) # Add any other thing you want to pass in llava_model_args
|
77 |
+
model.eval()
|
78 |
+
video_path = "XXXX"
|
79 |
+
max_frames_num = 64
|
80 |
+
video,frame_time,video_time = load_video(video_path, max_frames_num, 1, force_sample=True)
|
81 |
+
video = image_processor.preprocess(video, return_tensors="pt")["pixel_values"].cuda().half()
|
82 |
+
video = [video]
|
83 |
+
conv_template = "qwen_1_5" # Make sure you use correct chat template for different models
|
84 |
+
time_instruciton = f"The video lasts for {video_time:.2f} seconds, and {len(video[0])} frames are uniformly sampled from it. "
|
85 |
+
perspective_prompt = "You are seeing this video from egocentric view and you are the person. Your hands are sometimes interacting with objects. What action are you doing?"
|
86 |
+
task_prompt = "Describe in details what you see from the video frames."
|
87 |
+
question = DEFAULT_IMAGE_TOKEN + f"\n{time_instruction}\n{perspective_prompt} {task_prompt}"
|
88 |
+
conv = copy.deepcopy(conv_templates[conv_template])
|
89 |
+
conv.append_message(conv.roles[0], question)
|
90 |
+
conv.append_message(conv.roles[1], None)
|
91 |
+
prompt_question = conv.get_prompt()
|
92 |
+
input_ids = tokenizer_image_token(prompt_question, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
|
93 |
+
cont = model.generate(
|
94 |
+
input_ids,
|
95 |
+
images=video,
|
96 |
+
modalities= ["video"],
|
97 |
+
do_sample=False,
|
98 |
+
temperature=0,
|
99 |
+
max_new_tokens=4096,
|
100 |
+
)
|
101 |
+
text_outputs = tokenizer.batch_decode(cont, skip_special_tokens=True)[0].strip()
|
102 |
+
print(text_outputs)
|
103 |
+
```
|
104 |
+
|
105 |
+
|
106 |
+
## Training
|
107 |
+
|
108 |
+
|
109 |
+
### Model
|
110 |
+
- **Architecture**: SO400M + Qwen2
|
111 |
+
- **Initialized Model**: lmms-lab/llava-onevision-qwen2-0.5b-ov
|
112 |
+
- **Data**: EPIC-KITCHENS-100-MQA, 2 epochs, full model
|
113 |
+
- **Precision**: bfloat16
|
114 |
+
|
115 |
+
|
116 |
+
### Hardware & Software
|
117 |
+
GPUs: 32 * Nvidia GH-200 (for whole model series training)
|
118 |
+
Orchestration: HuggingFace Trainer
|
119 |
+
Neural networks: PyTorch
|
120 |
+
|
121 |
+
## Citation
|
122 |
+
|
123 |
+
```bibtex
|
124 |
+
@article{YeQi2025llavaction,
|
125 |
+
title={LLaVAction: evaluating and training multi-modal large language models for action recognition},
|
126 |
+
author={Ye, Shaokai and Qi, Haozhe and Mathis, Alexander and Mathis, Mackenzie W.},
|
127 |
+
journal={arXiv preprint},
|
128 |
+
year={2025}
|
129 |
+
}
|
130 |
+
```
|