Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend SegmentationParser. #59

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions depthai_nodes/ml/parsers/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,23 @@ def run(self):
output_layer_names = output.getAllLayerNames()

if len(output_layer_names) != 1:
raise ValueError(
f"Expected 1 output layer, got {len(output_layer_names)}."
print(
f"Expected 1 output layer, got {len(output_layer_names)}. Will take the first one."
)

segmentation_mask = output.getTensor(output_layer_names[0], dequantize=True)
if len(segmentation_mask.shape) == 4:
segmentation_mask = segmentation_mask[0]
else:
segmentation_mask = segmentation_mask.transpose(2, 0, 1)

if len(segmentation_mask.shape) != 3:
raise ValueError(
f"Expected 3D output tensor, got {len(segmentation_mask.shape)}D."
)

mask_shape = segmentation_mask.shape
min_dim = np.argmin(mask_shape)
if min_dim == len(mask_shape) - 1:
segmentation_mask = segmentation_mask.transpose(2, 0, 1)
if self.background_class:
segmentation_mask = np.vstack(
(
Expand All @@ -83,7 +85,6 @@ def run(self):
segmentation_mask,
)
)

class_map = (
np.argmax(segmentation_mask, axis=0)
.reshape(segmentation_mask.shape[1], segmentation_mask.shape[2], 1)
Expand Down
Loading