THUdyh commited on
Commit
6f87ed1
1 Parent(s): a0dbda2

Update README.md

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