Harsh72AI commited on
Commit
8cd053a
1 Parent(s): 7d7357e

Project Files committed

Browse files
LICENSE_plate_detection_YOLOv8_model_training.py.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
License_Plate_detection_Model_Evaluation.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
Project README.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Vehicle LICENSE Plate Detection
2
+
3
+ Detects the LICENSE Plates for variety of different Vehicles.
4
+
5
+ It has been trained using the YOLOv8 model from **ultraytics** for 15 epochs on NVIDIA T4 GPU
6
+
7
+ **Roboflow Dataset used: https://universe.roboflow.com/roboflow-universe-projects/license-plate-recognition-rxg4e**
8
+
9
+ **App: https://huggingface.co/spaces/Harsh72AI/Vehicle-License-Plate-Detection**
10
+
11
+ YOLOv8 model has achieved:
12
+ * Box Loss - 0.432
13
+ * mAP50 - 0.977
14
+ * mAP50-95 - 0.682
15
+
16
+
17
+
YOLOv8 Training Results.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29bece8ef0a7aedd08a4d699c45f8c5d5e8179c636c7ed1d565407e13a152f58
3
+ size 103926861
YOLOv8_best_weights.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:709142c277aaaffa348f907994ee42f2cd40b85c79701572cad8197762ee593f
3
+ size 52028609
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from predict_pipeline import DetectionPipeline
2
+ import streamlit as st
3
+
4
+ st.title('Automatic Vechile LICENSE Plate detection')
5
+ st.write('Detects the License plate of a car and predicts the digits present in it! \nPowered by YOLOv8 Medium model')
6
+
7
+ st.write('')
8
+
9
+ detect_pipeline = DetectionPipeline()
10
+
11
+ st.info('License Plate Detector MODEL loaded successfully!')
12
+
13
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
14
+
15
+ if uploaded_file is not None:
16
+
17
+ with st.container():
18
+ col1, col2 = st.columns([3, 3])
19
+ col1.header('Input Image')
20
+ col1.image(uploaded_file, caption='Uploaded Image', use_column_width=True)
21
+
22
+ col1.text('')
23
+ col1.text('')
24
+
25
+ if st.button('Detect!'):
26
+ preprocessed_img_array = detect_pipeline.preprocess_image(uploaded_file=uploaded_file)
27
+ detections = detect_pipeline.detectLicensePlates(input_array=preprocessed_img_array)
28
+ detections_img = detect_pipeline.detections2Image(preprocess_image=preprocessed_img_array, detections=detections)
29
+
30
+ col2.header('Detections')
31
+ col2.image(detections_img, caption='Predictions by model', use_column_width=True)
32
+
33
+
34
+
predict_pipeline.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ultralytics import YOLO
2
+ import numpy as np
3
+ from PIL import Image
4
+ import cv2 as cv
5
+
6
+
7
+ class DetectionPipeline():
8
+ def __init__(self) -> None:
9
+ # Initialize and Load in Custom YOLOv8 model training weights
10
+ self.license_plate_detector = YOLO('YOLOv8_best_weights.pt')
11
+
12
+
13
+ def preprocess_image(self, uploaded_file):
14
+ """
15
+ Takes a File in the format - '.jpg' / '.png' / '.jpeg' then converts it into a Numpy array and returns it
16
+
17
+ Args:
18
+ uploaded_file: File that needs to be converted to Numpy array
19
+
20
+ Returns:
21
+ img_array: Image in the `np.array` format
22
+ """
23
+
24
+ img = Image.open(uploaded_file).convert('RGB')
25
+ img_array = np.array(img)
26
+
27
+ return img_array
28
+
29
+ def detectLicensePlates(self, input_array):
30
+ detections = self.license_plate_detector(input_array)[0]
31
+ license_plate_detections = []
32
+ for license_plate in detections.boxes.data.tolist():
33
+ x1, y1, x2, y2, score, class_id = license_plate
34
+ license_plate_detections.append([int(x1), int(y1), int(x2), int(y2), score])
35
+
36
+ return license_plate_detections
37
+
38
+ def detections2Image(self, preprocess_image: np.array, detections:list):
39
+ img = np.array(preprocess_image, dtype='uint8')
40
+ for license_plate_info in detections:
41
+ x1, y1, x2, y2, score = license_plate_info
42
+ cv.rectangle(img, pt1=(x1, y1), pt2=(x2, y2), color=(0, 255, 0), thickness=2)
43
+ img_detections = np.array(img)
44
+ return img_detections
45
+
46
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ultralytics
2
+ torch
3
+ numpy