lixin4ever commited on
Commit
2f713ad
β€’
1 Parent(s): b0d0237

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +153 -3
README.md CHANGED
@@ -1,3 +1,153 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - OpenGVLab/VideoChat2-IT
5
+ - Lin-Chen/ShareGPT4V
6
+ - liuhaotian/LLaVA-Instruct-150K
7
+ language:
8
+ - en
9
+ metrics:
10
+ - accuracy
11
+ library_name: transformers
12
+ pipeline_tag: visual-question-answering
13
+ tags:
14
+ - multimodal large language model
15
+ - large video-language model
16
+ ---
17
+
18
+ <p align="center">
19
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/63913b120cf6b11c487ca31d/ROs4bHIp4zJ7g7vzgUycu.png" width="150" style="margin-bottom: 0.2;"/>
20
+ <p>
21
+
22
+
23
+ <h3 align="center"><a href="https://arxiv.org/abs/2406.07476">VideoLLaMA 2: Advancing Spatial-Temporal Modeling and Audio Understanding in Video-LLMs</a></h3>
24
+ <h5 align="center"> If you like our project, please give us a star ⭐ on <a href="https://github.com/DAMO-NLP-SG/VideoLLaMA2">Github</a> for the latest update. </h2>
25
+
26
+ <p align="center"><video src="https://cdn-uploads.huggingface.co/production/uploads/63913b120cf6b11c487ca31d/Wj7GuqQ0CB9JRoPo6_GoH.webm" width="800"></p>
27
+
28
+ ## πŸ“° News
29
+ * **[2024.06.12]** Release model weights and the first version of the technical report of VideoLLaMA 2.
30
+ * **[2024.06.03]** Release training, evaluation, and serving codes of VideoLLaMA 2.
31
+
32
+
33
+ ## 🌎 Model Zoo
34
+ | Model Name | Type | Visual Encoder | Language Decoder | # Training Frames |
35
+ |:-------------------|:--------------:|:----------------|:------------------|:----------------------:|
36
+ | [VideoLLaMA2-7B-Base](https://huggingface.co/DAMO-NLP-SG/VideoLLaMA2-7B-Base) | Base | [clip-vit-large-patch14-336](https://huggingface.co/openai/clip-vit-large-patch14-336) | [Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2) | 8 |
37
+ | [VideoLLaMA2-7B](https://huggingface.co/DAMO-NLP-SG/VideoLLaMA2-7B) | Chat | [clip-vit-large-patch14-336](https://huggingface.co/openai/clip-vit-large-patch14-336) | [Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2) | 8 |
38
+ | [VideoLLaMA2-7B-16F-Base](https://huggingface.co/DAMO-NLP-SG/VideoLLaMA2-7B-16F-Base) | Base | [clip-vit-large-patch14-336](https://huggingface.co/openai/clip-vit-large-patch14-336) | [Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2) | 16 |
39
+ | [VideoLLaMA2-7B-16F](https://huggingface.co/DAMO-NLP-SG/VideoLLaMA2-7B-16F) (This checkpoint) | Chat | [clip-vit-large-patch14-336](https://huggingface.co/openai/clip-vit-large-patch14-336) | [Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2) | 16 |
40
+
41
+
42
+
43
+ ## πŸš€ Main Results
44
+
45
+ ### Multi-Choice Video QA & Video Captioning
46
+ <p><img src="https://github.com/DAMO-NLP-SG/VideoLLaMA2/assets/18526640/9cc4a5ae-d850-4eef-bd51-83688b94698e" width="800" "/></p>
47
+
48
+
49
+ ### Open-Ended Video QA
50
+ <p><img src="https://github.com/DAMO-NLP-SG/VideoLLaMA2/assets/18526640/2ed7aa53-db56-4829-8375-85aefbc5120a" width="800" "/></p>
51
+
52
+
53
+
54
+
55
+ ## πŸ€– Inference with VideoLLaMA2
56
+ ```python
57
+ import torch
58
+ import transformers
59
+
60
+ import sys
61
+ sys.path.append('./')
62
+ from videollama2.conversation import conv_templates, SeparatorStyle
63
+ from videollama2.constants import DEFAULT_MMODAL_TOKEN, MMODAL_TOKEN_INDEX
64
+ from videollama2.mm_utils import get_model_name_from_path, tokenizer_MMODAL_token, KeywordsStoppingCriteria, process_video, process_image
65
+ from videollama2.model.builder import load_pretrained_model
66
+
67
+
68
+ def inference():
69
+ # Video Inference
70
+ paths = ['assets/cat_and_chicken.mp4']
71
+ questions = ['What animals are in the video, what are they doing, and how does the video feel?']
72
+ # Reply:
73
+ # The video features a kitten and a baby chick playing together. The kitten is seen laying on the floor while the baby chick hops around. The two animals interact playfully with each other, and the video has a cute and heartwarming feel to it.
74
+ modal_list = ['video']
75
+
76
+ # Video Inference
77
+ paths = ['assets/sora.mp4']
78
+ questions = ['Please describe this video.']
79
+ # Reply:
80
+ # The video features a series of colorful kites flying in the sky. The kites are first seen flying over trees, and then they are shown flying in the sky. The kites come in various shapes and colors, including red, green, blue, and yellow. The video captures the kites soaring gracefully through the air, with some kites flying higher than others. The sky is clear and blue, and the trees below are lush and green. The kites are the main focus of the video, and their vibrant colors and intricate designs are highlighted against the backdrop of the sky and trees. Overall, the video showcases the beauty and artistry of kite-flying, and it is a delight to watch the kites dance and glide through the air.
81
+ modal_list = ['video']
82
+
83
+ # Image Inference
84
+ paths = ['assets/sora.png']
85
+ questions = ['What is the woman wearing, what is she doing, and how does the image feel?']
86
+ # Reply:
87
+ # The woman in the image is wearing a black coat and sunglasses, and she is walking down a rain-soaked city street. The image feels vibrant and lively, with the bright city lights reflecting off the wet pavement, creating a visually appealing atmosphere. The woman's presence adds a sense of style and confidence to the scene, as she navigates the bustling urban environment.
88
+ modal_list = ['image']
89
+
90
+ # 1. Initialize the model.
91
+ model_path = 'DAMO-NLP-SG/VideoLLaMA2-7B-16F'
92
+ model_name = get_model_name_from_path(model_path)
93
+ tokenizer, model, processor, context_len = load_pretrained_model(model_path, None, model_name)
94
+ model = model.to('cuda:0')
95
+ conv_mode = 'llama_2'
96
+
97
+ # 2. Visual preprocess (load & transform image or video).
98
+ if modal_list[0] == 'video':
99
+ tensor = process_video(paths[0], processor, model.config.image_aspect_ratio).to(dtype=torch.float16, device='cuda', non_blocking=True)
100
+ default_mm_token = DEFAULT_MMODAL_TOKEN["VIDEO"]
101
+ modal_token_index = MMODAL_TOKEN_INDEX["VIDEO"]
102
+ else:
103
+ tensor = process_image(paths[0], processor, model.config.image_aspect_ratio)[0].to(dtype=torch.float16, device='cuda', non_blocking=True)
104
+ default_mm_token = DEFAULT_MMODAL_TOKEN["IMAGE"]
105
+ modal_token_index = MMODAL_TOKEN_INDEX["IMAGE"]
106
+ tensor = [tensor]
107
+
108
+ # 3. Text preprocess (tag process & generate prompt).
109
+ question = default_mm_token + "\n" + questions[0]
110
+ conv = conv_templates[conv_mode].copy()
111
+ conv.append_message(conv.roles[0], question)
112
+ conv.append_message(conv.roles[1], None)
113
+ prompt = conv.get_prompt()
114
+ input_ids = tokenizer_MMODAL_token(prompt, tokenizer, modal_token_index, return_tensors='pt').unsqueeze(0).to('cuda:0')
115
+
116
+ # 4. Generate a response according to visual signals and prompts.
117
+ stop_str = conv.sep if conv.sep_style in [SeparatorStyle.SINGLE] else conv.sep2
118
+ # keywords = ["<s>", "</s>"]
119
+ keywords = [stop_str]
120
+ stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)
121
+
122
+ with torch.inference_mode():
123
+ output_ids = model.generate(
124
+ input_ids,
125
+ images_or_videos=tensor,
126
+ modal_list=modal_list,
127
+ do_sample=True,
128
+ temperature=0.2,
129
+ max_new_tokens=1024,
130
+ use_cache=True,
131
+ stopping_criteria=[stopping_criteria],
132
+ )
133
+
134
+ outputs = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
135
+ print(outputs[0])
136
+
137
+
138
+ if __name__ == "__main__":
139
+ inference()
140
+ ```
141
+
142
+
143
+ ## Citation
144
+ If you find our project useful, hope you can star our repo and cite our paper as follows:
145
+ ```
146
+ @article{damonlpsg2024videollama2,
147
+ author = {Cheng, Zesen and Leng, Sicong and Zhang, Hang and Xin, Yifei and Li, Xin and Chen, Guanzheng and Zhu, Yongxin and Zhang, Wenqi and Luo, Ziyang and Bing, Lidong},
148
+ title = {VideoLLaMA 2: Advancing Spatial-Temporal Modeling and Audio Understanding in Video-LLMs},
149
+ year = 2024,
150
+ journal = {arXiv preprint arXiv:2406.07476},
151
+ url = {https://arxiv.org/abs/2406.07476}
152
+ }
153
+ ```