Spaces:
Sleeping
Sleeping
Upload 9 files
Browse files- .gitattributes +1 -0
- yolo11/Trial.ipynb +356 -0
- yolo11/keypoints-order-ultralytics-yolov8-pose.jpg +0 -0
- yolo11/v8pose.png +3 -0
- yolo11/yolo11m-pose.pt +3 -0
- yolo11/yolo11n-pose.onnx +3 -0
- yolo11/yolo11n-pose.pt +3 -0
- yolo11/yolo11n.pt +3 -0
- yolo11/yolov5s.pt +3 -0
- yolo11/yolov8n-pose.pt +3 -0
.gitattributes
CHANGED
@@ -43,3 +43,4 @@ videos/David_PopUp2Reps.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
43 |
videos/Popup1.png filter=lfs diff=lfs merge=lfs -text
|
44 |
videos/PopUp1Rep.mp4 filter=lfs diff=lfs merge=lfs -text
|
45 |
videos/PopUp1RepFacingLeft.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
43 |
videos/Popup1.png filter=lfs diff=lfs merge=lfs -text
|
44 |
videos/PopUp1Rep.mp4 filter=lfs diff=lfs merge=lfs -text
|
45 |
videos/PopUp1RepFacingLeft.mp4 filter=lfs diff=lfs merge=lfs -text
|
46 |
+
yolo11/v8pose.png filter=lfs diff=lfs merge=lfs -text
|
yolo11/Trial.ipynb
ADDED
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"* Running on local URL: http://127.0.0.1:7863\n",
|
13 |
+
"\n",
|
14 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
15 |
+
]
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"data": {
|
19 |
+
"text/html": [
|
20 |
+
"<div><iframe src=\"http://127.0.0.1:7863/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
21 |
+
],
|
22 |
+
"text/plain": [
|
23 |
+
"<IPython.core.display.HTML object>"
|
24 |
+
]
|
25 |
+
},
|
26 |
+
"metadata": {},
|
27 |
+
"output_type": "display_data"
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"data": {
|
31 |
+
"text/plain": []
|
32 |
+
},
|
33 |
+
"execution_count": 3,
|
34 |
+
"metadata": {},
|
35 |
+
"output_type": "execute_result"
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"name": "stdout",
|
39 |
+
"output_type": "stream",
|
40 |
+
"text": [
|
41 |
+
"\n",
|
42 |
+
"0: 448x640 1 person, 73.4ms\n",
|
43 |
+
"Speed: 6.0ms preprocess, 73.4ms inference, 3.8ms postprocess per image at shape (1, 3, 448, 640)\n"
|
44 |
+
]
|
45 |
+
},
|
46 |
+
{
|
47 |
+
"name": "stderr",
|
48 |
+
"output_type": "stream",
|
49 |
+
"text": [
|
50 |
+
"Traceback (most recent call last):\n",
|
51 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\gradio\\queueing.py\", line 625, in process_events\n",
|
52 |
+
" response = await route_utils.call_process_api(\n",
|
53 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
54 |
+
" ...<5 lines>...\n",
|
55 |
+
" )\n",
|
56 |
+
" ^\n",
|
57 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\gradio\\route_utils.py\", line 322, in call_process_api\n",
|
58 |
+
" output = await app.get_blocks().process_api(\n",
|
59 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
60 |
+
" ...<11 lines>...\n",
|
61 |
+
" )\n",
|
62 |
+
" ^\n",
|
63 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\gradio\\blocks.py\", line 2098, in process_api\n",
|
64 |
+
" result = await self.call_function(\n",
|
65 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
66 |
+
" ...<8 lines>...\n",
|
67 |
+
" )\n",
|
68 |
+
" ^\n",
|
69 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\gradio\\blocks.py\", line 1645, in call_function\n",
|
70 |
+
" prediction = await anyio.to_thread.run_sync( # type: ignore\n",
|
71 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
72 |
+
" fn, *processed_input, limiter=self.limiter\n",
|
73 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
74 |
+
" )\n",
|
75 |
+
" ^\n",
|
76 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\anyio\\to_thread.py\", line 56, in run_sync\n",
|
77 |
+
" return await get_async_backend().run_sync_in_worker_thread(\n",
|
78 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
79 |
+
" func, args, abandon_on_cancel=abandon_on_cancel, limiter=limiter\n",
|
80 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
81 |
+
" )\n",
|
82 |
+
" ^\n",
|
83 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 2461, in run_sync_in_worker_thread\n",
|
84 |
+
" return await future\n",
|
85 |
+
" ^^^^^^^^^^^^\n",
|
86 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 962, in run\n",
|
87 |
+
" result = context.run(func, *args)\n",
|
88 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\gradio\\utils.py\", line 883, in wrapper\n",
|
89 |
+
" response = f(*args, **kwargs)\n",
|
90 |
+
" File \"C:\\Users\\Owner\\AppData\\Local\\Temp\\ipykernel_31136\\1222528933.py\", line 183, in <lambda>\n",
|
91 |
+
" fn=lambda input_video: process_video(input_video) if input_video else (\"\", []),\n",
|
92 |
+
" ~~~~~~~~~~~~~^^^^^^^^^^^^^\n",
|
93 |
+
" File \"C:\\Users\\Owner\\AppData\\Local\\Temp\\ipykernel_31136\\1222528933.py\", line 81, in process_video\n",
|
94 |
+
" writer = imageio.get_writer(output_video_path, fps=fps, codec=\"libx264\")\n",
|
95 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\imageio\\v2.py\", line 324, in get_writer\n",
|
96 |
+
" image_file = imopen(uri, \"w\" + mode, **imopen_args)\n",
|
97 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\imageio\\core\\imopen.py\", line 113, in imopen\n",
|
98 |
+
" request = Request(uri, io_mode, format_hint=format_hint, extension=extension)\n",
|
99 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\imageio\\core\\request.py\", line 249, in __init__\n",
|
100 |
+
" self._parse_uri(uri)\n",
|
101 |
+
" ~~~~~~~~~~~~~~~^^^^^\n",
|
102 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\imageio\\core\\request.py\", line 414, in _parse_uri\n",
|
103 |
+
" raise FileNotFoundError(\"The directory %r does not exist\" % dn)\n",
|
104 |
+
"FileNotFoundError: The directory 'e:\\\\content\\\\drive\\\\MyDrive\\\\Computer Vision YOLO-Judol Detection' does not exist\n",
|
105 |
+
"Traceback (most recent call last):\n",
|
106 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\gradio\\queueing.py\", line 625, in process_events\n",
|
107 |
+
" response = await route_utils.call_process_api(\n",
|
108 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
109 |
+
" ...<5 lines>...\n",
|
110 |
+
" )\n",
|
111 |
+
" ^\n",
|
112 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\gradio\\route_utils.py\", line 322, in call_process_api\n",
|
113 |
+
" output = await app.get_blocks().process_api(\n",
|
114 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
115 |
+
" ...<11 lines>...\n",
|
116 |
+
" )\n",
|
117 |
+
" ^\n",
|
118 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\gradio\\blocks.py\", line 2108, in process_api\n",
|
119 |
+
" data = await self.postprocess_data(block_fn, result[\"prediction\"], state)\n",
|
120 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
121 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\gradio\\blocks.py\", line 1914, in postprocess_data\n",
|
122 |
+
" prediction_value = block.postprocess(prediction_value)\n",
|
123 |
+
" File \"e:\\Steven's Files\\Work\\Reserves\\Python Coding\\Pop-Up Trainer\\Pop_Up_Trainer\\2025014_PopUp_Clean\\.venv\\Lib\\site-packages\\gradio\\components\\video.py\", line 293, in postprocess\n",
|
124 |
+
" raise TypeError(\n",
|
125 |
+
" f\"If a tuple is provided, both elements must be strings or Path objects. Received: {value}\"\n",
|
126 |
+
" )\n",
|
127 |
+
"TypeError: If a tuple is provided, both elements must be strings or Path objects. Received: ('', [])\n"
|
128 |
+
]
|
129 |
+
}
|
130 |
+
],
|
131 |
+
"source": [
|
132 |
+
"# -*- coding: utf-8 -*-\n",
|
133 |
+
"\"\"\"Judol Gradio YOLO11.ipynb\n",
|
134 |
+
"Automatically generated by Colab.\n",
|
135 |
+
"Original file is located at\n",
|
136 |
+
" https://colab.research.google.com/drive/1oiuTAi-cys1ydtUhSDJSRdeA02mAmZQH\n",
|
137 |
+
" https://huggingface.co/JrEasy/Judol-Detection-YOLO11/blob/main/judol_gradio_yolo11.py\n",
|
138 |
+
"\"\"\"\n",
|
139 |
+
"\n",
|
140 |
+
"#!pip install ultralytics\n",
|
141 |
+
"#!pip install gradio\n",
|
142 |
+
"\n",
|
143 |
+
"import cv2\n",
|
144 |
+
"from ultralytics import YOLO\n",
|
145 |
+
"import gradio as gr\n",
|
146 |
+
"import imageio\n",
|
147 |
+
"#from google.colab import drive\n",
|
148 |
+
"\n",
|
149 |
+
"#model = YOLO('https://huggingface.co/JrEasy/Judol-Detection-YOLO11/resolve/main/best.pt')\n",
|
150 |
+
"model = YOLO(\"yolo11/yolo11n-pose.pt\")\n",
|
151 |
+
"\n",
|
152 |
+
"confidence_threshold = 0.5\n",
|
153 |
+
"\n",
|
154 |
+
"class_names = {\n",
|
155 |
+
" 0: \"BK8\",\n",
|
156 |
+
" 1: \"Gate of Olympus\",\n",
|
157 |
+
" 2: \"Princess\",\n",
|
158 |
+
" 3: \"Starlight Princess\",\n",
|
159 |
+
" 4: \"Zeus\",\n",
|
160 |
+
"}\n",
|
161 |
+
"\n",
|
162 |
+
"class_colors = {\n",
|
163 |
+
" 0: (0, 255, 0), # Green for BK8\n",
|
164 |
+
" 1: (255, 0, 0), # Blue for Gate of Olympus\n",
|
165 |
+
" 2: (0, 0, 255), # Red for Princess\n",
|
166 |
+
" 3: (255, 255, 0), # Cyan for Starlight Princess\n",
|
167 |
+
" 4: (255, 0, 255), # Magenta for Zeus\n",
|
168 |
+
"}\n",
|
169 |
+
"\n",
|
170 |
+
"def format_time_ranges(timestamps, classes):\n",
|
171 |
+
"\n",
|
172 |
+
" if not timestamps:\n",
|
173 |
+
" return \"\"\n",
|
174 |
+
"\n",
|
175 |
+
"\n",
|
176 |
+
" class_timestamps = {}\n",
|
177 |
+
"\n",
|
178 |
+
" for timestamp, class_id in zip(timestamps, classes):\n",
|
179 |
+
" class_name = class_names.get(class_id, 'Unknown')\n",
|
180 |
+
" if class_name not in class_timestamps:\n",
|
181 |
+
" class_timestamps[class_name] = []\n",
|
182 |
+
" class_timestamps[class_name].append(timestamp)\n",
|
183 |
+
"\n",
|
184 |
+
"\n",
|
185 |
+
" formatted_ranges = []\n",
|
186 |
+
"\n",
|
187 |
+
" for class_name, timestamps in class_timestamps.items():\n",
|
188 |
+
" timestamps = sorted(timestamps)\n",
|
189 |
+
" ranges = []\n",
|
190 |
+
" start = timestamps[0]\n",
|
191 |
+
" for i in range(1, len(timestamps)):\n",
|
192 |
+
" if timestamps[i] - timestamps[i - 1] <= 1:\n",
|
193 |
+
" continue\n",
|
194 |
+
" else:\n",
|
195 |
+
" ranges.append(f\"{int(start)}-{int(timestamps[i - 1])}\")\n",
|
196 |
+
" start = timestamps[i]\n",
|
197 |
+
"\n",
|
198 |
+
" ranges.append(f\"{int(start)}-{int(timestamps[-1])}\")\n",
|
199 |
+
"\n",
|
200 |
+
" formatted_ranges.append(f\"{class_name} = {', '.join(ranges)}\")\n",
|
201 |
+
"\n",
|
202 |
+
" return \", \".join(formatted_ranges)\n",
|
203 |
+
"\n",
|
204 |
+
"def process_video(input_video):\n",
|
205 |
+
" cap = cv2.VideoCapture(input_video)\n",
|
206 |
+
" if not cap.isOpened():\n",
|
207 |
+
" print(\"Error: Could not open input video.\")\n",
|
208 |
+
" return None, []\n",
|
209 |
+
"\n",
|
210 |
+
" fps = cap.get(cv2.CAP_PROP_FPS)\n",
|
211 |
+
" output_video_path = \"/content/drive/MyDrive/Computer Vision YOLO-Judol Detection/processed_video.mp4\"\n",
|
212 |
+
" writer = imageio.get_writer(output_video_path, fps=fps, codec=\"libx264\")\n",
|
213 |
+
"\n",
|
214 |
+
" frame_count = 0\n",
|
215 |
+
" timestamps = []\n",
|
216 |
+
" classes_detected = []\n",
|
217 |
+
"\n",
|
218 |
+
" while cap.isOpened():\n",
|
219 |
+
" ret, frame = cap.read()\n",
|
220 |
+
" if not ret:\n",
|
221 |
+
" break\n",
|
222 |
+
"\n",
|
223 |
+
" timestamp = frame_count / fps\n",
|
224 |
+
" frame_count += 1\n",
|
225 |
+
"\n",
|
226 |
+
" gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n",
|
227 |
+
" input_frame = cv2.merge([gray_frame, gray_frame, gray_frame])\n",
|
228 |
+
"\n",
|
229 |
+
" results = model.predict(input_frame)\n",
|
230 |
+
"\n",
|
231 |
+
" for result in results:\n",
|
232 |
+
" for box in result.boxes:\n",
|
233 |
+
" if box.conf[0] >= confidence_threshold:\n",
|
234 |
+
" x1, y1, x2, y2 = map(int, box.xyxy[0])\n",
|
235 |
+
" class_id = int(box.cls[0])\n",
|
236 |
+
" class_name = class_names.get(class_id, f\"Class {class_id}\")\n",
|
237 |
+
" color = class_colors.get(class_id, (0, 255, 0))\n",
|
238 |
+
" cv2.rectangle(frame, (x1, y1), (x2, y2), color, 2)\n",
|
239 |
+
" text = f'{class_name}, Conf: {box.conf[0]:.2f}'\n",
|
240 |
+
" text_position = (x1, y1 - 10 if y1 > 20 else y1 + 20)\n",
|
241 |
+
" cv2.putText(frame, text, text_position, cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)\n",
|
242 |
+
"\n",
|
243 |
+
" timestamps.append(timestamp)\n",
|
244 |
+
" classes_detected.append(class_id)\n",
|
245 |
+
"\n",
|
246 |
+
" writer.append_data(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))\n",
|
247 |
+
"\n",
|
248 |
+
" cap.release()\n",
|
249 |
+
" writer.close()\n",
|
250 |
+
"\n",
|
251 |
+
"\n",
|
252 |
+
" formatted_time_ranges = format_time_ranges(timestamps, classes_detected)\n",
|
253 |
+
"\n",
|
254 |
+
" print(f\"Processed video saved at: {output_video_path}\")\n",
|
255 |
+
"\n",
|
256 |
+
" return output_video_path, formatted_time_ranges\n",
|
257 |
+
"\n",
|
258 |
+
"\n",
|
259 |
+
"def process_image(input_image):\n",
|
260 |
+
" # Convert image from RGB to BGR for OpenCV processing\n",
|
261 |
+
" bgr_frame = cv2.cvtColor(input_image, cv2.COLOR_RGB2BGR)\n",
|
262 |
+
"\n",
|
263 |
+
" # Convert to grayscale and create a 3-channel grayscale image\n",
|
264 |
+
" gray_frame = cv2.cvtColor(bgr_frame, cv2.COLOR_BGR2GRAY)\n",
|
265 |
+
" input_frame = cv2.merge([gray_frame, gray_frame, gray_frame])\n",
|
266 |
+
"\n",
|
267 |
+
" # Run the model on the processed input\n",
|
268 |
+
" results = model.predict(input_frame)\n",
|
269 |
+
"\n",
|
270 |
+
" detections_log = [] # Store detection logs\n",
|
271 |
+
" classes_detected = [] # Track detected class IDs\n",
|
272 |
+
"\n",
|
273 |
+
" for result in results:\n",
|
274 |
+
" for box in result.boxes:\n",
|
275 |
+
" if box.conf[0] >= confidence_threshold: # Filter by confidence\n",
|
276 |
+
" x1, y1, x2, y2 = map(int, box.xyxy[0]) # Bounding box coordinates\n",
|
277 |
+
" class_id = int(box.cls[0]) # Class ID\n",
|
278 |
+
" class_name = class_names.get(class_id, f\"Class {class_id}\")\n",
|
279 |
+
" color = class_colors.get(class_id, (0, 255, 0)) # Default green color\n",
|
280 |
+
"\n",
|
281 |
+
" # Draw bounding box and class text on the frame\n",
|
282 |
+
" cv2.rectangle(bgr_frame, (x1, y1), (x2, y2), color, 2)\n",
|
283 |
+
" text = f'{class_name}, Conf: {box.conf[0]:.2f}'\n",
|
284 |
+
" text_position = (x1, y1 - 10 if y1 > 20 else y1 + 20)\n",
|
285 |
+
" cv2.putText(bgr_frame, text, text_position, cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)\n",
|
286 |
+
"\n",
|
287 |
+
" # Log detection information\n",
|
288 |
+
" detections_log.append({\n",
|
289 |
+
" \"class\": class_name,\n",
|
290 |
+
" \"confidence\": box.conf[0]\n",
|
291 |
+
" })\n",
|
292 |
+
" classes_detected.append(class_id)\n",
|
293 |
+
"\n",
|
294 |
+
" # Count occurrences of each class detected\n",
|
295 |
+
" class_count = {class_names.get(cls, f\"Class {cls}\"): classes_detected.count(cls) for cls in set(classes_detected)}\n",
|
296 |
+
"\n",
|
297 |
+
" # Format the detections as 'Class = Count' pairs\n",
|
298 |
+
" formatted_log = \", \".join([f\"{class_name} = {count}\" for class_name, count in class_count.items()])\n",
|
299 |
+
"\n",
|
300 |
+
" # Convert the output frame back to RGB\n",
|
301 |
+
" output_image = cv2.cvtColor(bgr_frame, cv2.COLOR_BGR2RGB)\n",
|
302 |
+
" return output_image, formatted_log\n",
|
303 |
+
"\n",
|
304 |
+
"with gr.Blocks() as app:\n",
|
305 |
+
" gr.Markdown(\"## Judol Detection using YOLOv11\")\n",
|
306 |
+
"\n",
|
307 |
+
" with gr.Tab(\"Video Detection\"):\n",
|
308 |
+
" with gr.Row():\n",
|
309 |
+
" input_video = gr.Video(label=\"Upload a video\")\n",
|
310 |
+
" output_video = gr.Video(label=\"Processed Video\")\n",
|
311 |
+
" detections_log = gr.Textbox(label=\"Detections Log\", lines=10)\n",
|
312 |
+
"\n",
|
313 |
+
" input_video.change(\n",
|
314 |
+
" fn=lambda input_video: process_video(input_video) if input_video else (\"\", []),\n",
|
315 |
+
" inputs=input_video,\n",
|
316 |
+
" outputs=[output_video],\n",
|
317 |
+
" )\n",
|
318 |
+
"\n",
|
319 |
+
" with gr.Tab(\"Image Detection\"):\n",
|
320 |
+
" with gr.Row():\n",
|
321 |
+
" input_image = gr.Image(label=\"Upload an image\")\n",
|
322 |
+
" output_image = gr.Image(label=\"Processed Image\")\n",
|
323 |
+
" image_detections_log = gr.Textbox(label=\"Detections Log\", lines=10)\n",
|
324 |
+
"\n",
|
325 |
+
" input_image.change(\n",
|
326 |
+
" fn=process_image,\n",
|
327 |
+
" inputs=input_image,\n",
|
328 |
+
" outputs=[output_image, image_detections_log],\n",
|
329 |
+
" )\n",
|
330 |
+
"\n",
|
331 |
+
"app.launch()"
|
332 |
+
]
|
333 |
+
}
|
334 |
+
],
|
335 |
+
"metadata": {
|
336 |
+
"kernelspec": {
|
337 |
+
"display_name": ".venv",
|
338 |
+
"language": "python",
|
339 |
+
"name": "python3"
|
340 |
+
},
|
341 |
+
"language_info": {
|
342 |
+
"codemirror_mode": {
|
343 |
+
"name": "ipython",
|
344 |
+
"version": 3
|
345 |
+
},
|
346 |
+
"file_extension": ".py",
|
347 |
+
"mimetype": "text/x-python",
|
348 |
+
"name": "python",
|
349 |
+
"nbconvert_exporter": "python",
|
350 |
+
"pygments_lexer": "ipython3",
|
351 |
+
"version": "3.13.0"
|
352 |
+
}
|
353 |
+
},
|
354 |
+
"nbformat": 4,
|
355 |
+
"nbformat_minor": 2
|
356 |
+
}
|
yolo11/keypoints-order-ultralytics-yolov8-pose.jpg
ADDED
![]() |
yolo11/v8pose.png
ADDED
![]() |
Git LFS Details
|
yolo11/yolo11m-pose.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:29b17eaf3a3117cbea906090dbedf9159f7c6a49db58ec8b99ed2dfde1cf6eb2
|
3 |
+
size 42459307
|
yolo11/yolo11n-pose.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cfe6eeb4193078497c9f615e269c95dac437bd2c86a96dab30408f427cb8180f
|
3 |
+
size 11620187
|
yolo11/yolo11n-pose.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:869e83fcdffdc7371fa4e34cd8e51c838cc729571d1635e5141e3075e9319dc0
|
3 |
+
size 6255593
|
yolo11/yolo11n.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0ebbc80d4a7680d14987a577cd21342b65ecfd94632bd9a8da63ae6417644ee1
|
3 |
+
size 5613764
|
yolo11/yolov5s.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8b3b748c1e592ddd8868022e8732fde20025197328490623cc16c6f24d0782ee
|
3 |
+
size 14808437
|
yolo11/yolov8n-pose.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c6fa93dd1ee4a2c18c900a45c1d864a1c6f7aba75d84f91648a30b7fb641d212
|
3 |
+
size 6832633
|