husseinxyzz commited on
Commit
4bea9da
·
verified ·
1 Parent(s): 4ee29d7

Copy current files from TESS-Computer/qwen-dit-draw

Browse files
Files changed (3) hide show
  1. README.md +136 -0
  2. config.json +7 -0
  3. trajectory_head.pt +3 -0
README.md ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Qwen/Qwen2.5-VL-3B-Instruct
4
+ datasets:
5
+ - TESS-Computer/quickdraw-circles
6
+ tags:
7
+ - trajectory-prediction
8
+ - diffusion-transformer
9
+ - vision-language
10
+ - robotics
11
+ - drawing
12
+ pipeline_tag: image-to-image
13
+ ---
14
+
15
+ # Qwen-DiT-Draw
16
+
17
+ A Vision-Language Model with Diffusion Transformer head for trajectory prediction. Given an image and instruction, the model predicts drawing trajectories.
18
+
19
+ **Architecture:** Frozen Qwen2.5-VL-3B backbone + trainable DiT action head (36.7M params)
20
+
21
+ ## Model Details
22
+
23
+ - **Base Model:** [Qwen/Qwen2.5-VL-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct)
24
+ - **Training Data:** [TESS-Computer/quickdraw-circles](https://huggingface.co/datasets/TESS-Computer/quickdraw-circles) (21k circle drawings)
25
+ - **Architecture:** GR00T-style chunked prediction with flow matching
26
+ - **Trainable Parameters:** 36.7M (DiT head only, VLM frozen)
27
+ - **Chunk Size:** 16 points per chunk
28
+ - **Output:** (x, y, state) where state > 0.5 indicates stop signal
29
+
30
+ ## Usage
31
+
32
+ ```python
33
+ import torch
34
+ from PIL import Image
35
+ from transformers import AutoProcessor
36
+ from qwen_vl_utils import process_vision_info
37
+
38
+ from src.model import Qwen2_5_VL_Draw, TrajectoryConfig
39
+
40
+ # Load model
41
+ config = TrajectoryConfig(chunk_size=16, dit_hidden_size=512, dit_num_layers=6)
42
+ model = Qwen2_5_VL_Draw(
43
+ model_id="Qwen/Qwen2.5-VL-3B-Instruct",
44
+ config=config,
45
+ freeze_backbone=True,
46
+ dtype=torch.bfloat16,
47
+ )
48
+
49
+ # Load trained weights
50
+ from huggingface_hub import hf_hub_download
51
+ weights_path = hf_hub_download(repo_id="TESS-Computer/qwen-dit-draw", filename="trajectory_head.pt")
52
+ model.trajectory_head.load_state_dict(torch.load(weights_path, weights_only=True))
53
+ model = model.to("cuda").eval()
54
+
55
+ # Load processor
56
+ processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-3B-Instruct")
57
+
58
+ # Create input
59
+ image = Image.new("RGB", (512, 512), "white") # White canvas
60
+ instruction = "draw a circle"
61
+
62
+ messages = [{
63
+ "role": "user",
64
+ "content": [
65
+ {"type": "image", "image": image, "min_pixels": 200704, "max_pixels": 401408},
66
+ {"type": "text", "text": instruction},
67
+ ],
68
+ }]
69
+
70
+ text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
71
+ image_inputs, _, _ = process_vision_info(messages, return_video_kwargs=True)
72
+ inputs = processor(text=[text], images=image_inputs, return_tensors="pt")
73
+ inputs = {k: v.to("cuda") if torch.is_tensor(v) else v for k, v in inputs.items()}
74
+
75
+ # Predict trajectory chunk
76
+ with torch.no_grad():
77
+ chunk = model.predict_chunk(**inputs)
78
+
79
+ chunk = chunk[0].float().cpu().numpy() # (16, 3) - (x, y, state)
80
+ print(f"Predicted {len(chunk)} points")
81
+ for i, (x, y, state) in enumerate(chunk):
82
+ print(f" Point {i}: ({x:.3f}, {y:.3f}), stop={state > 0.5}")
83
+ ```
84
+
85
+ ## Multi-Chunk Inference (Full Drawing)
86
+
87
+ For complete drawings, use visual feedback loop:
88
+
89
+ ```python
90
+ from PIL import ImageDraw
91
+
92
+ canvas = Image.new("RGB", (512, 512), "white")
93
+ all_points = []
94
+ max_chunks = 10
95
+
96
+ for chunk_idx in range(max_chunks):
97
+ # Prepare inputs with current canvas
98
+ messages = [{
99
+ "role": "user",
100
+ "content": [
101
+ {"type": "image", "image": canvas, "min_pixels": 200704, "max_pixels": 401408},
102
+ {"type": "text", "text": "draw a circle"},
103
+ ],
104
+ }]
105
+ # ... process and predict ...
106
+
107
+ # Draw on canvas (use BLACK lines to match training!)
108
+ draw = ImageDraw.Draw(canvas)
109
+ for i in range(1, len(chunk)):
110
+ x1, y1 = int(chunk[i-1][0] * 512), int(chunk[i-1][1] * 512)
111
+ x2, y2 = int(chunk[i][0] * 512), int(chunk[i][1] * 512)
112
+ draw.line([(x1, y1), (x2, y2)], fill='black', width=2)
113
+
114
+ if chunk[i][2] > 0.5: # Stop signal
115
+ break
116
+ ```
117
+
118
+ ## Training
119
+
120
+ Trained on Modal H100 for 2 epochs using flow matching loss.
121
+
122
+ ## Citation
123
+
124
+ ```bibtex
125
+ @misc{qwen-dit-draw,
126
+ author = {TESS Computer},
127
+ title = {Qwen-DiT-Draw: VLM + DiT for Trajectory Prediction},
128
+ year = {2025},
129
+ url = {https://huggingface.co/TESS-Computer/qwen-dit-draw}
130
+ }
131
+ ```
132
+
133
+ ## Links
134
+
135
+ - **Dataset:** [TESS-Computer/quickdraw-circles](https://huggingface.co/datasets/TESS-Computer/quickdraw-circles)
136
+ - **Base Model:** [Qwen/Qwen2.5-VL-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct)
config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_id": "Qwen/Qwen2.5-VL-3B-Instruct",
3
+ "chunk_size": 16,
4
+ "dit_hidden_size": 512,
5
+ "dit_num_layers": 6,
6
+ "best_loss": 0.16406146394491467
7
+ }
trajectory_head.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:51f97190319bd4a50d1bff20f30985a9535963aeadcb8f3ed7d8e2fea85e8d98
3
+ size 73580119