Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
-
import torch
|
| 4 |
import numpy as np
|
|
|
|
| 5 |
|
| 6 |
# Load the YOLOv5 model
|
| 7 |
-
model =
|
| 8 |
|
| 9 |
# Function to run inference on an image
|
| 10 |
def run_inference(image):
|
|
@@ -12,11 +12,10 @@ def run_inference(image):
|
|
| 12 |
image = np.array(image)
|
| 13 |
|
| 14 |
# Run YOLOv5 inference
|
| 15 |
-
results = model(image)
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
annotated_image = results.
|
| 19 |
-
annotated_image = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
| 20 |
|
| 21 |
return annotated_image
|
| 22 |
|
|
@@ -24,7 +23,7 @@ def run_inference(image):
|
|
| 24 |
interface = gr.Interface(
|
| 25 |
fn=run_inference,
|
| 26 |
inputs=gr.Image(type="pil"),
|
| 27 |
-
outputs=gr.Image(type="
|
| 28 |
title="YOLOv5 Object Detection",
|
| 29 |
description="Upload an image to run YOLOv5 object detection and see the results."
|
| 30 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
+
from ultralytics import YOLO # Import YOLO from ultralytics
|
| 5 |
|
| 6 |
# Load the YOLOv5 model
|
| 7 |
+
model = YOLO('yolov5s') # Use the YOLOv5s pre-trained model
|
| 8 |
|
| 9 |
# Function to run inference on an image
|
| 10 |
def run_inference(image):
|
|
|
|
| 12 |
image = np.array(image)
|
| 13 |
|
| 14 |
# Run YOLOv5 inference
|
| 15 |
+
results = model.predict(source=image, save=False, conf=0.25, stream=False)
|
| 16 |
|
| 17 |
+
# Annotate the image with detected objects
|
| 18 |
+
annotated_image = results[0].plot() # Use YOLO's built-in plotting function
|
|
|
|
| 19 |
|
| 20 |
return annotated_image
|
| 21 |
|
|
|
|
| 23 |
interface = gr.Interface(
|
| 24 |
fn=run_inference,
|
| 25 |
inputs=gr.Image(type="pil"),
|
| 26 |
+
outputs=gr.Image(type="numpy"),
|
| 27 |
title="YOLOv5 Object Detection",
|
| 28 |
description="Upload an image to run YOLOv5 object detection and see the results."
|
| 29 |
)
|