supritg commited on
Commit
1e54fbd
1 Parent(s): 8f59702

Added all the files

Browse files
Files changed (3) hide show
  1. app.py +74 -0
  2. best.pt +3 -0
  3. requirements.txt +9 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import cv2
4
+ import gradio as gr
5
+ import torch
6
+ from ultralyticsplus import YOLO, render_result
7
+ import matplotlib.pyplot as plt
8
+
9
+ # Creating a function to perform predictions
10
+ def prediction(image: gr.Image = None,
11
+ image_size: gr.Slider = 640,
12
+ conf_threshold: gr.Slider = 0.4,
13
+ iou_threshold: gr.Slider = 0.50):
14
+
15
+ model = YOLO("best.pt")
16
+
17
+ results = model.predict(
18
+ source=image,
19
+ conf=conf_threshold,
20
+ iou=iou_threshold,
21
+ imgsz=image_size
22
+ )
23
+
24
+ image = cv2.imread(image)
25
+
26
+ for result in results[0].obb:
27
+ point_1_x = float(result.xyxyxyxy[0][0][0])
28
+ point_1_y = float(result.xyxyxyxy[0][0][1])
29
+ point_2_x = float(result.xyxyxyxy[0][1][0])
30
+ point_2_y = float(result.xyxyxyxy[0][1][1])
31
+ point_3_x = float(result.xyxyxyxy[0][2][0])
32
+ point_3_y = float(result.xyxyxyxy[0][2][1])
33
+ point_4_x = float(result.xyxyxyxy[0][3][0])
34
+ point_4_y = float(result.xyxyxyxy[0][3][1])
35
+
36
+ cls = int(result.cls)
37
+
38
+ if cls == 1:
39
+ color = (0, 255, 0)
40
+ else:
41
+ color = (255, 0, 0)
42
+
43
+ conf = float(result.conf)
44
+
45
+ text = f"{cls} : {np.round(conf) * 100}%"
46
+
47
+ points = np.array([[point_1_x, point_1_y],
48
+ [point_2_x, point_2_y],
49
+ [point_3_x, point_3_y],
50
+ [point_4_x, point_4_y]], np.int32)
51
+
52
+ points = points.reshape((-1, 1, 2))
53
+
54
+ cv2.polylines(image, [points], isClosed = True, color = color, thickness = 2)
55
+
56
+ return image
57
+
58
+ inputs = [
59
+ gr.Image(type="filepath", label="Select an image"),
60
+ gr.Slider(minimum=320, maximum=1280, value=640, step=32, label="Image Size"),
61
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.25, step=0.05, label="Confidence Threshold"),
62
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold")
63
+ ]
64
+
65
+ outputs = gr.Image(type = "filepath", label="Output Image")
66
+
67
+ yolo_app = gr.Interface(
68
+ fn = prediction,
69
+ inputs = inputs,
70
+ outputs = outputs,
71
+ title = "VPS Model"
72
+ )
73
+
74
+ yolo_app.launch(debug = True, share = True)
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e0fc4b78a2d09baa3a84fd7abbc981a963d31d3986c2cbcbdc0a7ab872c57e9a
3
+ size 6673154
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ gradio==4.31.5
2
+ matplotlib==3.7.2
3
+ numpy==1.24.3
4
+ opencv_python==4.7.0.72
5
+ opencv_python_headless==4.8.0.74
6
+ opencv_python_rolling==4.6.0.20220924
7
+ pandas==2.0.3
8
+ torch==2.1.2
9
+ ultralyticsplus==0.1.0