THUdyh commited on
Commit
23b0f6c
1 Parent(s): 6b9effa

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +129 -0
README.md ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - THUdyh/Oryx-SFT-Data
5
+ base_model:
6
+ - Qwen/Qwen2.5-32B-Instruct
7
+ pipeline_tag: text-generation
8
+ language:
9
+ - en
10
+ - zh
11
+ ---
12
+
13
+ # Oryx-1.5-32B
14
+
15
+ ## Model Summary
16
+
17
+ The Oryx-1.5 models are 7/32B parameter models trained on [Oryx-SFT-Data](https://huggingface.co/datasets/THUdyh/Oryx-SFT-Data), based on Qwen2.5 language model with a context window of 32K tokens.
18
+
19
+ Oryx offers an on-demand solution to seamlessly and efficiently process visual inputs with arbitrary spatial sizes and temporal lengths.
20
+
21
+ - **Repository:** https://github.com/Oryx-mllm/Oryx
22
+ - **Languages:** English, Chinese
23
+ - **Paper:** https://arxiv.org/abs/2409.12961
24
+
25
+ ## Use
26
+
27
+ We provide a simple generation process for using our model. For more details, please refer to our [Github Repo](https://github.com/liuzuyan/oryx)
28
+
29
+ ```
30
+ from oryx.model.builder import load_pretrained_model
31
+ from oryx.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token
32
+ from oryx.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, IGNORE_INDEX
33
+ from oryx.conversation import conv_templates, SeparatorStyle
34
+ from PIL import Image
35
+ import requests
36
+ import copy
37
+ import torch
38
+ import sys
39
+ import warnings
40
+ from decord import VideoReader, cpu
41
+ import numpy as np
42
+
43
+ def load_video(self, video_path, max_frames_num,fps=1,force_sample=False):
44
+ if max_frames_num == 0:
45
+ return np.zeros((1, 336, 336, 3))
46
+ vr = VideoReader(video_path, ctx=cpu(0),num_threads=1)
47
+ total_frame_num = len(vr)
48
+ video_time = total_frame_num / vr.get_avg_fps()
49
+ fps = round(vr.get_avg_fps()/fps)
50
+ frame_idx = [i for i in range(0, len(vr), fps)]
51
+ frame_time = [i/fps for i in frame_idx]
52
+ if len(frame_idx) > max_frames_num or force_sample:
53
+ sample_fps = max_frames_num
54
+ uniform_sampled_frames = np.linspace(0, total_frame_num - 1, sample_fps, dtype=int)
55
+ frame_idx = uniform_sampled_frames.tolist()
56
+ frame_time = [i/vr.get_avg_fps() for i in frame_idx]
57
+ frame_time = ",".join([f"{i:.2f}s" for i in frame_time])
58
+ spare_frames = vr.get_batch(frame_idx).asnumpy()
59
+ # import pdb;pdb.set_trace()
60
+ return spare_frames,frame_time,video_time
61
+ pretrained = "THUdyh/Oryx-7B"
62
+ model_name = "oryx_qwen"
63
+ device = "cuda"
64
+ device_map = "auto"
65
+ tokenizer, model, image_processor, max_length = load_pretrained_model(pretrained, None, model_name, device_map=device_map)
66
+ model.eval()
67
+ video_path = ""
68
+ max_frames_num = "64"
69
+ video,frame_time,video_time = load_video(video_path, max_frames_num, 1, force_sample=True)
70
+ video = image_processor.preprocess(video, return_tensors="pt")["pixel_values"].cuda().bfloat16()
71
+ video = [video]
72
+ video_data = (video, video)
73
+ input_data = (video_data, (384, 384), "video")
74
+ conv_template = "qwen_1_5"
75
+ question = DEFAULT_IMAGE_TOKEN + "\nPlease describe this video in detail."
76
+ conv = copy.deepcopy(conv_templates[conv_template])
77
+ conv.append_message(conv.roles[0], question)
78
+ conv.append_message(conv.roles[1], None)
79
+ prompt_question = conv.get_prompt()
80
+ input_ids = tokenizer_image_token(prompt_question, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
81
+ output_ids = model.generate(
82
+ inputs=input_ids,
83
+ images=input_data[0][0],
84
+ images_highres=input_data[0][1],
85
+ modalities=video_data[2],
86
+ do_sample=False,
87
+ temperature=0,
88
+ max_new_tokens=128,
89
+ use_cache=True,
90
+ )
91
+
92
+ text_outputs = tokenizer.batch_decode(cont, skip_special_tokens=True)
93
+ print(text_outputs)
94
+ ```
95
+
96
+
97
+ ### Results
98
+
99
+ #### General Video Benchmark
100
+
101
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/652965773a416e1f2173443b/hKfOK0u3OXly_u4hgGLDB.png" alt="image/png" style="zoom: 33%;" />
102
+
103
+ #### Long-Form Video Understanding
104
+
105
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/652965773a416e1f2173443b/Xweq9f4OWkqeVc_FZIMuO.png" alt="image/png" style="zoom:33%;" />
106
+
107
+ #### Common Image Benchmark
108
+
109
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/652965773a416e1f2173443b/ybfroSA9WaKXtJbP_9cLR.png" alt="image/png" style="zoom:33%;" />
110
+
111
+ #### 3D Spatial Understanding
112
+
113
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/652965773a416e1f2173443b/5v8ACRzAoKS0FbcVBXZhT.png" alt="image/png" style="zoom:33%;" />
114
+
115
+
116
+
117
+ ### Model Architecture
118
+
119
+ - **Architecture:** Pre-trained [Oryx-ViT](https://huggingface.co/THUdyh/Oryx-ViT) + Qwen-2.5-32B
120
+ - **Data:** a mixture of 1.2M image/video data
121
+ - **Precision:** BFloat16
122
+
123
+ #### Hardware & Software
124
+
125
+ - **Hardware:** 64 * NVIDIA Tesla A100
126
+ - **Orchestration:** HuggingFace Trainer
127
+ - **Code:** Pytorch
128
+
129
+ ## Citation