File size: 5,513 Bytes
17b0d26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff5781c
 
 
 
 
 
17b0d26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a0a894
17b0d26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a88994a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
056e81d
 
 
a88994a
 
17b0d26
 
 
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
license: agpl-3.0
pipeline_tag: object-detection
tags:
- ultralytics
- tracking
- instance-segmentation
- image-classification
- pose-estimation
- obb
- object-detection
- yolo
- yolov8
- license_plate
- Iran
- veichle_lisence_plate

---


[Ultralytics](https://www.ultralytics.com/) [YOLOv8](https://github.com/ultralytics/ultralytics) is a cutting-edge, state-of-the-art (SOTA) model that builds upon the success of previous YOLO versions and introduces new features and improvements to further boost performance and flexibility. YOLOv8 is designed to be fast, accurate, and easy to use, making it an excellent choice for a wide range of object detection and tracking, instance segmentation, image classification and pose estimation tasks.

I fine tuned this model on [this dataset](https://www.kaggle.com/datasets/samyarr/iranvehicleplatedataset) for detecting Iranian veichle license plate.


## <div align="center">Documentation</div>

See below for a quickstart installation and usage example, and see the [YOLOv8 Docs](https://docs.ultralytics.com/) for full documentation on training, validation, prediction and deployment.

<details open>
<summary>Install</summary>

Pip install the ultralytics package including all [requirements](https://github.com/ultralytics/ultralytics/blob/main/pyproject.toml) in a [**Python>=3.8**](https://www.python.org/) environment with [**PyTorch>=1.8**](https://pytorch.org/get-started/locally/).

[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics/) [![Downloads](https://static.pepy.tech/badge/ultralytics)](https://pepy.tech/project/ultralytics) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics/)

```bash
pip install ultralytics
```

For alternative installation methods including [Conda](https://anaconda.org/conda-forge/ultralytics), [Docker](https://hub.docker.com/r/ultralytics/ultralytics), and Git, please refer to the [Quickstart Guide](https://docs.ultralytics.com/quickstart/).

[![Conda Version](https://img.shields.io/conda/vn/conda-forge/ultralytics?logo=condaforge)](https://anaconda.org/conda-forge/ultralytics) [![Docker Image Version](https://img.shields.io/docker/v/ultralytics/ultralytics?sort=semver&logo=docker)](https://hub.docker.com/r/ultralytics/ultralytics)

</details>

<details open>
<summary>Usage</summary>

### CLI

YOLOv8 may be used directly in the Command Line Interface (CLI) with a `yolo` command:

```bash
yolo predict model=YOLOv8m_Iran_license_plate_detection.pt source='your_image.jpg'
```

`yolo` can be used for a variety of tasks and modes and accepts additional arguments, i.e. `imgsz=640`. See the YOLOv8 [CLI Docs](https://docs.ultralytics.com/usage/cli/) for examples.

### Python

YOLOv8 may also be used directly in a Python environment, and accepts the same [arguments](https://docs.ultralytics.com/usage/cfg/) as in the CLI example above:

```python
from ultralytics import YOLO
# Load a model
model = YOLO("local_model_path/YOLOv8m_Iran_license_plate_detection.pt")
# Train the model
train_results = model.train(
    data="Iran_license_plate.yaml",  # path to dataset YAML
    epochs=100,  # number of training epochs
    imgsz=640,  # training image size
    device="cpu",  # device to run on, i.e. device=0 or device=0,1,2,3 or device=cpu
)
# Evaluate model performance on the validation set
metrics = model.val()
# Perform object detection on an image
results = model("path/to/image.jpg")
results[0].show()
# Export the model to ONNX format
path = model.export(format="onnx")  # return path to exported model
```


### Inference

You can use the model with this code to see how it detects, the style you plot or save detected object is up to you, but here is an example:

```python
from ultralytics import YOLO
import matplotlib.pyplot as plt
import cv2

# Load the YOLO model
model = YOLO("path/to/local/model.pt")

# Define the input image file path
file_path = "path/to/image"

# Get the prediction results
results = model([file_path])

# Read the input image
img = cv2.imread(file_path)

# Iterate over the results to extract bounding box and display both input and cropped output
for result in results:
    maxa = result.boxes.conf.argmax()  # Get the index of the highest confidence box
    x, y, w, h = result.boxes.xywh[maxa]  # Extract coordinates and size
    print(f"Bounding box: x={x}, y={y}, w={w}, h={h}")
    
    # Crop the detected object from the image
    crop_img = img[int(y-h/2):int(y+h/2), int(x-w/2):int(x+w/2)]

    # Convert the image from BGR to RGB for display with matplotlib
    img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    crop_img_rgb = cv2.cvtColor(crop_img, cv2.COLOR_BGR2RGB)

    # Plot the input image and cropped image side by side
    plt.figure(figsize=(10, 5))

    # Display the input image
    plt.subplot(1, 2, 1)
    plt.imshow(img_rgb)
    plt.title("Input Image")
    plt.axis("off")

    # Display the cropped image (output)
    plt.subplot(1, 2, 2)
    plt.imshow(crop_img_rgb)
    plt.title("Cropped Output")
    plt.axis("off")

    plt.show()
```

desired output:
Bounding box: x=246.37399291992188, y=254.00021362304688, w=146.7321014404297, h=38.26557922363281
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64fec52b57a40de19102d516/rzqKl97C7JDGq40fwLp_h.png)


See YOLOv8 [Python Docs](https://docs.ultralytics.com/usage/python/) for more examples.

</details>