dwkurnie commited on
Commit ·
92ce739
1
Parent(s): fa11d8c
- .gitignore +0 -1
- app.py +8 -6
- best.pt +3 -0
.gitignore
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
flagged/
|
| 2 |
-
*.pt
|
| 3 |
*.png
|
| 4 |
*.jpg
|
| 5 |
*.mp4
|
|
|
|
| 1 |
flagged/
|
|
|
|
| 2 |
*.png
|
| 3 |
*.jpg
|
| 4 |
*.mp4
|
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import cv2
|
|
| 3 |
from ultralytics import YOLO
|
| 4 |
|
| 5 |
# Load YOLO model
|
| 6 |
-
model = YOLO(
|
| 7 |
|
| 8 |
# Function to perform object detection on an image
|
| 9 |
def show_preds_image(image_path):
|
|
@@ -17,10 +17,11 @@ def show_preds_image(image_path):
|
|
| 17 |
(int(det[2]), int(det[3])),
|
| 18 |
color=(0, 0, 255),
|
| 19 |
thickness=2,
|
| 20 |
-
lineType=cv2.LINE_AA
|
| 21 |
)
|
| 22 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 23 |
|
|
|
|
| 24 |
# Define inputs and outputs for image interface
|
| 25 |
inputs_image = [
|
| 26 |
gr.inputs.Image(type="filepath", label="Input Image"),
|
|
@@ -35,10 +36,11 @@ interface_image = gr.Interface(
|
|
| 35 |
title="Garbage Detector (Image Input)",
|
| 36 |
)
|
| 37 |
|
|
|
|
| 38 |
# Function to perform object detection on a video stream
|
| 39 |
def show_preds_video(video_stream):
|
| 40 |
cap = cv2.VideoCapture(video_stream.name)
|
| 41 |
-
while
|
| 42 |
ret, frame = cap.read()
|
| 43 |
if ret:
|
| 44 |
frame_copy = frame.copy()
|
|
@@ -51,10 +53,11 @@ def show_preds_video(video_stream):
|
|
| 51 |
(int(det[2]), int(det[3])),
|
| 52 |
color=(0, 0, 255),
|
| 53 |
thickness=2,
|
| 54 |
-
lineType=cv2.LINE_AA
|
| 55 |
)
|
| 56 |
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
| 57 |
|
|
|
|
| 58 |
# Define inputs and outputs for video interface
|
| 59 |
inputs_video = [
|
| 60 |
gr.inputs.Video(type="webcam", label="Input Webcam"),
|
|
@@ -71,6 +74,5 @@ interface_video = gr.Interface(
|
|
| 71 |
|
| 72 |
# Launch tabbed interface for both image and video inference
|
| 73 |
gr.TabbedInterface(
|
| 74 |
-
[interface_image, interface_video],
|
| 75 |
-
tab_names=['Image Inference', 'Video Inference']
|
| 76 |
).launch()
|
|
|
|
| 3 |
from ultralytics import YOLO
|
| 4 |
|
| 5 |
# Load YOLO model
|
| 6 |
+
model = YOLO("best.pt")
|
| 7 |
|
| 8 |
# Function to perform object detection on an image
|
| 9 |
def show_preds_image(image_path):
|
|
|
|
| 17 |
(int(det[2]), int(det[3])),
|
| 18 |
color=(0, 0, 255),
|
| 19 |
thickness=2,
|
| 20 |
+
lineType=cv2.LINE_AA,
|
| 21 |
)
|
| 22 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 23 |
|
| 24 |
+
|
| 25 |
# Define inputs and outputs for image interface
|
| 26 |
inputs_image = [
|
| 27 |
gr.inputs.Image(type="filepath", label="Input Image"),
|
|
|
|
| 36 |
title="Garbage Detector (Image Input)",
|
| 37 |
)
|
| 38 |
|
| 39 |
+
|
| 40 |
# Function to perform object detection on a video stream
|
| 41 |
def show_preds_video(video_stream):
|
| 42 |
cap = cv2.VideoCapture(video_stream.name)
|
| 43 |
+
while cap.isOpened():
|
| 44 |
ret, frame = cap.read()
|
| 45 |
if ret:
|
| 46 |
frame_copy = frame.copy()
|
|
|
|
| 53 |
(int(det[2]), int(det[3])),
|
| 54 |
color=(0, 0, 255),
|
| 55 |
thickness=2,
|
| 56 |
+
lineType=cv2.LINE_AA,
|
| 57 |
)
|
| 58 |
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
| 59 |
|
| 60 |
+
|
| 61 |
# Define inputs and outputs for video interface
|
| 62 |
inputs_video = [
|
| 63 |
gr.inputs.Video(type="webcam", label="Input Webcam"),
|
|
|
|
| 74 |
|
| 75 |
# Launch tabbed interface for both image and video inference
|
| 76 |
gr.TabbedInterface(
|
| 77 |
+
[interface_image, interface_video], tab_names=["Image Inference", "Video Inference"]
|
|
|
|
| 78 |
).launch()
|
best.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2f688e18f683030746d48dacf9b60b198722205e3837afd5b2d26574f541a8f2
|
| 3 |
+
size 22520163
|