cache
Browse files- .gradio/cached_examples/15/Detection Result/0f4a843e237f45cc683d/image.webp +0 -0
- .gradio/cached_examples/15/Detection Result/7a807e887e791a89cfd1/image.webp +0 -0
- .gradio/cached_examples/15/Detection Result/a4c35db755cee9e726ee/image.webp +0 -0
- .gradio/cached_examples/15/Detection Result/d9cd32cfeb6409958eea/image.webp +0 -0
- .gradio/cached_examples/15/indices.csv +4 -0
- .gradio/cached_examples/15/log.csv +33 -0
- app.py +35 -35
- models/YOLO-11-L.bin +3 -0
- models/YOLO-11-L.xml +0 -0
- models/YOLO-11-M.bin +3 -0
- models/YOLO-11-M.xml +0 -0
- models/{serialized.bin β YOLO-11-N.bin} +0 -0
- models/{serialized.xml β YOLO-11-N.xml} +0 -0
- models/YOLO-11-S.bin +3 -0
- models/YOLO-11-S.xml +0 -0
.gradio/cached_examples/15/Detection Result/0f4a843e237f45cc683d/image.webp
ADDED
|
.gradio/cached_examples/15/Detection Result/7a807e887e791a89cfd1/image.webp
ADDED
|
.gradio/cached_examples/15/Detection Result/a4c35db755cee9e726ee/image.webp
ADDED
|
.gradio/cached_examples/15/Detection Result/d9cd32cfeb6409958eea/image.webp
ADDED
|
.gradio/cached_examples/15/indices.csv
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
0
|
| 2 |
+
1
|
| 3 |
+
2
|
| 4 |
+
3
|
.gradio/cached_examples/15/log.csv
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Detection Result,Performance Metrics,timestamp
|
| 2 |
+
"{""path"": "".gradio/cached_examples/15/Detection Result/0f4a843e237f45cc683d/image.webp"", ""url"": ""/gradio_api/file=/tmp/gradio/ec172c8c5cac482f5cd3149cec4c95a810cd9bdd8b39676e261d8d2c04f6c692/image.webp"", ""size"": null, ""orig_name"": ""image.webp"", ""mime_type"": null, ""is_stream"": false, ""meta"": {""_type"": ""gradio.FileData""}}","π Preprocessing: 0.09 ms
|
| 3 |
+
βοΈ Inference: 94.41 ms
|
| 4 |
+
π Postprocessing: 1.14 ms
|
| 5 |
+
ββββββββββββββββββββββββββββββββββ
|
| 6 |
+
β±οΈ Total Time: 95.64 ms
|
| 7 |
+
π― FPS: 10.45
|
| 8 |
+
π Total Frames: 1
|
| 9 |
+
",2025-12-16 10:43:38.214724
|
| 10 |
+
"{""path"": "".gradio/cached_examples/15/Detection Result/7a807e887e791a89cfd1/image.webp"", ""url"": ""/gradio_api/file=/tmp/gradio/5a9f71131c8b6e743cff2071bd67257a6951a67aa00a87d95e1323704a5f2e13/image.webp"", ""size"": null, ""orig_name"": ""image.webp"", ""mime_type"": null, ""is_stream"": false, ""meta"": {""_type"": ""gradio.FileData""}}","π Preprocessing: 0.06 ms
|
| 11 |
+
βοΈ Inference: 98.54 ms
|
| 12 |
+
π Postprocessing: 1.08 ms
|
| 13 |
+
ββββββββββββββββββββββββββββββββββ
|
| 14 |
+
β±οΈ Total Time: 99.68 ms
|
| 15 |
+
π― FPS: 10.03
|
| 16 |
+
π Total Frames: 1
|
| 17 |
+
",2025-12-16 10:43:38.670276
|
| 18 |
+
"{""path"": "".gradio/cached_examples/15/Detection Result/d9cd32cfeb6409958eea/image.webp"", ""url"": ""/gradio_api/file=/tmp/gradio/9483b5797df1bb66cab99d79a6032e40cc372252e39d4041864c17c49b2cf05c/image.webp"", ""size"": null, ""orig_name"": ""image.webp"", ""mime_type"": null, ""is_stream"": false, ""meta"": {""_type"": ""gradio.FileData""}}","π Preprocessing: 0.05 ms
|
| 19 |
+
βοΈ Inference: 138.72 ms
|
| 20 |
+
π Postprocessing: 1.73 ms
|
| 21 |
+
ββββββββββββββββββββββββββββββββββ
|
| 22 |
+
β±οΈ Total Time: 140.51 ms
|
| 23 |
+
π― FPS: 7.12
|
| 24 |
+
π Total Frames: 1
|
| 25 |
+
",2025-12-16 10:43:39.262280
|
| 26 |
+
"{""path"": "".gradio/cached_examples/15/Detection Result/a4c35db755cee9e726ee/image.webp"", ""url"": ""/gradio_api/file=/tmp/gradio/3b4bac53ba462bf24dce5bb0407dd71d41b8c77d9b42d4eb616940880c432e12/image.webp"", ""size"": null, ""orig_name"": ""image.webp"", ""mime_type"": null, ""is_stream"": false, ""meta"": {""_type"": ""gradio.FileData""}}","π Preprocessing: 0.03 ms
|
| 27 |
+
βοΈ Inference: 57.13 ms
|
| 28 |
+
π Postprocessing: 0.08 ms
|
| 29 |
+
ββββββββββββββββββββββββββββββββββ
|
| 30 |
+
β±οΈ Total Time: 57.25 ms
|
| 31 |
+
π― FPS: 17.46
|
| 32 |
+
π Total Frames: 1
|
| 33 |
+
",2025-12-16 10:43:39.875985
|
app.py
CHANGED
|
@@ -42,28 +42,39 @@ def get_available_models():
|
|
| 42 |
return sorted(model_names)
|
| 43 |
|
| 44 |
|
| 45 |
-
def load_model(model_name: str, device: str = "CPU"):
|
| 46 |
"""
|
| 47 |
Load OpenVINO model using model_api.
|
| 48 |
|
| 49 |
Args:
|
| 50 |
model_name: Name of the model (without .xml extension)
|
| 51 |
device: Inference device (CPU, GPU, etc.)
|
|
|
|
| 52 |
|
| 53 |
Returns:
|
| 54 |
Model instance from model_api
|
| 55 |
"""
|
| 56 |
global current_model, current_model_name
|
| 57 |
-
|
| 58 |
-
return current_model
|
| 59 |
|
| 60 |
model_path = Path("models") / f"{model_name}.xml"
|
| 61 |
|
| 62 |
if not model_path.exists():
|
| 63 |
raise FileNotFoundError(f"Model not found: {model_path}")
|
| 64 |
|
| 65 |
-
print(f"Loading model: {model_name}")
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
model.get_performance_metrics().reset()
|
| 68 |
|
| 69 |
current_model = model
|
|
@@ -77,7 +88,7 @@ def run_inference(
|
|
| 77 |
image: np.ndarray,
|
| 78 |
model_name: str,
|
| 79 |
confidence_threshold: float
|
| 80 |
-
) -> Tuple[Image.Image, str
|
| 81 |
"""
|
| 82 |
Perform inference and return visualized result with metrics.
|
| 83 |
|
|
@@ -87,21 +98,20 @@ def run_inference(
|
|
| 87 |
confidence_threshold: Confidence threshold for filtering predictions
|
| 88 |
|
| 89 |
Returns:
|
| 90 |
-
Tuple of (visualized_image,
|
| 91 |
"""
|
| 92 |
# Input validation
|
| 93 |
if image is None:
|
| 94 |
-
return None, "β οΈ Please upload an image first."
|
| 95 |
|
| 96 |
if model_name is None or model_name == "No models available":
|
| 97 |
-
return None, "β οΈ No model selected or available."
|
| 98 |
|
| 99 |
try:
|
| 100 |
-
model = load_model(model_name)
|
| 101 |
|
| 102 |
# Run inference
|
| 103 |
result = model(image)
|
| 104 |
-
|
| 105 |
# Get performance metrics
|
| 106 |
metrics = model.get_performance_metrics()
|
| 107 |
inference_time = metrics.get_inference_time()
|
|
@@ -110,9 +120,7 @@ def run_inference(
|
|
| 110 |
fps = metrics.get_fps()
|
| 111 |
|
| 112 |
# Format metrics text
|
| 113 |
-
metrics_text = f"""
|
| 114 |
-
ββββββββββββββββββββββββββββββββββ
|
| 115 |
-
π Preprocessing: {preprocess_time.mean()*1000:.2f} ms
|
| 116 |
βοΈ Inference: {inference_time.mean()*1000:.2f} ms
|
| 117 |
π Postprocessing: {postprocess_time.mean()*1000:.2f} ms
|
| 118 |
ββββββββββββββββββββββββββββββββββ
|
|
@@ -121,17 +129,15 @@ def run_inference(
|
|
| 121 |
π Total Frames: {inference_time.count}
|
| 122 |
"""
|
| 123 |
|
| 124 |
-
# Format results based on model type
|
| 125 |
-
results_text = format_results(result, confidence_threshold)
|
| 126 |
-
|
| 127 |
# Visualize results using model_api's visualizer
|
|
|
|
| 128 |
visualized_image = visualizer.render(image, result)
|
| 129 |
|
| 130 |
-
return visualized_image, metrics_text
|
| 131 |
|
| 132 |
except Exception as e:
|
| 133 |
error_msg = f"Error during inference: {str(e)}"
|
| 134 |
-
return None, error_msg
|
| 135 |
|
| 136 |
|
| 137 |
def format_results(result, confidence_threshold: float) -> str:
|
|
@@ -206,9 +212,9 @@ def create_gradio_interface():
|
|
| 206 |
print("Warning: No models found in models/ folder")
|
| 207 |
available_models = ["No models available"]
|
| 208 |
|
| 209 |
-
with gr.Blocks(title="
|
| 210 |
-
gr.Markdown("# π―
|
| 211 |
-
gr.Markdown("
|
| 212 |
|
| 213 |
with gr.Row():
|
| 214 |
with gr.Column(scale=1):
|
|
@@ -244,12 +250,6 @@ def create_gradio_interface():
|
|
| 244 |
height=400
|
| 245 |
)
|
| 246 |
|
| 247 |
-
detections_output = gr.Textbox(
|
| 248 |
-
label="Detected Objects",
|
| 249 |
-
lines=8,
|
| 250 |
-
max_lines=15
|
| 251 |
-
)
|
| 252 |
-
|
| 253 |
metrics_output = gr.Textbox(
|
| 254 |
label="Performance Metrics",
|
| 255 |
lines=8,
|
|
@@ -260,22 +260,22 @@ def create_gradio_interface():
|
|
| 260 |
gr.Markdown("## πΈ Examples")
|
| 261 |
gr.Examples(
|
| 262 |
examples=[
|
| 263 |
-
["examples/vehicles.png", "
|
| 264 |
-
["examples/dog.jpg", "
|
| 265 |
-
["examples/people-walking.png", "
|
| 266 |
-
["examples/zidane.jpg", "
|
| 267 |
],
|
| 268 |
inputs=[input_image, model_dropdown, confidence_slider],
|
| 269 |
-
outputs=[output_image,
|
| 270 |
fn=run_inference,
|
| 271 |
-
cache_examples=
|
| 272 |
)
|
| 273 |
|
| 274 |
# Connect the button to the inference function
|
| 275 |
classify_btn.click(
|
| 276 |
fn=run_inference,
|
| 277 |
inputs=[input_image, model_dropdown, confidence_slider],
|
| 278 |
-
outputs=[output_image,
|
| 279 |
)
|
| 280 |
|
| 281 |
return demo
|
|
|
|
| 42 |
return sorted(model_names)
|
| 43 |
|
| 44 |
|
| 45 |
+
def load_model(model_name: str, device: str = "CPU", confidence_threshold: float = 0.3):
|
| 46 |
"""
|
| 47 |
Load OpenVINO model using model_api.
|
| 48 |
|
| 49 |
Args:
|
| 50 |
model_name: Name of the model (without .xml extension)
|
| 51 |
device: Inference device (CPU, GPU, etc.)
|
| 52 |
+
confidence_threshold: Confidence threshold for predictions
|
| 53 |
|
| 54 |
Returns:
|
| 55 |
Model instance from model_api
|
| 56 |
"""
|
| 57 |
global current_model, current_model_name
|
| 58 |
+
# Always reload model to apply new confidence threshold
|
|
|
|
| 59 |
|
| 60 |
model_path = Path("models") / f"{model_name}.xml"
|
| 61 |
|
| 62 |
if not model_path.exists():
|
| 63 |
raise FileNotFoundError(f"Model not found: {model_path}")
|
| 64 |
|
| 65 |
+
print(f"Loading model: {model_name} with confidence threshold: {confidence_threshold}")
|
| 66 |
+
|
| 67 |
+
# Set configuration based on model type
|
| 68 |
+
configuration = {}
|
| 69 |
+
if "YOLO" in model_name.upper():
|
| 70 |
+
# YOLO models use confidence_threshold and iou_threshold
|
| 71 |
+
configuration["confidence_threshold"] = confidence_threshold
|
| 72 |
+
configuration["iou_threshold"] = 0.5 # Standard IoU threshold for NMS
|
| 73 |
+
else:
|
| 74 |
+
# Other detection models typically use CONFIDENCE_THRESHOLD
|
| 75 |
+
configuration["confidence_threshold"] = confidence_threshold
|
| 76 |
+
|
| 77 |
+
model = Model.create_model(str(model_path), device=device, configuration=configuration)
|
| 78 |
model.get_performance_metrics().reset()
|
| 79 |
|
| 80 |
current_model = model
|
|
|
|
| 88 |
image: np.ndarray,
|
| 89 |
model_name: str,
|
| 90 |
confidence_threshold: float
|
| 91 |
+
) -> Tuple[Image.Image, str]:
|
| 92 |
"""
|
| 93 |
Perform inference and return visualized result with metrics.
|
| 94 |
|
|
|
|
| 98 |
confidence_threshold: Confidence threshold for filtering predictions
|
| 99 |
|
| 100 |
Returns:
|
| 101 |
+
Tuple of (visualized_image, metrics_text)
|
| 102 |
"""
|
| 103 |
# Input validation
|
| 104 |
if image is None:
|
| 105 |
+
return None, "β οΈ Please upload an image first."
|
| 106 |
|
| 107 |
if model_name is None or model_name == "No models available":
|
| 108 |
+
return None, "β οΈ No model selected or available."
|
| 109 |
|
| 110 |
try:
|
| 111 |
+
model = load_model(model_name, confidence_threshold=confidence_threshold)
|
| 112 |
|
| 113 |
# Run inference
|
| 114 |
result = model(image)
|
|
|
|
| 115 |
# Get performance metrics
|
| 116 |
metrics = model.get_performance_metrics()
|
| 117 |
inference_time = metrics.get_inference_time()
|
|
|
|
| 120 |
fps = metrics.get_fps()
|
| 121 |
|
| 122 |
# Format metrics text
|
| 123 |
+
metrics_text = f"""π Preprocessing: {preprocess_time.mean()*1000:.2f} ms
|
|
|
|
|
|
|
| 124 |
βοΈ Inference: {inference_time.mean()*1000:.2f} ms
|
| 125 |
π Postprocessing: {postprocess_time.mean()*1000:.2f} ms
|
| 126 |
ββββββββββββββββββββββββββββββββββ
|
|
|
|
| 129 |
π Total Frames: {inference_time.count}
|
| 130 |
"""
|
| 131 |
|
|
|
|
|
|
|
|
|
|
| 132 |
# Visualize results using model_api's visualizer
|
| 133 |
+
print(f"Visualizing results with confidence threshold: {confidence_threshold}")
|
| 134 |
visualized_image = visualizer.render(image, result)
|
| 135 |
|
| 136 |
+
return visualized_image, metrics_text
|
| 137 |
|
| 138 |
except Exception as e:
|
| 139 |
error_msg = f"Error during inference: {str(e)}"
|
| 140 |
+
return None, error_msg
|
| 141 |
|
| 142 |
|
| 143 |
def format_results(result, confidence_threshold: float) -> str:
|
|
|
|
| 212 |
print("Warning: No models found in models/ folder")
|
| 213 |
available_models = ["No models available"]
|
| 214 |
|
| 215 |
+
with gr.Blocks(title="OpenVINO with model_api") as demo:
|
| 216 |
+
gr.Markdown("# π― OpenVINO with model_api")
|
| 217 |
+
gr.Markdown("Experience high-performance object detection powered by **OpenVINOβ’** and **model_api**. See real-time inference with detailed performance metrics.")
|
| 218 |
|
| 219 |
with gr.Row():
|
| 220 |
with gr.Column(scale=1):
|
|
|
|
| 250 |
height=400
|
| 251 |
)
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
metrics_output = gr.Textbox(
|
| 254 |
label="Performance Metrics",
|
| 255 |
lines=8,
|
|
|
|
| 260 |
gr.Markdown("## πΈ Examples")
|
| 261 |
gr.Examples(
|
| 262 |
examples=[
|
| 263 |
+
["examples/vehicles.png", "YOLO-11-N" if "YOLO-11-N" in available_models else available_models[0], 0.5],
|
| 264 |
+
["examples/dog.jpg", "YOLO-11-S" if "YOLO-11-S" in available_models else available_models[0], 0.6],
|
| 265 |
+
["examples/people-walking.png", "YOLO-11-M" if "YOLO-11-M" in available_models else available_models[0], 0.3],
|
| 266 |
+
["examples/zidane.jpg", "resnet50" if "resnet50" in available_models else available_models[0], 0.5],
|
| 267 |
],
|
| 268 |
inputs=[input_image, model_dropdown, confidence_slider],
|
| 269 |
+
outputs=[output_image, metrics_output],
|
| 270 |
fn=run_inference,
|
| 271 |
+
cache_examples=True
|
| 272 |
)
|
| 273 |
|
| 274 |
# Connect the button to the inference function
|
| 275 |
classify_btn.click(
|
| 276 |
fn=run_inference,
|
| 277 |
inputs=[input_image, model_dropdown, confidence_slider],
|
| 278 |
+
outputs=[output_image, metrics_output]
|
| 279 |
)
|
| 280 |
|
| 281 |
return demo
|
models/YOLO-11-L.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f9256465f36a4ab2eb25b290575aecb15ae2832776790f7a4148a3daff5c1369
|
| 3 |
+
size 101465149
|
models/YOLO-11-L.xml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
models/YOLO-11-M.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5cca976c16d0848a09c4ed98b2703cf2020ea622bbd1b364e95b9dbaf6ab246b
|
| 3 |
+
size 80468029
|
models/YOLO-11-M.xml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
models/{serialized.bin β YOLO-11-N.bin}
RENAMED
|
File without changes
|
models/{serialized.xml β YOLO-11-N.xml}
RENAMED
|
File without changes
|
models/YOLO-11-S.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:39aac0b1bf65a540fdf961523cbecce68531185b344459e45cc493e63defe1b5
|
| 3 |
+
size 37876237
|
models/YOLO-11-S.xml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|