Spaces:
Sleeping
Sleeping
rasoul asadian
commited on
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -7,15 +7,22 @@ from ultralytics import YOLO
|
|
7 |
max_len = 10
|
8 |
|
9 |
def ocr(plate_image, ocr_model):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def process_image(image, detection_model, ocr_model, yolo_thresh, perpective_width, perpective_height):
|
16 |
-
model = YOLO(f'./weights/{detection_model}.pt')
|
17 |
task = 'obb' if 'obb' in detection_model else 'detect'
|
18 |
-
|
|
|
|
|
19 |
|
20 |
if 'obb' in detection_model:
|
21 |
obb_crops, transformed = perspective_transform(predict, dst_width=perpective_width, dst_height=perpective_height)
|
@@ -37,7 +44,7 @@ def create_interface():
|
|
37 |
with gr.Row():
|
38 |
with gr.Column(scale=1):
|
39 |
detection_model = gr.Dropdown(label="Detection Model", choices=["yolov8-m", "yolov8-obb-m","yolov8-s", "yolov8-obb-s"], value="yolov8-m")
|
40 |
-
ocr_model = gr.Dropdown(label="OCR Model", choices=["
|
41 |
yolo_thresh = gr.Slider(minimum=0.0, maximum=1.0, label='yolo_threshold')
|
42 |
with gr.Row():
|
43 |
perpective_width = gr.Slider(minimum=100, maximum=500, label='perpective_width')
|
|
|
7 |
max_len = 10
|
8 |
|
9 |
def ocr(plate_image, ocr_model):
|
10 |
+
try:
|
11 |
+
if 'yolo' in ocr_model:
|
12 |
+
model = YOLO(f'/content/drive/MyDrive/{ocr_model}.pt', task='detect')
|
13 |
+
preds = model.predict(plate_image)
|
14 |
+
return ''.join([model.names[int(pred.boxes.cls.cpu().numpy()[0])] for pred in preds[0]])
|
15 |
+
else:
|
16 |
+
return ''
|
17 |
+
except Exception :
|
18 |
+
|
19 |
+
return 'error'
|
20 |
|
21 |
def process_image(image, detection_model, ocr_model, yolo_thresh, perpective_width, perpective_height):
|
|
|
22 |
task = 'obb' if 'obb' in detection_model else 'detect'
|
23 |
+
model = YOLO(f'/content/drive/MyDrive/{detection_model}.pt', task=task)
|
24 |
+
|
25 |
+
predict = model(image, conf=yolo_thresh)
|
26 |
|
27 |
if 'obb' in detection_model:
|
28 |
obb_crops, transformed = perspective_transform(predict, dst_width=perpective_width, dst_height=perpective_height)
|
|
|
44 |
with gr.Row():
|
45 |
with gr.Column(scale=1):
|
46 |
detection_model = gr.Dropdown(label="Detection Model", choices=["yolov8-m", "yolov8-obb-m","yolov8-s", "yolov8-obb-s"], value="yolov8-m")
|
47 |
+
ocr_model = gr.Dropdown(label="OCR Model", choices=["trocr-v1", "trocr-v2"], value="trocr-v1")
|
48 |
yolo_thresh = gr.Slider(minimum=0.0, maximum=1.0, label='yolo_threshold')
|
49 |
with gr.Row():
|
50 |
perpective_width = gr.Slider(minimum=100, maximum=500, label='perpective_width')
|