Skip to content

Commit 88c9a0f

Browse files
Update examples for native SegMask and SegParser (#850)
* Migrate DeepLab examples to native SegmentationMask * Migrate dino tracking to native SegmentationMask * Use native visualizer for YOLO-P outputs * Update generic example segmentation overlay docs * Update YOLO-P visualizer docs * Temporarily target DAI 3.8 and depthai-nodes main * Update generic example instance segmentation docs * Address PR review follow-ups * Use released depthai-nodes version
1 parent 340cee1 commit 88c9a0f

17 files changed

Lines changed: 57 additions & 137 deletions

File tree

apps/dino-tracking/backend/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
depthai==3.7.1
2-
depthai-nodes==0.5.0
1+
depthai==3.8.0
2+
depthai-nodes==0.6.0
33
opencv-python-headless~=4.10.0
44
python-dotenv
55
python-box

apps/dino-tracking/backend/src/annotations/outlines_overlay_node.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import cv2
22
import depthai as dai
33
import numpy as np
4-
from depthai_nodes.message import SegmentationMask
54
from depthai_nodes.node.base_host_node import BaseHostNode
65

76

@@ -31,12 +30,8 @@ def process(self, frame_msg: dai.ImgFrame, segmentation: dai.Buffer):
3130
self.out.send(frame_msg)
3231
return
3332

34-
assert isinstance(segmentation, SegmentationMask)
35-
mask = getattr(segmentation, "mask", None)
36-
37-
if mask is None:
38-
self.out.send(frame_msg)
39-
return
33+
assert isinstance(segmentation, dai.SegmentationMask)
34+
mask = segmentation.getCvMask()
4035

4136
frame = frame_msg.getCvFrame()
4237
H, W = frame.shape[:2]

apps/dino-tracking/backend/src/object_selection/mask_selection_node.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import depthai as dai
22
import numpy as np
3-
from depthai_nodes.message import SegmentationMask
43
from depthai_nodes.node import BaseHostNode
54

65

@@ -31,10 +30,8 @@ def clear_selection(self) -> None:
3130
self._pending_click = None
3231
self._selected_mask = None
3332

34-
def process(self, segmentation: dai.Buffer):
35-
assert isinstance(segmentation, SegmentationMask)
36-
37-
segmentation_mask = segmentation.mask.astype(np.int32)
33+
def process(self, segmentation: dai.SegmentationMask):
34+
segmentation_mask = segmentation.getCvMask().astype(np.int32)
3835

3936
if self._pending_click:
4037
segment_id = self._map_click_to_segment(
@@ -78,10 +75,17 @@ def _map_click_to_segment(
7875
if patch.size == 0:
7976
return None
8077

81-
values, counts = np.unique(patch, return_counts=True)
78+
# Native dai.SegmentationMask uses 255 as background/unassigned.
79+
# Do not select the background as an object, while keeping class/instance
80+
# id 0 valid.
81+
foreground_patch = patch[patch != 255]
82+
if foreground_patch.size == 0:
83+
return None
84+
85+
values, counts = np.unique(foreground_patch, return_counts=True)
8286
return int(values[np.argmax(counts)])
8387

84-
def _send_mask(self, segmentation: SegmentationMask, mask: np.ndarray):
88+
def _send_mask(self, segmentation: dai.SegmentationMask, mask: np.ndarray):
8589
mask_u8 = mask.astype(np.uint8) * 255
8690

8791
out = dai.ImgFrame()

neural-networks/generic-example/AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Reusable single-model inference scaffold. It runs one Model Zoo model with one i
8686
## Validation
8787

8888
- `Run:` `python3 main.py`
89-
- `Alternative run:` `python3 main.py --model luxonis/mediapipe-selfie-segmentation:256x144 --overlay_mode`
89+
- `Alternative run:` `python3 main.py --model luxonis/mediapipe-selfie-segmentation:256x144`
9090
- `Archive run:` `python3 main.py --model /path/to/custom-model.tar.xz`
9191
- `Success looks like:` Visualizer exposes `Video` and `Detections`, and the pipeline runs until `q` is pressed
9292
- `Common failure meaning:` model identifier unavailable for platform, private model auth missing, or selected model violates the single-input/single-output assumptions

neural-networks/generic-example/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Here is a list of all available parameters:
2323
-api API_KEY, --api_key API_KEY
2424
HubAI API key for private HubAI access. Can also use 'DEPTHAI_HUB_API_KEY' environment variable instead. (default: )
2525
-overlay OVERLAY_MODE, --overlay_mode
26-
If passed, overlays model output on the input image when the output is an array (e.g., depth maps, segmentation maps). Otherwise, displays outputs separately.
26+
If passed, overlays model output on the input image when the output is an array (e.g., depth maps). Otherwise, displays outputs separately.
2727
```
2828

2929
## Peripheral Mode
@@ -53,20 +53,26 @@ This will run a simple YOLOv6 object detection model (`luxonis/yolov6-nano:r2-co
5353

5454
```bash
5555
python3 main.py \
56-
--model luxonis/mediapipe-selfie-segmentation:256x144 \
57-
--overlay_mode
56+
--model luxonis/mediapipe-selfie-segmentation:256x144
5857
```
5958

6059
This will run a selfie segmentation model.
6160

6261
```bash
6362
python3 main.py \
64-
--model luxonis/yolov8-instance-segmentation-nano:coco-512x288 \
65-
--overlay_mode
63+
--model luxonis/yolov8-instance-segmentation-nano:coco-512x288
6664
```
6765

6866
And this will run an instance segmentation model.
6967

68+
```bash
69+
python3 main.py \
70+
--model luxonis/midas-v2-1:small-512x288 \
71+
--overlay_mode
72+
```
73+
74+
This will run a MiDaS depth estimation model and overlay the depth map on the input image.
75+
7076
```bash
7177
python3 main.py \
7278
--model /path/to/custom-model.tar.xz
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
depthai==3.7.1
2-
depthai-nodes==0.5.0
1+
depthai==3.8.0
2+
depthai-nodes==0.6.0
33
opencv-python-headless~=4.10.0
44
numpy>=1.22
55
python-dotenv

neural-networks/generic-example/utils/arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def initialize_argparser():
6060
parser.add_argument(
6161
"-overlay",
6262
"--overlay_mode",
63-
help="If passed, overlays model output on the input image when the output is an array (e.g., depth maps, segmentation maps). Otherwise, displays outputs separately.",
63+
help="If passed, overlays model output on the input image when the output is an array (e.g., depth maps). Otherwise, displays outputs separately.",
6464
required=False,
6565
action="store_true",
6666
)

neural-networks/object-detection/yolo-p/AGENTS.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,24 @@ This is the repository reference for ADAS-style YOLO-P output: detections plus r
2727
- `Runs on:` RVC2 peripheral, RVC4 peripheral, and RVC4 standalone packaging
2828
- `Requires:` YOLO-P model and input resized to model dimensions
2929
- `Input:` camera frames by default or `ReplayVideo` via `--media_path`
30-
- `Output:` `Road Segmentation` and `Detections`
30+
- `Output:` `Video`, `Detections`, `Road Segmentation`, and `Lane Segmentation`
3131
- `Models:` YOLO-P YAMLs in [depthai_models/](depthai_models/)
3232
- `Visualizer / UI:` DepthAI Visualizer via `dai.RemoteConnection`
3333

3434
## Read First
3535

3636
- [README.md](README.md)
3737
- [main.py](main.py)
38-
- [utils/annotation_node.py](utils/annotation_node.py)
3938
- [utils/arguments.py](utils/arguments.py)
4039

4140
## Architecture
4241

4342
- `ParsingNeuralNetwork` runs the YOLO-P multi-head model on camera or replay input.
44-
- [utils/annotation_node.py](utils/annotation_node.py) consumes three outputs:
43+
- [main.py](main.py) sends the model outputs to Visualizer topics:
4544
- detections
4645
- road segmentation
4746
- lane segmentation
48-
- The Visualizer exposes the segmentation composite and detection overlay separately.
47+
- The Visualizer renders the input video, detections, road segmentation, and lane segmentation topics.
4948

5049
## Constraints
5150

@@ -62,5 +61,5 @@ This is the repository reference for ADAS-style YOLO-P output: detections plus r
6261
## Validation
6362

6463
- `Run:` `python3 main.py`
65-
- `Success looks like:` the Visualizer shows `Road Segmentation` and `Detections`, with lane/road overlays and detected vehicles
64+
- `Success looks like:` the Visualizer shows `Video`, `Detections`, `Road Segmentation`, and `Lane Segmentation`, with road/lane segmentation and detected vehicles
6665
- `Common failure meaning:` the model output ordering changed, the replay input was resized incorrectly, or the operator expected a generic single-output detector

neural-networks/object-detection/yolo-p/main.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from depthai_nodes.node import ParsingNeuralNetwork
55

66
from utils.arguments import initialize_argparser
7-
from utils.annotation_node import AnnotationNode
87

98
_, args = initialize_argparser()
109

@@ -54,19 +53,11 @@
5453
input_node_out, nn_archive
5554
)
5655

57-
# annotation
58-
annotation_node = pipeline.create(AnnotationNode).build(
59-
frame=input_node_out,
60-
detections=nn.getOutput(0),
61-
road_segmentations=nn.getOutput(1),
62-
lane_segmentations=nn.getOutput(2),
63-
)
64-
6556
# visualization
66-
visualizer.addTopic(
67-
"Road Segmentation", annotation_node.out_segmentations, "images"
68-
)
69-
visualizer.addTopic("Detections", annotation_node.out_detections, "images")
57+
visualizer.addTopic("Video", nn.passthrough, "images")
58+
visualizer.addTopic("Detections", nn.getOutput(0), "images")
59+
visualizer.addTopic("Road Segmentation", nn.getOutput(1), "images")
60+
visualizer.addTopic("Lane Segmentation", nn.getOutput(2), "images")
7061

7162
print("Pipeline created.")
7263

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
depthai==3.7.1
2-
depthai-nodes==0.5.0
1+
depthai==3.8.0
2+
depthai-nodes==0.6.0
33
opencv-python-headless~=4.10.0
44
numpy>=1.22

0 commit comments

Comments
 (0)