MLAdaptiveIntelligence/LLaVAction-7B
196
1---2license: cc-by-nc-sa-4.03datasets:4- lmms-lab/LLaVA-Video-178K5language:6- en7metrics:8- accuracy9base_model:10- lmms-lab/LLaVA-Video-7B-Qwen211pipeline_tag: video-text-to-text12library_name: transformers13tags:14- Action15- Video16- MQA17- multimodal18- VLM19- LLaVAction20- MLLMs21model-index:22- name: LLaVAction-7B23 results:24 - task:25 type: multimodal26 dataset:27 name: EgoSchema28 type: egoschema29 metrics:30 - type: accuracy31 value: 5932 name: accuracy33 verified: true34 - task:35 type: multimodal36 dataset:37 name: MVBench38 type: mvbench39 metrics:40 - type: accuracy41 value: 61.142 name: accuracy43 verified: true44 - task:45 type: multimodal46 dataset:47 name: NextQA48 type: nextqa49 metrics:50 - type: accuracy51 value: 82.852 name: accuracy53 verified: true54 - task:55 type: multimodal56 dataset:57 name: PercepTest58 type: percepTest59 metrics:60 - type: accuracy61 value: 70.262 name: accuracy63 verified: true64 - task:65 type: multimodal66 dataset:67 name: LongVideoBench68 type: longvideobench69 metrics:70 - type: accuracy71 value: 58.672 name: accuracy73 verified: true74 - task:75 type: multimodal76 dataset:77 name: VideoMME78 type: videomme79 metrics:80 - type: accuracy81 value: 63.982 name: accuracy83 verified: true84 - task:85 type: multimodal86 dataset:87 name: VideoMME (w-subs)88 type: videomme89 metrics:90 - type: accuracy91 value: 71.492 name: accuracy93 verified: true94---95 96# LLaVAction-7B97 98<div align="center">99<h2>LLaVAction: evaluating and training multi-modal large language models for action recognition100</h2>101 102[Shaokai Ye](https://yeshaokai.github.io/)<sup>1**</sup> 103[Haozhe Qi](https://people.epfl.ch/haozhe.qi)<sup>1**</sup> 104 105[Alexander Mathis](https://mathislab.org/)<sup>1</sup><sup>†</sup> 106[Mackenzie Weygandt Mathis](https://www.mackenziemathislab.org/mackenziemathis)<sup>1</sup><sup>†</sup><sup>‡</sup> 107 108<sup>1</sup> EPFL109 110<sup>**</sup> First authors <sup>†</sup> Senior Authors <sup>‡</sup> Corresponding Author111 112\[[arXiv Paper](arxiv.org/abs/2503.18712)\] \[[Project Page](https://mmathislab.github.io/llavaction/)\] \[[Github Repo](https://github.com/AdaptiveMotorControlLab/LLaVAction)\] 113 114</div>115 116## Model Summary117The LLaVAction-7B model is trained on EPIC-KITCHENS-100-MQA, based on Qwen2 language model with a context window of 32K tokens.118This model supports at most 64 frames.119 120- **Project Page**: [https://mmathislab.github.io/llavaction/](https://mmathislab.github.io/llavaction/)121- **Paper**: For more details, please check our [paper](https://arxiv.org/abs/tbd)122- **Repository**: [https://github.com/AdaptiveMotorControlLab/LLaVAction](https://github.com/AdaptiveMotorControlLab/LLaVAction)123- **Point of Contact**: [Mackenzie Mathis](https://people.epfl.ch/mackenzie.mathis)124- **Languages**: English125- 126## Useage127 128### Intended use129The model was trained on EPIC-KITCHENS-100-MQA [dataset release pending] and [LLaVA-Video-178K](https://huggingface.co/datasets/lmms-lab/LLaVA-Video-178K). It has improved capability on understanding human egocentric actions from videos.130 131 132### Generation133We provide the simple generation process for using our model. For more details, you could refer to our [Github](https://github.com/AdaptiveMotorControlLab/LLaVAction).134 135```python136!pip install llavaction137 138from llavaction.model.builder import load_pretrained_model139from llavaction.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token140from llavaction.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, IGNORE_INDEX141from llavaction.conversation import conv_templates, SeparatorStyle142from PIL import Image143import requests144import copy145import torch146import sys147import warnings148from decord import VideoReader, cpu149import numpy as np150warnings.filterwarnings("ignore")151 152#Your video (it assumes an egocentric view point)153video_path = "XXXX"154 155#These are the prompts we trained with, but you can test others:156perspective_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?"157task_prompt = "Describe in details what you see from the video frames."158 159def load_video(video_path, max_frames_num,fps=1,force_sample=False):160 if max_frames_num == 0:161 return np.zeros((1, 336, 336, 3))162 vr = VideoReader(video_path, ctx=cpu(0),num_threads=1)163 total_frame_num = len(vr)164 video_time = total_frame_num / vr.get_avg_fps()165 fps = round(vr.get_avg_fps()/fps)166 frame_idx = [i for i in range(0, len(vr), fps)]167 if len(frame_idx) > max_frames_num or force_sample:168 sample_fps = max_frames_num169 uniform_sampled_frames = np.linspace(0, total_frame_num - 1, sample_fps, dtype=int)170 frame_idx = uniform_sampled_frames.tolist()171 frame_time = [i/vr.get_avg_fps() for i in frame_idx]172 spare_frames = vr.get_batch(frame_idx).asnumpy()173 # import pdb;pdb.set_trace()174 return spare_frames,frame_time,video_time175 176pretrained = "MLAdaptiveIntelligence/LLaVAction-7B"177model_name = "llava_qwen"178device = "cuda"179device_map = "auto"180tokenizer, 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_args181model.eval()182max_frames_num = 64183video,frame_time,video_time = load_video(video_path, max_frames_num, 1, force_sample=True)184video = image_processor.preprocess(video, return_tensors="pt")["pixel_values"].cuda().to(torch.bfloat16)185video = [video]186conv_template = "qwen_1_5" # Make sure you use correct chat template for different models187time_instruction = f"The video lasts for {video_time:.2f} seconds, and {len(video[0])} frames are uniformly sampled from it. "188question = DEFAULT_IMAGE_TOKEN + f"\n{time_instruction}\n{perspective_prompt} {task_prompt}"189 190conv = copy.deepcopy(conv_templates[conv_template])191conv.append_message(conv.roles[0], question)192conv.append_message(conv.roles[1], None)193prompt_question = conv.get_prompt()194input_ids = tokenizer_image_token(prompt_question, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)195 196cont = model.generate(197 input_ids,198 images=video,199 modalities= ["video"],200 do_sample=False,201 temperature=0,202 max_new_tokens=4096,203)204text_outputs = tokenizer.batch_decode(cont, skip_special_tokens=True)[0].strip()205print(text_outputs)206```207 208 209## Training210 211See details in Ye et al. 2025: arxiv.org/abs/2503.18712212 213### Model214- **Architecture**: SO400M + Qwen2215- **Initialized Model**: lmms-lab/LLaVA-Video-7B-Qwen2216- **Data**: A mixture of LLaVA-178K and EPIC-KITCHENS-100-MQA, 2 epochs, full model217- **Precision**: bfloat16218 219 220### Hardware & Software221GPUs: 32 * Nvidia GH-200 (for whole model series training)222Orchestration: HuggingFace Trainer223Neural networks: PyTorch224 225## Citation226 227arXiv: arxiv.org/abs/2503.18712228 229```bibtex230@article{YeQi2025llavaction,231 title={LLaVAction: evaluating and training multi-modal large language models for action recognition},232 author={Ye, Shaokai and Qi, Haozhe and Mathis, Alexander and Mathis, Mackenzie W.},233 journal={arXiv preprint},234 year={2025}235}236```