Skip to content

Commit 8bb18fd

Browse files
authored
v2.0.5
1 parent 8527eae commit 8bb18fd

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ results = bplusplus.validate(
134134
#### Step 5: Run Inference on Video
135135
Process a video file to detect, classify, and track insects using motion-based detection. The pipeline uses background subtraction (GMM) to detect moving insects, tracks them across frames, and classifies confirmed tracks.
136136
137+
**Note:** The species list and taxonomy are automatically loaded from the model checkpoint, so you don't need to provide them again.
138+
137139
**Output files generated in `output_dir`:**
138140
- `{video}_annotated.mp4` - Video showing confirmed tracks with classifications
139141
- `{video}_debug.mp4` - Debug video with motion mask and all detections
@@ -146,13 +148,14 @@ OUTPUT_DIR = Path("./output")
146148
HIERARCHICAL_MODEL_PATH = TRAINED_MODEL_DIR / "best_multitask.pt"
147149
148150
results = bplusplus.inference(
149-
species_list=names,
150151
hierarchical_model_path=HIERARCHICAL_MODEL_PATH,
151152
video_path=VIDEO_INPUT_PATH,
152153
output_dir=OUTPUT_DIR,
154+
# species_list=names, # Optional: override species from checkpoint
153155
fps=None, # None = process all frames
154156
backbone="resnet50", # Must match training
155157
save_video=True, # Set to False to skip video rendering (only CSV output)
158+
img_size=60, # Must match training
156159
)
157160
158161
print(f"Detected {results['tracks']} tracks ({results['confirmed_tracks']} confirmed)")
@@ -171,7 +174,44 @@ results = bplusplus.inference(
171174
)
172175
```
173176

174-
Download a template config from the [releases page](https://github.com/Tvenver/Bplusplus/releases). Parameters control cohesiveness filtering, shape filtering, tracking behavior, and path topology analysis for confirming insect-like movement.
177+
Download a template config from the [releases page](https://github.com/Tvenver/Bplusplus/releases).
178+
179+
<details>
180+
<summary><b>Full Configuration Parameters</b> (click to expand)</summary>
181+
182+
| Parameter | Default | Description |
183+
|-----------|---------|-------------|
184+
| **GMM Background Subtractor** | | *Motion detection model* |
185+
| `gmm_history` | 500 | Frames to build background model |
186+
| `gmm_var_threshold` | 16 | Variance threshold for foreground detection |
187+
| **Morphological Filtering** | | *Noise removal* |
188+
| `morph_kernel_size` | 3 | Morphological kernel size (NxN) |
189+
| **Cohesiveness** | | *Filters scattered motion (plants) vs compact motion (insects)* |
190+
| `min_largest_blob_ratio` | 0.80 | Min ratio of largest blob to total motion |
191+
| `max_num_blobs` | 5 | Max separate blobs allowed in detection |
192+
| `min_motion_ratio` | 0.15 | Min ratio of motion pixels to bbox area |
193+
| **Shape** | | *Filters by contour properties* |
194+
| `min_area` | 200 | Min detection area (px²) |
195+
| `max_area` | 40000 | Max detection area (px²) |
196+
| `min_density` | 3.0 | Min area/perimeter ratio |
197+
| `min_solidity` | 0.55 | Min convex hull fill ratio |
198+
| **Tracking** | | *Controls track behavior* |
199+
| `min_displacement` | 50 | Min net movement for confirmation (px) |
200+
| `min_path_points` | 10 | Min points before path analysis |
201+
| `max_frame_jump` | 100 | Max jump between frames (px) |
202+
| `max_lost_frames` | 45 | Frames before lost track deleted (e.g., 45 @ 30fps = 1.5s) |
203+
| `max_area_change_ratio` | 3.0 | Max area change ratio between frames |
204+
| **Tracker Matching** | | *Hungarian algorithm cost function* |
205+
| `tracker_w_dist` | 0.6 | Weight for distance cost (0-1) |
206+
| `tracker_w_area` | 0.4 | Weight for area cost (0-1) |
207+
| `tracker_cost_threshold` | 0.3 | Max cost for valid match (0-1) |
208+
| **Path Topology** | | *Confirms insect-like movement patterns* |
209+
| `max_revisit_ratio` | 0.30 | Max ratio of revisited positions |
210+
| `min_progression_ratio` | 0.70 | Min forward progression |
211+
| `max_directional_variance` | 0.90 | Max heading variance |
212+
| `revisit_radius` | 50 | Radius (px) for revisit detection |
213+
214+
</details>
175215

176216
### Customization
177217

full_pipeline.ipynb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@
281281
"\n",
282282
"Runs motion-based insect detection and hierarchical classification on video files. Detects moving insects using background subtraction (GMM), tracks them across frames, classifies each detection, and aggregates predictions per track.\n",
283283
"\n",
284+
"**Note:** The species list and taxonomy are automatically loaded from the model checkpoint, so you don't need to provide them again.\n",
285+
"\n",
284286
"**Output files generated:**\n",
285287
"- `{video}_annotated.mp4` - Video with detection boxes and track paths (if `save_video=True`)\n",
286288
"- `{video}_debug.mp4` - Side-by-side view with GMM motion mask (if `save_video=True`)\n",
@@ -297,13 +299,14 @@
297299
"outputs": [],
298300
"source": [
299301
"results = bplusplus.inference(\n",
300-
" species_list=names,\n",
301302
" hierarchical_model_path=RESNET_MULTITASK_WEIGHTS,\n",
302303
" video_path=\"./10.mp4\",\n",
303304
" output_dir=\"./output\",\n",
305+
" # species_list=names, # Optional: override species from checkpoint\n",
304306
" fps=None, # None = all frames\n",
305307
" backbone=\"resnet50\", # Must match training\n",
306308
" save_video=True, # Set to False to skip video rendering (only CSV output)\n",
309+
" img_size=60, # Must match training\n",
307310
")\n",
308311
"\n",
309312
"print(f\"Detected {results['tracks']} tracks ({results['confirmed_tracks']} confirmed)\")"
@@ -326,11 +329,19 @@
326329
")\n",
327330
"```\n",
328331
"\n",
332+
"#### Full Configuration Parameters\n",
333+
"\n",
329334
"| Parameter | Default | Description |\n",
330335
"|-----------|---------|-------------|\n",
336+
"| **GMM Background Subtractor** | | *Motion detection model* |\n",
337+
"| `gmm_history` | 500 | Frames to build background model |\n",
338+
"| `gmm_var_threshold` | 16 | Variance threshold for foreground detection |\n",
339+
"| **Morphological Filtering** | | *Noise removal* |\n",
340+
"| `morph_kernel_size` | 3 | Morphological kernel size (NxN) |\n",
331341
"| **Cohesiveness** | | *Filters scattered motion (plants) vs compact motion (insects)* |\n",
332342
"| `min_largest_blob_ratio` | 0.80 | Min ratio of largest blob to total motion |\n",
333343
"| `max_num_blobs` | 5 | Max separate blobs allowed in detection |\n",
344+
"| `min_motion_ratio` | 0.15 | Min ratio of motion pixels to bbox area |\n",
334345
"| **Shape** | | *Filters by contour properties* |\n",
335346
"| `min_area` | 200 | Min detection area (px²) |\n",
336347
"| `max_area` | 40000 | Max detection area (px²) |\n",
@@ -340,11 +351,17 @@
340351
"| `min_displacement` | 50 | Min net movement for confirmation (px) |\n",
341352
"| `min_path_points` | 10 | Min points before path analysis |\n",
342353
"| `max_frame_jump` | 100 | Max jump between frames (px) |\n",
343-
"| `lost_track_seconds` | 1.5 | How long to remember lost tracks (s) |\n",
354+
"| `max_lost_frames` | 45 | Frames before lost track deleted (e.g., 45 @ 30fps = 1.5s) |\n",
355+
"| `max_area_change_ratio` | 3.0 | Max area change ratio between frames |\n",
356+
"| **Tracker Matching** | | *Hungarian algorithm cost function* |\n",
357+
"| `tracker_w_dist` | 0.6 | Weight for distance cost (0-1) |\n",
358+
"| `tracker_w_area` | 0.4 | Weight for area cost (0-1) |\n",
359+
"| `tracker_cost_threshold` | 0.3 | Max cost for valid match (0-1) |\n",
344360
"| **Path Topology** | | *Confirms insect-like movement patterns* |\n",
345361
"| `max_revisit_ratio` | 0.30 | Max ratio of revisited positions |\n",
346362
"| `min_progression_ratio` | 0.70 | Min forward progression |\n",
347363
"| `max_directional_variance` | 0.90 | Max heading variance |\n",
364+
"| `revisit_radius` | 50 | Radius (px) for revisit detection |\n",
348365
"\n"
349366
]
350367
}

0 commit comments

Comments
 (0)