Spaces:
Sleeping
Sleeping
Commit
·
c298be5
1
Parent(s):
d41ea92
Added logging of images
Browse files
yolo-inference-project/src/app.py
CHANGED
@@ -5,13 +5,34 @@ from utils import draw_bounding_boxes
|
|
5 |
import time
|
6 |
import subprocess
|
7 |
import re
|
|
|
|
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
def get_model_names():
|
10 |
model_dir = "models" # Update this path to your models directory
|
11 |
return [f for f in os.listdir(model_dir) if f.endswith('.pt')] # Assuming models are in .pt format
|
12 |
|
13 |
model_names = get_model_names()
|
14 |
|
|
|
15 |
image_paths= [['examples/smaller_many_cans.jpg', 'yolo11m.pt', 0.5],
|
16 |
['examples/gazebo_all.jpg', 'yolo11m.pt', 0.5],
|
17 |
['examples/sequence_unity.jpg', 'yolo11m.pt', 0.5],
|
@@ -24,6 +45,7 @@ def inference(image, model_name, conf_thresh):
|
|
24 |
if not image:
|
25 |
raise gr.Error("No image provided. Please upload an image.")
|
26 |
|
|
|
27 |
model = load_model("models/" + model_name)
|
28 |
results = perform_inference(model, image)
|
29 |
output_image = draw_bounding_boxes(results, conf_thresh)
|
@@ -40,9 +62,13 @@ def inference(image, model_name, conf_thresh):
|
|
40 |
speed_str += "\nRunning on '" + proc_name + "'"
|
41 |
break
|
42 |
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
45 |
|
|
|
46 |
demo = gr.Interface(
|
47 |
fn=inference,
|
48 |
inputs=[
|
@@ -57,7 +83,7 @@ demo = gr.Interface(
|
|
57 |
title="YOLO Model Inference",
|
58 |
description="Select a YOLO model, upload an image, and set the confidence threshold to perform inference.",
|
59 |
examples=image_paths,
|
60 |
-
|
61 |
)
|
62 |
|
63 |
-
demo.launch()
|
|
|
5 |
import time
|
6 |
import subprocess
|
7 |
import re
|
8 |
+
from datetime import datetime
|
9 |
+
from roboflow import Roboflow
|
10 |
|
11 |
+
# Hugging Face Dataset configuration
|
12 |
+
HF_DATASET_NAME = "vincentb25/flagged-images" # Replace "username" with your HF username
|
13 |
+
PRIVATE_DATASET = False
|
14 |
+
|
15 |
+
# TODO get API KEY
|
16 |
+
rf = Roboflow(api_key=os.environ["ROBOFLOW_API_KEY"])
|
17 |
+
workspaceId = 'ezbot'
|
18 |
+
projectId = '2025'
|
19 |
+
project = rf.workspace(workspaceId).project(projectId)
|
20 |
+
|
21 |
+
|
22 |
+
def save_image_to_roboflow(image_path, model_name, conf_thresh):
|
23 |
+
"""Save flagged images to roboflow."""
|
24 |
+
|
25 |
+
project.upload(image_path)
|
26 |
+
|
27 |
+
|
28 |
+
# Load available models
|
29 |
def get_model_names():
|
30 |
model_dir = "models" # Update this path to your models directory
|
31 |
return [f for f in os.listdir(model_dir) if f.endswith('.pt')] # Assuming models are in .pt format
|
32 |
|
33 |
model_names = get_model_names()
|
34 |
|
35 |
+
# Sample images for testing
|
36 |
image_paths= [['examples/smaller_many_cans.jpg', 'yolo11m.pt', 0.5],
|
37 |
['examples/gazebo_all.jpg', 'yolo11m.pt', 0.5],
|
38 |
['examples/sequence_unity.jpg', 'yolo11m.pt', 0.5],
|
|
|
45 |
if not image:
|
46 |
raise gr.Error("No image provided. Please upload an image.")
|
47 |
|
48 |
+
# Perform inference
|
49 |
model = load_model("models/" + model_name)
|
50 |
results = perform_inference(model, image)
|
51 |
output_image = draw_bounding_boxes(results, conf_thresh)
|
|
|
62 |
speed_str += "\nRunning on '" + proc_name + "'"
|
63 |
break
|
64 |
|
65 |
+
# Save flagged image metadata
|
66 |
+
save_image_to_roboflow(image, model_name, conf_thresh)
|
67 |
+
print(f"Image flagged and saved: {image}")
|
68 |
+
|
69 |
+
return output_image, speed_str
|
70 |
|
71 |
+
# Define the Gradio app
|
72 |
demo = gr.Interface(
|
73 |
fn=inference,
|
74 |
inputs=[
|
|
|
83 |
title="YOLO Model Inference",
|
84 |
description="Select a YOLO model, upload an image, and set the confidence threshold to perform inference.",
|
85 |
examples=image_paths,
|
86 |
+
flagging_mode="auto" # Automatically flag all inputs
|
87 |
)
|
88 |
|
89 |
+
demo.launch()
|