-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from ultralytics import YOLO | ||
|
||
# Load a pretrained YOLOv8n model | ||
model = YOLO('runs/detect/train18/weights/best.pt') | ||
|
||
# Define remote image or video URL | ||
source = 'https://source.roboflow.com/dRDeH1hYd0WQDBtCSKP39MHuZOY2/3eO0urIBcEjzYDWshuFg/original.jpg' | ||
|
||
# Run inference on the source | ||
results = model(source) # list of Results objects |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
path: C:\Users\Ahmed\PycharmProjects\car plate.v26i.yolov8\data | ||
train: train/images | ||
val: valid/images | ||
test: test/images | ||
nc: 51 | ||
names: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'exp', 'new_DUBAI', 'new_RAK', 'new_abudabi', 'new_ajman', 'new_am', 'new_fujairah', 'old_DUBAI', 'old_RAK', 'old_abudabi', 'old_ajman', 'old_am', 'old_fujira', 'old_sharka', 'plate'] | ||
|
||
roboflow: | ||
workspace: zara-hara | ||
project: car-plate-k6xij | ||
version: 26 | ||
license: CC BY 4.0 | ||
url: https://universe.roboflow.com/zara-hara/car-plate-k6xij/dataset/26 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from ultralytics import YOLO | ||
|
||
# Load a model | ||
model = YOLO("yolov8n.yaml") # build a new model from scratch | ||
|
||
# Use the model | ||
model.train(data="data.yaml", epochs=3) # train the model |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import os | ||
from ultralytics import YOLO | ||
import cv2 | ||
import requests | ||
import numpy as np | ||
from io import BytesIO | ||
import matplotlib.pyplot as plt | ||
|
||
model_path = os.path.join('.', 'runs', 'detect', 'train23', 'weights', 'last.pt') | ||
|
||
specific_classes = ['0', '1', '2', '3', '4', '5', '6', '7', '8', | ||
'9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', | ||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', | ||
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] | ||
state_classes = { | ||
'exp': 'Export', | ||
'new_DUBAI': 'Dubai', | ||
'new_RAK': 'Ras Al-Kaimah', | ||
'new_abudabi': 'Abu Dhabi', | ||
'new_ajman': 'Ajman', | ||
'new_am': 'Umm Al Quwain', | ||
'new_fujairah': 'Fujairah', | ||
'old_DUBAI': 'Dubai', | ||
'old_RAK': 'Ras Al-Kaimah', | ||
'old_abudabi': 'Abu Dhabi', | ||
'old_ajman': 'Ajman', | ||
'old_am': 'Umm Al-Quwain', | ||
'old_fujira': 'Fujairah', | ||
'old_sharka': 'Sharjah' | ||
} | ||
|
||
# Load a model | ||
model = YOLO(model_path) # load a custom model | ||
|
||
threshold = 0.4 | ||
|
||
|
||
def detect_text(image): | ||
output_array = [] | ||
state_name = "couldn\'t be detected" | ||
|
||
H, W, _ = image.shape | ||
|
||
results = model(image)[0] | ||
|
||
# Sort the results by the x-axis position | ||
sorted_results = sorted(results.boxes.data.tolist(), key=lambda x: x[0]) | ||
|
||
|
||
for x1, y1, x2, y2, score, class_id in sorted_results: | ||
class_name = model.names[class_id] | ||
|
||
if (score > threshold) and (class_name in specific_classes): | ||
output_array.append(class_name) | ||
|
||
|
||
|
||
for x1, y1, x2, y2, score, class_id in sorted_results: | ||
class_name = model.names[class_id] | ||
if score > threshold and (class_name in state_classes): | ||
state_name = state_classes[class_name] | ||
break | ||
|
||
|
||
if 'D' in output_array and 'Q' in output_array: #error correction | ||
output_array.remove('Q') | ||
|
||
|
||
|
||
return output_array , state_name | ||
|
||
|
||
def main(): | ||
# URL list containing image URLs | ||
image_urls = [ | ||
'https://c8.alamy.com/comp/A8G1XR/luxury-car-bmw-with-dubai-license-plate-photo-by-willy-matheisl-A8G1XR.jpg', | ||
# Add more image URLs here | ||
] | ||
|
||
for image_url in image_urls: | ||
response = requests.get(image_url) | ||
if response.status_code == 200: | ||
image_data = BytesIO(response.content) | ||
image = cv2.imdecode(np.frombuffer(image_data.read(), np.uint8), cv2.IMREAD_COLOR) | ||
|
||
H, W, _ = image.shape | ||
|
||
results = model(image)[0] | ||
|
||
sorted_results = sorted (results.boxes.data.tolist (), key=lambda x: x[0]) | ||
|
||
for result in sorted_results: | ||
x1, y1, x2, y2, score, class_id = result | ||
|
||
if score > threshold and results.names[int(class_id)] == 'plate': | ||
cv2.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 4) | ||
plate_img = image[int(y1):int(y2), int(x1):int(x2)] | ||
output , state = detect_text(plate_img) | ||
print(output) | ||
print(f"The state this car belongs to {state}") | ||
|
||
|
||
plt.figure() | ||
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) | ||
|
||
plt.show() | ||
|
||
else: | ||
print(f"Failed to retrieve image from URL: {image_url}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
task: detect | ||
mode: train | ||
model: yolov8n.yaml | ||
data: data.yaml | ||
epochs: 3 | ||
patience: 50 | ||
batch: 16 | ||
imgsz: 640 | ||
save: true | ||
save_period: -1 | ||
cache: false | ||
device: null | ||
workers: 8 | ||
project: null | ||
name: null | ||
exist_ok: false | ||
pretrained: true | ||
optimizer: auto | ||
verbose: true | ||
seed: 0 | ||
deterministic: true | ||
single_cls: false | ||
rect: false | ||
cos_lr: false | ||
close_mosaic: 10 | ||
resume: false | ||
amp: true | ||
fraction: 1.0 | ||
profile: false | ||
freeze: null | ||
overlap_mask: true | ||
mask_ratio: 4 | ||
dropout: 0.0 | ||
val: true | ||
split: val | ||
save_json: false | ||
save_hybrid: false | ||
conf: null | ||
iou: 0.7 | ||
max_det: 300 | ||
half: false | ||
dnn: false | ||
plots: true | ||
source: null | ||
show: false | ||
save_txt: false | ||
save_conf: false | ||
save_crop: false | ||
show_labels: true | ||
show_conf: true | ||
vid_stride: 1 | ||
stream_buffer: false | ||
line_width: null | ||
visualize: false | ||
augment: false | ||
agnostic_nms: false | ||
classes: null | ||
retina_masks: false | ||
boxes: true | ||
format: torchscript | ||
keras: false | ||
optimize: false | ||
int8: false | ||
dynamic: false | ||
simplify: false | ||
opset: null | ||
workspace: 4 | ||
nms: false | ||
lr0: 0.01 | ||
lrf: 0.01 | ||
momentum: 0.937 | ||
weight_decay: 0.0005 | ||
warmup_epochs: 3.0 | ||
warmup_momentum: 0.8 | ||
warmup_bias_lr: 0.1 | ||
box: 7.5 | ||
cls: 0.5 | ||
dfl: 1.5 | ||
pose: 12.0 | ||
kobj: 1.0 | ||
label_smoothing: 0.0 | ||
nbs: 64 | ||
hsv_h: 0.015 | ||
hsv_s: 0.7 | ||
hsv_v: 0.4 | ||
degrees: 0.0 | ||
translate: 0.1 | ||
scale: 0.5 | ||
shear: 0.0 | ||
perspective: 0.0 | ||
flipud: 0.0 | ||
fliplr: 0.5 | ||
mosaic: 1.0 | ||
mixup: 0.0 | ||
copy_paste: 0.0 | ||
cfg: null | ||
tracker: botsort.yaml | ||
save_dir: runs\detect\train |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
epoch, train/box_loss, train/cls_loss, train/dfl_loss, metrics/precision(B), metrics/recall(B), metrics/mAP50(B), metrics/mAP50-95(B), val/box_loss, val/cls_loss, val/dfl_loss, lr/pg0, lr/pg1, lr/pg2 | ||
1, 4.4059, 7.2949, 3.9288, 0.35655, 0.0046, 0.00174, 0.00047, 3.2456, 5.315, 3.2751, 6.057e-05, 6.057e-05, 6.057e-05 | ||
2, 3.1671, 4.2795, 2.623, 0.09093, 0.02468, 0.01277, 0.00496, 2.8609, 3.8934, 2.029, 8.1229e-05, 8.1229e-05, 8.1229e-05 | ||
3, 2.7716, 3.3153, 1.8106, 0.11494, 0.02624, 0.01891, 0.00866, 2.4415, 3.1568, 1.6992, 6.1847e-05, 6.1847e-05, 6.1847e-05 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
task: detect | ||
mode: train | ||
model: yolov8n.yaml | ||
data: data.yaml | ||
epochs: 600 | ||
patience: 50 | ||
batch: 16 | ||
imgsz: 640 | ||
save: true | ||
save_period: -1 | ||
cache: false | ||
device: null | ||
workers: 8 | ||
project: null | ||
name: null | ||
exist_ok: false | ||
pretrained: true | ||
optimizer: auto | ||
verbose: true | ||
seed: 0 | ||
deterministic: true | ||
single_cls: false | ||
rect: false | ||
cos_lr: false | ||
close_mosaic: 10 | ||
resume: false | ||
amp: true | ||
fraction: 1.0 | ||
profile: false | ||
freeze: null | ||
overlap_mask: true | ||
mask_ratio: 4 | ||
dropout: 0.0 | ||
val: true | ||
split: val | ||
save_json: false | ||
save_hybrid: false | ||
conf: null | ||
iou: 0.7 | ||
max_det: 300 | ||
half: false | ||
dnn: false | ||
plots: true | ||
source: null | ||
show: false | ||
save_txt: false | ||
save_conf: false | ||
save_crop: false | ||
show_labels: true | ||
show_conf: true | ||
vid_stride: 1 | ||
stream_buffer: false | ||
line_width: null | ||
visualize: false | ||
augment: false | ||
agnostic_nms: false | ||
classes: null | ||
retina_masks: false | ||
boxes: true | ||
format: torchscript | ||
keras: false | ||
optimize: false | ||
int8: false | ||
dynamic: false | ||
simplify: false | ||
opset: null | ||
workspace: 4 | ||
nms: false | ||
lr0: 0.01 | ||
lrf: 0.01 | ||
momentum: 0.937 | ||
weight_decay: 0.0005 | ||
warmup_epochs: 3.0 | ||
warmup_momentum: 0.8 | ||
warmup_bias_lr: 0.1 | ||
box: 7.5 | ||
cls: 0.5 | ||
dfl: 1.5 | ||
pose: 12.0 | ||
kobj: 1.0 | ||
label_smoothing: 0.0 | ||
nbs: 64 | ||
hsv_h: 0.015 | ||
hsv_s: 0.7 | ||
hsv_v: 0.4 | ||
degrees: 0.0 | ||
translate: 0.1 | ||
scale: 0.5 | ||
shear: 0.0 | ||
perspective: 0.0 | ||
flipud: 0.0 | ||
fliplr: 0.5 | ||
mosaic: 1.0 | ||
mixup: 0.0 | ||
copy_paste: 0.0 | ||
cfg: null | ||
tracker: botsort.yaml | ||
save_dir: runs\detect\train17 |