Image-Text-to-Text
Transformers
Safetensors
qwen2_5_vl
autonomous-driving
hazard-detection
vision-language-model
lora
bitsandbytes
nf4
conversational
4-bit precision
Instructions to use jayanth7111/DriveSense-VLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jayanth7111/DriveSense-VLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="jayanth7111/DriveSense-VLM") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("jayanth7111/DriveSense-VLM") model = AutoModelForImageTextToText.from_pretrained("jayanth7111/DriveSense-VLM") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use jayanth7111/DriveSense-VLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "jayanth7111/DriveSense-VLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "jayanth7111/DriveSense-VLM", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/jayanth7111/DriveSense-VLM
- SGLang
How to use jayanth7111/DriveSense-VLM with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "jayanth7111/DriveSense-VLM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "jayanth7111/DriveSense-VLM", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "jayanth7111/DriveSense-VLM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "jayanth7111/DriveSense-VLM", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use jayanth7111/DriveSense-VLM with Docker Model Runner:
docker model run hf.co/jayanth7111/DriveSense-VLM
Upload DriveSense-VLM artifacts
Browse files
README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
base_model: Qwen/Qwen2.5-VL-3B-Instruct
|
| 5 |
+
tags:
|
| 6 |
+
- autonomous-driving
|
| 7 |
+
- hazard-detection
|
| 8 |
+
- vision-language-model
|
| 9 |
+
- lora
|
| 10 |
+
- bitsandbytes
|
| 11 |
+
- nf4
|
| 12 |
+
datasets:
|
| 13 |
+
- nuScenes
|
| 14 |
+
pipeline_tag: image-text-to-text
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# DriveSense-VLM
|
| 18 |
+
|
| 19 |
+
**SFT-optimized vision-language model for autonomous-vehicle rare hazard detection.**
|
| 20 |
+
|
| 21 |
+
DriveSense-VLM is a LoRA-fine-tuned [Qwen2.5-VL-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct)
|
| 22 |
+
that takes a single dashcam frame and returns structured JSON describing safety-critical
|
| 23 |
+
hazards: bounding box, hazard label, severity, chain-of-thought reasoning, and the
|
| 24 |
+
recommended ego-vehicle action.
|
| 25 |
+
|
| 26 |
+
[](https://colab.research.google.com/github/jayanth922/DriveSense-VLM/blob/main/notebooks/05_demo.ipynb)
|
| 27 |
+
[](https://github.com/jayanth922/DriveSense-VLM)
|
| 28 |
+
|
| 29 |
+
---
|
| 30 |
+
|
| 31 |
+
## Model details
|
| 32 |
+
|
| 33 |
+
| | |
|
| 34 |
+
|---|---|
|
| 35 |
+
| **Base model** | Qwen/Qwen2.5-VL-3B-Instruct |
|
| 36 |
+
| **Adapter** | LoRA (rank 32, alpha 64), merged into base weights |
|
| 37 |
+
| **Quantization** | bitsandbytes NF4 (4-bit), double-quant, bfloat16 compute |
|
| 38 |
+
| **Vision encoder** | Qwen2.5-VL ViT in fp16 (kept full-precision for grounding accuracy) |
|
| 39 |
+
| **Output schema** | JSON: `hazards[]{bbox_2d, label, severity, reasoning, action}`, `scene_summary`, `ego_context` |
|
| 40 |
+
| **Image resolution** | 672 × 448 (16h × 24w = 384 patches at 28×28 patch size) |
|
| 41 |
+
|
| 42 |
+
---
|
| 43 |
+
|
| 44 |
+
## Training
|
| 45 |
+
|
| 46 |
+
| | |
|
| 47 |
+
|---|---|
|
| 48 |
+
| **Dataset** | 2,754 nuScenes examples (rarity-filtered + LLM counterfactual augmentation) |
|
| 49 |
+
| **Epochs** | 5 |
|
| 50 |
+
| **Eval loss** | 0.312 |
|
| 51 |
+
| **LoRA targets** | `q_proj`, `k_proj`, `v_proj`, `o_proj`, `up_proj`, `down_proj` |
|
| 52 |
+
| **Hardware** | Google Colab Pro A100 |
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
+
|
| 56 |
+
## Evaluation
|
| 57 |
+
|
| 58 |
+
### Detection quality
|
| 59 |
+
|
| 60 |
+
| Metric | Value |
|
| 61 |
+
|---|---|
|
| 62 |
+
| Parse rate (valid JSON) | 99.1% |
|
| 63 |
+
| Mean IoU | 0.550 |
|
| 64 |
+
| Severity classification | 82.9% accuracy |
|
| 65 |
+
| F1 (hazard detection) | 0.107 |
|
| 66 |
+
|
| 67 |
+
### Optimization
|
| 68 |
+
|
| 69 |
+
| Metric | Value |
|
| 70 |
+
|---|---|
|
| 71 |
+
| Compression ratio | 3.1× (vs. fp16 base) |
|
| 72 |
+
| VRAM reduction | 68% |
|
| 73 |
+
| `torch.compile` speedup | 1.48× over eager |
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## Quick start
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
from transformers import AutoModelForImageTextToText, AutoProcessor
|
| 81 |
+
from PIL import Image
|
| 82 |
+
import torch
|
| 83 |
+
|
| 84 |
+
REPO = "jayanth922/DriveSense-VLM"
|
| 85 |
+
|
| 86 |
+
processor = AutoProcessor.from_pretrained(REPO)
|
| 87 |
+
model = AutoModelForImageTextToText.from_pretrained(
|
| 88 |
+
REPO,
|
| 89 |
+
device_map="auto",
|
| 90 |
+
torch_dtype=torch.bfloat16,
|
| 91 |
+
)
|
| 92 |
+
model.eval()
|
| 93 |
+
|
| 94 |
+
PROMPT = (
|
| 95 |
+
"Analyze this dashcam image for safety hazards. Return JSON with hazards array "
|
| 96 |
+
"containing bbox_2d (normalized 0-1000), label, severity (low/medium/high/critical), "
|
| 97 |
+
"reasoning, and action for each hazard. Include scene_summary and ego_context "
|
| 98 |
+
"(weather, time_of_day, road_type)."
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
image = Image.open("dashcam.jpg").convert("RGB")
|
| 102 |
+
messages = [{"role": "user", "content": [
|
| 103 |
+
{"type": "image", "image": image},
|
| 104 |
+
{"type": "text", "text": PROMPT},
|
| 105 |
+
]}]
|
| 106 |
+
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 107 |
+
inputs = processor(text=[text], images=[image], return_tensors="pt").to("cuda")
|
| 108 |
+
|
| 109 |
+
with torch.no_grad():
|
| 110 |
+
out = model.generate(**inputs, max_new_tokens=300, do_sample=False)
|
| 111 |
+
|
| 112 |
+
print(processor.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
---
|
| 116 |
+
|
| 117 |
+
## Intended use
|
| 118 |
+
|
| 119 |
+
- **Portfolio / research demonstration** of VLM fine-tuning, quantization, and grounding for
|
| 120 |
+
the autonomous-driving domain.
|
| 121 |
+
- **Educational** reference implementation of a structured-output VLM pipeline.
|
| 122 |
+
|
| 123 |
+
**Not intended for**: deployment in any safety-critical or production autonomous-driving system.
|
| 124 |
+
|
| 125 |
+
---
|
| 126 |
+
|
| 127 |
+
## Limitations
|
| 128 |
+
|
| 129 |
+
- **Low recall (6.1%)** — the model is conservative and frequently misses hazards present in
|
| 130 |
+
the scene; suitable for ranking / triage, not as a sole detector.
|
| 131 |
+
- **Label fragmentation** — semantically similar hazards (e.g. `pedestrian_in_path`,
|
| 132 |
+
`pedestrian_crossing`) are treated as distinct classes by the F1 calculator, depressing
|
| 133 |
+
the score.
|
| 134 |
+
- **Limited geographic / sensor diversity** — trained on three nuScenes blobs only; expect
|
| 135 |
+
degraded performance on dashcams that differ substantially in mounting, FoV, or weather.
|
| 136 |
+
- **No temporal context** — single-frame inference. Hazards that require motion cues (e.g.
|
| 137 |
+
cut-ins, pedestrian intent) are weaker.
|
| 138 |
+
- **Quantization noise** — NF4 reduces VRAM but introduces a small accuracy delta vs. fp16.
|
| 139 |
+
|
| 140 |
+
---
|
| 141 |
+
|
| 142 |
+
## Files
|
| 143 |
+
|
| 144 |
+
| File | Purpose |
|
| 145 |
+
|---|---|
|
| 146 |
+
| `*.safetensors` | NF4-quantized merged model weights |
|
| 147 |
+
| `config.json` | Model architecture + quantization config |
|
| 148 |
+
| `quant_config.json` | bitsandbytes quantization metadata |
|
| 149 |
+
| `tokenizer*`, `*.json` | Processor / tokenizer / chat template |
|
| 150 |
+
| `examples/*.jpg` | Sample dashcam frames for the Gradio demo |
|
| 151 |
+
| `README.md` | This model card |
|
| 152 |
+
|
| 153 |
+
---
|
| 154 |
+
|
| 155 |
+
## Links
|
| 156 |
+
|
| 157 |
+
- **GitHub repo**: <https://github.com/jayanth922/DriveSense-VLM>
|
| 158 |
+
- **Colab demo**: [`notebooks/05_demo.ipynb`](https://colab.research.google.com/github/jayanth922/DriveSense-VLM/blob/main/notebooks/05_demo.ipynb)
|
| 159 |
+
- **Base model**: [Qwen/Qwen2.5-VL-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct)
|
| 160 |
+
- **Datasets**: [nuScenes](https://www.nuscenes.org/), DADA-2000
|
| 161 |
+
|
| 162 |
+
## License
|
| 163 |
+
|
| 164 |
+
Apache-2.0. Inherits the [Qwen2.5-VL license](https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct/blob/main/LICENSE)
|
| 165 |
+
for the base weights.
|