Raj Bhalerao commited on
Commit
c1bf807
·
1 Parent(s): 7326db3

openvino adapted and adjustments

Browse files
README.md CHANGED
@@ -22,11 +22,12 @@ Full-stack traffic analytics dashboard. YOLO + ByteTrack backend processes uploa
22
  - **Frontend**: Vanilla HTML/JS, TailwindCSS CDN, Chart.js
23
  - **Infra**: Docker, CPU-only inference
24
 
25
- ## Run with Docker
26
 
27
  ```bash
28
- docker build -t funky .
29
- docker run -p 7860:7860 funky
 
30
  ```
31
 
32
  Open `http://localhost:7860`
@@ -45,4 +46,4 @@ python backend/server.py
45
  3. System auto-calculates optimal inference settings (adjustable)
46
  4. Draw counting line on first frame
47
  5. Engine processes frames, dashboard updates in real time
48
- 6. View run details and live analytics
 
22
  - **Frontend**: Vanilla HTML/JS, TailwindCSS CDN, Chart.js
23
  - **Infra**: Docker, CPU-only inference
24
 
25
+ ## Run Locally with Docker
26
 
27
  ```bash
28
+ docker build -t urbanflow .
29
+ docker run -p 7860:7860 -e HF_TOKEN=hf_your_token_here urbanflow
30
+
31
  ```
32
 
33
  Open `http://localhost:7860`
 
46
  3. System auto-calculates optimal inference settings (adjustable)
47
  4. Draw counting line on first frame
48
  5. Engine processes frames, dashboard updates in real time
49
+ 6. View run details and live analytics
backend/config.py CHANGED
@@ -57,7 +57,7 @@ def get_optimal_config(video_path):
57
  model_fps = _estimate_fps(imgsz, cpu_score)
58
  detect_stride = _select_stride(fps, model_fps)
59
  effective_fps = model_fps / detect_stride
60
- # realtime_possible = effective_fps >= fps
61
 
62
  return {
63
  "video_fps": fps,
@@ -69,6 +69,6 @@ def get_optimal_config(video_path):
69
  "imgsz": imgsz,
70
  "detect_stride": detect_stride,
71
  "model_fps_est": round(model_fps, 2),
72
- "effective_fps_est": round(effective_fps, 2)
73
- # "realtime_possible": realtime_possible
74
  }
 
57
  model_fps = _estimate_fps(imgsz, cpu_score)
58
  detect_stride = _select_stride(fps, model_fps)
59
  effective_fps = model_fps / detect_stride
60
+ realtime_possible = effective_fps >= fps
61
 
62
  return {
63
  "video_fps": fps,
 
69
  "imgsz": imgsz,
70
  "detect_stride": detect_stride,
71
  "model_fps_est": round(model_fps, 2),
72
+ "effective_fps_est": round(effective_fps, 2),
73
+ "realtime_possible": realtime_possible
74
  }
backend/model.py CHANGED
@@ -1,4 +1,3 @@
1
- # Using OpenVino as per Space settings compatible for performance on Intel CPU hardware
2
  import os
3
  from pathlib import Path
4
  from dotenv import load_dotenv
@@ -8,7 +7,7 @@ load_dotenv()
8
 
9
  MODEL_DIR = Path(__file__).parent / "weights"
10
  PT_PATH = MODEL_DIR / "best.pt"
11
- OV_PATH = MODEL_DIR / "best_openvino_model" # it's a directory
12
 
13
 
14
  def ensure_openvino():
@@ -22,12 +21,10 @@ def ensure_openvino():
22
  f'https://huggingface.co/Perception365/VehicleNet-Y26s/resolve/main/weights/best.pt'
23
  )
24
 
25
- if not OV_PATH.exists():
26
- # Export happens relative to the .pt file's location
27
- # Result will be: weights/best_openvino_model/
28
  YOLO(str(PT_PATH)).export(format="openvino", dynamic=True)
29
 
30
 
31
  def load_model():
32
  ensure_openvino()
33
- return YOLO(str(OV_PATH), task="detect")
 
 
1
  import os
2
  from pathlib import Path
3
  from dotenv import load_dotenv
 
7
 
8
  MODEL_DIR = Path(__file__).parent / "weights"
9
  PT_PATH = MODEL_DIR / "best.pt"
10
+ OV_DIR = MODEL_DIR / "best_openvino_model"
11
 
12
 
13
  def ensure_openvino():
 
21
  f'https://huggingface.co/Perception365/VehicleNet-Y26s/resolve/main/weights/best.pt'
22
  )
23
 
24
+ if not OV_DIR.exists():
 
 
25
  YOLO(str(PT_PATH)).export(format="openvino", dynamic=True)
26
 
27
 
28
  def load_model():
29
  ensure_openvino()
30
+ return YOLO(str(OV_DIR), task="detect")
frontend/initial.html CHANGED
@@ -105,8 +105,9 @@
105
 
106
  <!-- STEP: Module Select -->
107
  <div id="step-modules" class="w-full flex flex-col fade-in justify-center">
108
- <h2 class="text-3xl font-montserrat font-bold mb-2 text-slate-900">Select AI Module</h2>
109
- <p class="text-[13px] font-medium text-slate-400 mb-6">Choose an intelligence pipeline for your media
 
110
  stream.</p>
111
 
112
  <div class="grid grid-cols-2 gap-4">
@@ -127,7 +128,8 @@
127
  Coming Soon</div>
128
  <i class="fa-solid fa-layer-group text-3xl text-slate-300 mb-4 block"></i>
129
  <h3 class="font-montserrat font-bold text-sm mb-2 leading-tight text-slate-700">Semantic
130
- <br>Segmentation</h3>
 
131
  <p class="text-[10px] text-slate-400 font-medium">Pixel-perfect instance segmentation for
132
  complex spatial scene understanding.</p>
133
  </div>
@@ -138,7 +140,8 @@
138
  Coming Soon</div>
139
  <i class="fa-solid fa-tags text-3xl text-slate-300 mb-4 block"></i>
140
  <h3 class="font-montserrat font-bold text-sm mb-2 leading-tight text-slate-700">Image
141
- <br>Classification</h3>
 
142
  <p class="text-[10px] text-slate-400 font-medium">High-speed categorical labeling for vast and
143
  diverse image datasets.</p>
144
  </div>
@@ -149,7 +152,8 @@
149
  Coming Soon</div>
150
  <i class="fa-solid fa-expand text-3xl text-slate-300 mb-4 block"></i>
151
  <h3 class="font-montserrat font-bold text-sm mb-2 leading-tight text-slate-700">Custom
152
- <br>Detection</h3>
 
153
  <p class="text-[10px] text-slate-400 font-medium">Deploy proprietary neural networks for highly
154
  specialized edge inference.</p>
155
  </div>
@@ -162,8 +166,10 @@
162
  class="text-slate-400 hover:text-black transition flex items-center text-xs font-bold uppercase tracking-widest mb-6 w-fit">
163
  <i class="fa-solid fa-arrow-left mr-2"></i> Back to Modules
164
  </button>
165
- <h2 class="text-3xl font-montserrat font-bold mb-2 text-slate-900">Initialize Media Source</h2>
166
- <p class="text-[13px] font-medium text-slate-400 mb-8">Provide the target video footage to configure the
 
 
167
  Traffic Analytics pipeline.</p>
168
 
169
  <div id="dropzone"
@@ -192,8 +198,9 @@
192
 
193
  <!-- STEP: Config -->
194
  <div id="step-config" class="hidden w-full flex flex-col fade-in justify-center">
195
- <h2 class="text-3xl font-montserrat font-bold mb-2 text-slate-900">System Configuration</h2>
196
- <p class="text-[11px] font-montserrat font-bold text-slate-400 mb-8 uppercase tracking-widest">
 
197
  Optimal values auto-configured for performance
198
  </p>
199
 
@@ -207,8 +214,10 @@
207
 
208
  <!-- STEP: Draw Line -->
209
  <div id="step-draw" class="hidden w-full flex flex-col fade-in justify-center">
210
- <h2 class="text-3xl font-montserrat font-bold mb-2 text-slate-900">Define Boundary</h2>
211
- <p class="text-[11px] font-montserrat font-bold uppercase tracking-widest text-slate-400 mb-6">Click two
 
 
212
  points to establish counting threshold</p>
213
 
214
  <div
@@ -244,9 +253,9 @@
244
  let runConfig = {};
245
 
246
  const configParams = [
247
- { key: "imgsz", label: "Image Size", step: 32, min: 320, max: 1280 },
248
- { key: "conf", label: "Confidence", step: 0.01, min: 0.01, max: 1.0, decimals: 2 },
249
- { key: "iou", label: "IoU Threshold", step: 0.05, min: 0.1, max: 1.0, decimals: 2 },
250
  { key: "detect_stride", label: "Frame Stride", step: 1, min: 1, max: 10 }
251
  ];
252
 
 
105
 
106
  <!-- STEP: Module Select -->
107
  <div id="step-modules" class="w-full flex flex-col fade-in justify-center">
108
+ <h2 class="text-3xl font-montserrat font-bold mb-2 text-slate-900 text-center">Select AI Module</h2>
109
+ <p class="text-[13px] font-medium text-slate-400 mb-6 text-center">Choose an intelligence pipeline for
110
+ your media
111
  stream.</p>
112
 
113
  <div class="grid grid-cols-2 gap-4">
 
128
  Coming Soon</div>
129
  <i class="fa-solid fa-layer-group text-3xl text-slate-300 mb-4 block"></i>
130
  <h3 class="font-montserrat font-bold text-sm mb-2 leading-tight text-slate-700">Semantic
131
+ <br>Segmentation
132
+ </h3>
133
  <p class="text-[10px] text-slate-400 font-medium">Pixel-perfect instance segmentation for
134
  complex spatial scene understanding.</p>
135
  </div>
 
140
  Coming Soon</div>
141
  <i class="fa-solid fa-tags text-3xl text-slate-300 mb-4 block"></i>
142
  <h3 class="font-montserrat font-bold text-sm mb-2 leading-tight text-slate-700">Image
143
+ <br>Classification
144
+ </h3>
145
  <p class="text-[10px] text-slate-400 font-medium">High-speed categorical labeling for vast and
146
  diverse image datasets.</p>
147
  </div>
 
152
  Coming Soon</div>
153
  <i class="fa-solid fa-expand text-3xl text-slate-300 mb-4 block"></i>
154
  <h3 class="font-montserrat font-bold text-sm mb-2 leading-tight text-slate-700">Custom
155
+ <br>Detection
156
+ </h3>
157
  <p class="text-[10px] text-slate-400 font-medium">Deploy proprietary neural networks for highly
158
  specialized edge inference.</p>
159
  </div>
 
166
  class="text-slate-400 hover:text-black transition flex items-center text-xs font-bold uppercase tracking-widest mb-6 w-fit">
167
  <i class="fa-solid fa-arrow-left mr-2"></i> Back to Modules
168
  </button>
169
+ <h2 class="text-3xl font-montserrat font-bold mb-2 text-slate-900 text-center">Initialize Media Source
170
+ </h2>
171
+ <p class="text-[13px] font-medium text-slate-400 mb-8 text-center">Provide the target video footage to
172
+ configure the
173
  Traffic Analytics pipeline.</p>
174
 
175
  <div id="dropzone"
 
198
 
199
  <!-- STEP: Config -->
200
  <div id="step-config" class="hidden w-full flex flex-col fade-in justify-center">
201
+ <h2 class="text-3xl font-montserrat font-bold mb-2 text-slate-900 text-center">System Configuration</h2>
202
+ <p
203
+ class="text-[11px] font-montserrat font-bold text-slate-400 mb-8 uppercase tracking-widest text-center">
204
  Optimal values auto-configured for performance
205
  </p>
206
 
 
214
 
215
  <!-- STEP: Draw Line -->
216
  <div id="step-draw" class="hidden w-full flex flex-col fade-in justify-center">
217
+ <h2 class="text-3xl font-montserrat font-bold mb-2 text-slate-900 text-center">Define Boundary</h2>
218
+ <p
219
+ class="text-[11px] font-montserrat font-bold uppercase tracking-widest text-slate-400 mb-6 text-center">
220
+ Click two
221
  points to establish counting threshold</p>
222
 
223
  <div
 
253
  let runConfig = {};
254
 
255
  const configParams = [
256
+ { key: "imgsz", label: "Image Size", step: 32, min: 640, max: 1280 },
257
+ { key: "conf", label: "Confidence", step: 0.01, min: 0.08, max: 1.0, decimals: 2 },
258
+ { key: "iou", label: "IoU Threshold", step: 0.05, min: 0.5, max: 1.0, decimals: 2 },
259
  { key: "detect_stride", label: "Frame Stride", step: 1, min: 1, max: 10 }
260
  ];
261
 
frontend/vehicles.html CHANGED
@@ -154,10 +154,10 @@
154
  </div>
155
 
156
  <!-- TAB: Overview -->
157
- <div id="tab-overview" class="grid grid-cols-4 gap-4 flex-1 min-h-0 grid-rows-2">
158
 
159
  <!-- Congestion Index -->
160
- <div class="col-span-2 bg-white rounded-xl p-5 border border-slate-200 shadow-sm flex flex-col">
161
  <div class="flex justify-between items-center mb-2 relative">
162
  <h3 class="font-bold text-slate-900 text-sm flex items-center">Congestion Index
163
  <span class="info-wrap"><span class="info-btn"><i class="fa-solid fa-info"></i></span>
@@ -200,7 +200,7 @@
200
 
201
  <!-- Vehicle Classification Breakdown -->
202
  <div
203
- class="col-span-1 bg-white rounded-xl p-5 border border-slate-200 shadow-sm flex flex-col overflow-hidden">
204
  <div class="flex justify-between items-center mb-1 relative">
205
  <h3 class="font-bold text-slate-900 text-sm flex items-center">Classification
206
  <span class="info-wrap"><span class="info-btn"><i class="fa-solid fa-info"></i></span>
@@ -213,7 +213,7 @@
213
  </div>
214
 
215
  <!-- Class Dominance -->
216
- <div class="col-span-2 bg-white rounded-xl p-5 border border-slate-200 shadow-sm flex flex-col">
217
  <div class="flex justify-between items-center mb-2 relative">
218
  <h3 class="font-bold text-slate-900 text-sm flex items-center">Class Dominance
219
  <span class="info-wrap"><span class="info-btn"><i class="fa-solid fa-info"></i></span>
@@ -228,7 +228,7 @@
228
  </div>
229
 
230
  <!-- Traffic Flow Over Time -->
231
- <div class="col-span-2 bg-white rounded-xl p-5 border border-slate-200 shadow-sm flex flex-col">
232
  <div class="flex justify-between items-center mb-2 relative">
233
  <h3 class="font-bold text-slate-900 text-sm flex items-center">Traffic Flow
234
  <span class="info-wrap"><span class="info-btn"><i class="fa-solid fa-info"></i></span>
@@ -246,7 +246,7 @@
246
 
247
  <!-- TAB: Run Details -->
248
  <div id="tab-run-details" class="hidden flex-1 min-h-0 overflow-y-auto">
249
- <div class="grid grid-cols-2 gap-4 h-full">
250
  <!-- Video Input -->
251
  <div class="bg-white rounded-xl border border-slate-200 shadow-sm flex flex-col overflow-hidden">
252
  <div class="px-5 py-3 border-b border-slate-100 bg-slate-50/50">
@@ -308,7 +308,12 @@
308
  const tip = wrap.querySelector('.info-tip');
309
  if (!tip) return;
310
  const rect = wrap.getBoundingClientRect();
311
- tip.style.top = (rect.bottom + 6) + 'px';
 
 
 
 
 
312
  tip.style.left = Math.min(rect.left, window.innerWidth - 300) + 'px';
313
  });
314
 
@@ -387,11 +392,12 @@
387
  <a href="https://huggingface.co/Perception365/VehicleNet-Y26s" target="_blank" class="text-sm font-bold text-blue-600 bg-blue-50 px-2 py-0.5 rounded border border-blue-100 mono-font hover:bg-blue-100 transition">Perception365/VehicleNet-Y26s <i class="fa-solid fa-arrow-up-right-from-square text-[9px] ml-1"></i></a>
388
  </div>` +
389
  detailRow('task', 'detect') +
 
390
  detailRow('tracker', 'ByteTrack');
391
 
392
  document.getElementById('panel-infer').innerHTML =
393
  infoRow('imgsz', c.imgsz, 'Input image resolution for model inference.') +
394
- infoRow('detect_stride', c.detect_stride, 'Frames skipped between consecutive detections.') +
395
  infoRow('conf', c.conf || 0.12, 'Minimum confidence threshold for valid detections.') +
396
  infoRow('iou', c.iou || 0.60, 'Intersection-over-Union threshold for non-max suppression.') +
397
  infoRow('stream', 'TRUE', 'Frame-by-frame processing for constant memory usage.') +
 
154
  </div>
155
 
156
  <!-- TAB: Overview -->
157
+ <div id="tab-overview" class="grid grid-cols-6 gap-4 flex-1 min-h-0 grid-rows-2">
158
 
159
  <!-- Congestion Index -->
160
+ <div class="col-span-3 bg-white rounded-xl p-5 border border-slate-200 shadow-sm flex flex-col">
161
  <div class="flex justify-between items-center mb-2 relative">
162
  <h3 class="font-bold text-slate-900 text-sm flex items-center">Congestion Index
163
  <span class="info-wrap"><span class="info-btn"><i class="fa-solid fa-info"></i></span>
 
200
 
201
  <!-- Vehicle Classification Breakdown -->
202
  <div
203
+ class="col-span-2 bg-white rounded-xl p-5 border border-slate-200 shadow-sm flex flex-col overflow-hidden">
204
  <div class="flex justify-between items-center mb-1 relative">
205
  <h3 class="font-bold text-slate-900 text-sm flex items-center">Classification
206
  <span class="info-wrap"><span class="info-btn"><i class="fa-solid fa-info"></i></span>
 
213
  </div>
214
 
215
  <!-- Class Dominance -->
216
+ <div class="col-span-3 bg-white rounded-xl p-5 border border-slate-200 shadow-sm flex flex-col">
217
  <div class="flex justify-between items-center mb-2 relative">
218
  <h3 class="font-bold text-slate-900 text-sm flex items-center">Class Dominance
219
  <span class="info-wrap"><span class="info-btn"><i class="fa-solid fa-info"></i></span>
 
228
  </div>
229
 
230
  <!-- Traffic Flow Over Time -->
231
+ <div class="col-span-3 bg-white rounded-xl p-5 border border-slate-200 shadow-sm flex flex-col">
232
  <div class="flex justify-between items-center mb-2 relative">
233
  <h3 class="font-bold text-slate-900 text-sm flex items-center">Traffic Flow
234
  <span class="info-wrap"><span class="info-btn"><i class="fa-solid fa-info"></i></span>
 
246
 
247
  <!-- TAB: Run Details -->
248
  <div id="tab-run-details" class="hidden flex-1 min-h-0 overflow-y-auto">
249
+ <div class="grid grid-cols-2 gap-4">
250
  <!-- Video Input -->
251
  <div class="bg-white rounded-xl border border-slate-200 shadow-sm flex flex-col overflow-hidden">
252
  <div class="px-5 py-3 border-b border-slate-100 bg-slate-50/50">
 
308
  const tip = wrap.querySelector('.info-tip');
309
  if (!tip) return;
310
  const rect = wrap.getBoundingClientRect();
311
+ const tipH = 60;
312
+ if (rect.bottom + tipH + 10 > window.innerHeight) {
313
+ tip.style.top = (rect.top - tipH - 6) + 'px';
314
+ } else {
315
+ tip.style.top = (rect.bottom + 6) + 'px';
316
+ }
317
  tip.style.left = Math.min(rect.left, window.innerWidth - 300) + 'px';
318
  });
319
 
 
392
  <a href="https://huggingface.co/Perception365/VehicleNet-Y26s" target="_blank" class="text-sm font-bold text-blue-600 bg-blue-50 px-2 py-0.5 rounded border border-blue-100 mono-font hover:bg-blue-100 transition">Perception365/VehicleNet-Y26s <i class="fa-solid fa-arrow-up-right-from-square text-[9px] ml-1"></i></a>
393
  </div>` +
394
  detailRow('task', 'detect') +
395
+ detailRow('format', 'OpenVINO') +
396
  detailRow('tracker', 'ByteTrack');
397
 
398
  document.getElementById('panel-infer').innerHTML =
399
  infoRow('imgsz', c.imgsz, 'Input image resolution for model inference.') +
400
+ infoRow('vid_stride', c.detect_stride, 'Frames skipped between consecutive detections.') +
401
  infoRow('conf', c.conf || 0.12, 'Minimum confidence threshold for valid detections.') +
402
  infoRow('iou', c.iou || 0.60, 'Intersection-over-Union threshold for non-max suppression.') +
403
  infoRow('stream', 'TRUE', 'Frame-by-frame processing for constant memory usage.') +
requirements.txt CHANGED
@@ -7,6 +7,7 @@ numpy==1.24.3
7
  python-dotenv==1.0.0
8
  websockets==12.0
9
  onnxruntime
 
10
  onnx>=1.12.0
11
  onnxslim>=0.1.71
12
  lap>=0.5.12
 
7
  python-dotenv==1.0.0
8
  websockets==12.0
9
  onnxruntime
10
+ openvino>=2024.0.0
11
  onnx>=1.12.0
12
  onnxslim>=0.1.71
13
  lap>=0.5.12