File size: 2,987 Bytes
88023f1
2d9e33d
 
88023f1
 
 
 
 
 
2d9e33d
 
 
 
 
 
88023f1
 
 
 
2d9e33d
88023f1
 
 
 
 
 
2d9e33d
 
 
88023f1
2d9e33d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88023f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
base_model:
- Qwen/Qwen2-VL-2B-Instruct
library_name: transformers
model_name: HazardNet-unsloth-v0.4
tags:
- trl
- sft
licence: license
license: apache-2.0
datasets:
- Tami3/HazardQA
language:
- en
pipeline_tag: visual-question-answering
---

# Model Card for HazardNet-unsloth-v0.4

This model is a fine-tuned version of [Qwen/Qwen2-VL-2B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct).
It has been trained using [TRL](https://github.com/huggingface/trl).

## Quick start

```python
from transformers import pipeline
from PIL import Image
import requests
from io import BytesIO

# Initialize the Visual Question Answering pipeline with HazardNet
hazard_vqa = pipeline(
    "visual-question-answering",
    model="Tami3/HazardNet"
)

# Function to load image from a local path or URL
def load_image(image_path=None, image_url=None):
    if image_path:
        return Image.open(image_path).convert("RGB")
    elif image_url:
        response = requests.get(image_url)
        response.raise_for_status()  # Ensure the request was successful
        return Image.open(BytesIO(response.content)).convert("RGB")
    else:
        raise ValueError("Provide either image_path or image_url.")

# Example 1: Loading image from a local file
try:
    image_path = "path_to_your_ego_car_image.jpg"  # Replace with your local image path
    image = load_image(image_path=image_path)
except Exception as e:
    print(f"Error loading image from path: {e}")
    # Optionally, handle the error or exit

# Example 2: Loading image from a URL
# try:
#     image_url = "https://example.com/path_to_image.jpg"  # Replace with your image URL
#     image = load_image(image_url=image_url)
# except Exception as e:
#     print(f"Error loading image from URL: {e}")
#     # Optionally, handle the error or exit

# Define your question about potential hazards
question = "Is there a pedestrian crossing the road ahead?"

# Get the answer from the HazardNet pipeline
try:
    result = hazard_vqa(question=question, image=image)
    answer = result.get('answer', 'No answer provided.')
    score = result.get('score', 0.0)
    
    print("Question:", question)
    print("Answer:", answer)
    print("Confidence Score:", score)
except Exception as e:
    print(f"Error during inference: {e}")
    # Optionally, handle the error or exit
```

## Training procedure

 


This model was trained with SFT.

### Framework versions

- TRL: 0.13.0
- Transformers: 4.47.1
- Pytorch: 2.5.1+cu121
- Datasets: 3.2.0
- Tokenizers: 0.21.0

## Citations



Cite TRL as:
    
```bibtex
@misc{vonwerra2022trl,
	title        = {{TRL: Transformer Reinforcement Learning}},
	author       = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallouédec},
	year         = 2020,
	journal      = {GitHub repository},
	publisher    = {GitHub},
	howpublished = {\url{https://github.com/huggingface/trl}}
}
```