Spaces:
Running
on
Zero
Running
on
Zero
Upload 3 files
Browse filesUpdate YOLOv8 to YOLOv11
- detection_model.py +16 -15
- requirements.txt +1 -1
- ui_manager.py +9 -8
detection_model.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from ultralytics import YOLO
|
| 2 |
from typing import Any, List, Dict, Optional
|
| 3 |
import torch
|
|
@@ -5,36 +6,36 @@ import numpy as np
|
|
| 5 |
import os
|
| 6 |
|
| 7 |
class DetectionModel:
|
| 8 |
-
"""Core detection model class for object detection using
|
| 9 |
|
| 10 |
# Model information dictionary
|
| 11 |
MODEL_INFO = {
|
| 12 |
-
"
|
| 13 |
-
"name": "
|
| 14 |
-
"description": "Fastest model with smallest size (
|
| 15 |
-
"size_mb":
|
| 16 |
"inference_speed": "Very Fast"
|
| 17 |
},
|
| 18 |
-
"
|
| 19 |
-
"name": "
|
| 20 |
-
"description": "Balanced model with good accuracy-speed tradeoff (
|
| 21 |
-
"size_mb":
|
| 22 |
"inference_speed": "Medium"
|
| 23 |
},
|
| 24 |
-
"
|
| 25 |
-
"name": "
|
| 26 |
-
"description": "Most accurate but slower model (
|
| 27 |
-
"size_mb":
|
| 28 |
"inference_speed": "Slower"
|
| 29 |
}
|
| 30 |
}
|
| 31 |
|
| 32 |
-
def __init__(self, model_name: str = '
|
| 33 |
"""
|
| 34 |
Initialize the detection model
|
| 35 |
|
| 36 |
Args:
|
| 37 |
-
model_name: Model name or path, default is
|
| 38 |
confidence: Confidence threshold, default is 0.25
|
| 39 |
iou: IoU threshold for non-maximum suppression, default is 0.45
|
| 40 |
"""
|
|
|
|
| 1 |
+
# %%writefile detection_model.py
|
| 2 |
from ultralytics import YOLO
|
| 3 |
from typing import Any, List, Dict, Optional
|
| 4 |
import torch
|
|
|
|
| 6 |
import os
|
| 7 |
|
| 8 |
class DetectionModel:
|
| 9 |
+
"""Core detection model class for object detection using YOLOv11"""
|
| 10 |
|
| 11 |
# Model information dictionary
|
| 12 |
MODEL_INFO = {
|
| 13 |
+
"yolo11n.pt": {
|
| 14 |
+
"name": "YOLOv11n (Nano)",
|
| 15 |
+
"description": "Fastest model with smallest size (2.6M parameters). Best for speed-critical applications.",
|
| 16 |
+
"size_mb": 5,
|
| 17 |
"inference_speed": "Very Fast"
|
| 18 |
},
|
| 19 |
+
"yolo11m.pt": {
|
| 20 |
+
"name": "YOLOv11m (Medium)",
|
| 21 |
+
"description": "Balanced model with good accuracy-speed tradeoff (20.1M parameters). Recommended for general use.",
|
| 22 |
+
"size_mb": 20,
|
| 23 |
"inference_speed": "Medium"
|
| 24 |
},
|
| 25 |
+
"yolo11x.pt": {
|
| 26 |
+
"name": "YOLOv11x (XLarge)",
|
| 27 |
+
"description": "Most accurate but slower model (56.9M parameters). Best for accuracy-critical applications.",
|
| 28 |
+
"size_mb": 56,
|
| 29 |
"inference_speed": "Slower"
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
+
def __init__(self, model_name: str = 'yolo11m.pt', confidence: float = 0.25, iou: float = 0.25):
|
| 34 |
"""
|
| 35 |
Initialize the detection model
|
| 36 |
|
| 37 |
Args:
|
| 38 |
+
model_name: Model name or path, default is yolo11m.pt
|
| 39 |
confidence: Confidence threshold, default is 0.25
|
| 40 |
iou: IoU threshold for non-maximum suppression, default is 0.45
|
| 41 |
"""
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
torch>=2.0.0
|
| 2 |
torchvision>=0.15.0
|
| 3 |
-
ultralytics>=8.
|
| 4 |
opencv-python>=4.7.0
|
| 5 |
pillow>=9.4.0
|
| 6 |
numpy>=1.23.5
|
|
|
|
| 1 |
torch>=2.0.0
|
| 2 |
torchvision>=0.15.0
|
| 3 |
+
ultralytics>=8.3.0
|
| 4 |
opencv-python>=4.7.0
|
| 5 |
pillow>=9.4.0
|
| 6 |
numpy>=1.23.5
|
ui_manager.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from typing import Dict, List, Any, Optional, Tuple
|
| 3 |
import matplotlib.pyplot as plt
|
|
@@ -25,7 +26,7 @@ class UIManager:
|
|
| 25 |
self.model_choices = [model["model_file"] for model in self.available_models]
|
| 26 |
except ImportError:
|
| 27 |
# Fallback model choices if DetectionModel is not available
|
| 28 |
-
self.model_choices = ["
|
| 29 |
|
| 30 |
# Setup class choices
|
| 31 |
self.class_choices_formatted = [f"{id}: {name}" for id, name in self.get_all_classes()]
|
|
@@ -171,7 +172,7 @@ class UIManager:
|
|
| 171 |
return gr.HTML("""
|
| 172 |
<div class="footer" style="padding: 25px 0; text-align: center; background: linear-gradient(to right, #f5f9fc, #e1f5fe); border-top: 1px solid #e2e8f0; margin-top: 30px;">
|
| 173 |
<div style="margin-bottom: 15px;">
|
| 174 |
-
<p style="font-size: 14px; color: #4A5568; margin: 5px 0;">Powered by
|
| 175 |
</div>
|
| 176 |
<div style="display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 15px;">
|
| 177 |
<p style="font-family: 'Arial', sans-serif; font-size: 14px; font-weight: 500; letter-spacing: 2px; background: linear-gradient(90deg, #38b2ac, #4299e1); -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 0; text-transform: uppercase; display: inline-block;">EXPLORE THE CODE →</p>
|
|
@@ -192,7 +193,7 @@ class UIManager:
|
|
| 192 |
components = {}
|
| 193 |
|
| 194 |
with gr.Tab("Image Processing"):
|
| 195 |
-
components['current_image_model'] = gr.State("
|
| 196 |
|
| 197 |
with gr.Row(equal_height=False):
|
| 198 |
# Left Column: Image Input & Controls
|
|
@@ -208,13 +209,13 @@ class UIManager:
|
|
| 208 |
with gr.Accordion("Image Analysis Settings", open=False):
|
| 209 |
components['image_model_dropdown'] = gr.Dropdown(
|
| 210 |
choices=self.model_choices,
|
| 211 |
-
value="
|
| 212 |
label="Select Model",
|
| 213 |
info="Choose speed vs. accuracy (n=fast, m=balanced, x=accurate)"
|
| 214 |
)
|
| 215 |
|
| 216 |
components['image_model_info'] = gr.Markdown(
|
| 217 |
-
self.get_model_description("
|
| 218 |
)
|
| 219 |
|
| 220 |
components['image_confidence'] = gr.Slider(
|
|
@@ -451,7 +452,7 @@ class UIManager:
|
|
| 451 |
with gr.Accordion("Video Analysis Settings", open=True):
|
| 452 |
components['video_model_dropdown'] = gr.Dropdown(
|
| 453 |
choices=self.model_choices,
|
| 454 |
-
value="
|
| 455 |
label="Select Model (Video)",
|
| 456 |
info="Faster models (like 'n') are recommended for video processing"
|
| 457 |
)
|
|
@@ -491,7 +492,7 @@ class UIManager:
|
|
| 491 |
gr.Markdown("""
|
| 492 |
1. Choose your input method: Upload a file or enter a URL.
|
| 493 |
2. Adjust settings if needed:
|
| 494 |
-
* Use **faster models** (
|
| 495 |
* Set **larger intervals** (15+ frames) for longer videos
|
| 496 |
* Adjust **confidence threshold** to filter low-quality detections
|
| 497 |
3. Click "Analyze Video". **Processing time varies based on video length.**
|
|
@@ -499,7 +500,7 @@ class UIManager:
|
|
| 499 |
|
| 500 |
**⚡ Performance Tips:**
|
| 501 |
* For videos longer than 2 minutes, use interval ≥ 15 frames
|
| 502 |
-
*
|
| 503 |
* Higher confidence thresholds reduce processing noise
|
| 504 |
""")
|
| 505 |
|
|
|
|
| 1 |
+
# %%writefile ui_manager.py
|
| 2 |
import gradio as gr
|
| 3 |
from typing import Dict, List, Any, Optional, Tuple
|
| 4 |
import matplotlib.pyplot as plt
|
|
|
|
| 26 |
self.model_choices = [model["model_file"] for model in self.available_models]
|
| 27 |
except ImportError:
|
| 28 |
# Fallback model choices if DetectionModel is not available
|
| 29 |
+
self.model_choices = ["yolo11n.pt", "yolo11s.pt", "yolo11m.pt", "yolo11l.pt", "yolo11x.pt"]
|
| 30 |
|
| 31 |
# Setup class choices
|
| 32 |
self.class_choices_formatted = [f"{id}: {name}" for id, name in self.get_all_classes()]
|
|
|
|
| 172 |
return gr.HTML("""
|
| 173 |
<div class="footer" style="padding: 25px 0; text-align: center; background: linear-gradient(to right, #f5f9fc, #e1f5fe); border-top: 1px solid #e2e8f0; margin-top: 30px;">
|
| 174 |
<div style="margin-bottom: 15px;">
|
| 175 |
+
<p style="font-size: 14px; color: #4A5568; margin: 5px 0;">Powered by YOLOv11, CLIP, Places365, Meta Llama3.2 and Ultralytics • Enhanced Video Processing with Temporal Analysis • Created with Gradio</p>
|
| 176 |
</div>
|
| 177 |
<div style="display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 15px;">
|
| 178 |
<p style="font-family: 'Arial', sans-serif; font-size: 14px; font-weight: 500; letter-spacing: 2px; background: linear-gradient(90deg, #38b2ac, #4299e1); -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 0; text-transform: uppercase; display: inline-block;">EXPLORE THE CODE →</p>
|
|
|
|
| 193 |
components = {}
|
| 194 |
|
| 195 |
with gr.Tab("Image Processing"):
|
| 196 |
+
components['current_image_model'] = gr.State("yolo11m.pt")
|
| 197 |
|
| 198 |
with gr.Row(equal_height=False):
|
| 199 |
# Left Column: Image Input & Controls
|
|
|
|
| 209 |
with gr.Accordion("Image Analysis Settings", open=False):
|
| 210 |
components['image_model_dropdown'] = gr.Dropdown(
|
| 211 |
choices=self.model_choices,
|
| 212 |
+
value="yolo11m.pt",
|
| 213 |
label="Select Model",
|
| 214 |
info="Choose speed vs. accuracy (n=fast, m=balanced, x=accurate)"
|
| 215 |
)
|
| 216 |
|
| 217 |
components['image_model_info'] = gr.Markdown(
|
| 218 |
+
self.get_model_description("yolo11m.pt")
|
| 219 |
)
|
| 220 |
|
| 221 |
components['image_confidence'] = gr.Slider(
|
|
|
|
| 452 |
with gr.Accordion("Video Analysis Settings", open=True):
|
| 453 |
components['video_model_dropdown'] = gr.Dropdown(
|
| 454 |
choices=self.model_choices,
|
| 455 |
+
value="yolo11n.pt",
|
| 456 |
label="Select Model (Video)",
|
| 457 |
info="Faster models (like 'n') are recommended for video processing"
|
| 458 |
)
|
|
|
|
| 492 |
gr.Markdown("""
|
| 493 |
1. Choose your input method: Upload a file or enter a URL.
|
| 494 |
2. Adjust settings if needed:
|
| 495 |
+
* Use **faster models** (yolo11n) for quicker processing
|
| 496 |
* Set **larger intervals** (15+ frames) for longer videos
|
| 497 |
* Adjust **confidence threshold** to filter low-quality detections
|
| 498 |
3. Click "Analyze Video". **Processing time varies based on video length.**
|
|
|
|
| 500 |
|
| 501 |
**⚡ Performance Tips:**
|
| 502 |
* For videos longer than 2 minutes, use interval ≥ 15 frames
|
| 503 |
+
* YOLOv11n model provides best speed for video processing
|
| 504 |
* Higher confidence thresholds reduce processing noise
|
| 505 |
""")
|
| 506 |
|