YoloSpatialDetectionNetwork

Spatial detection for the Yolo NN. It is similar to a combination of the YoloDetectionNetwork and SpatialLocationCalculator.

How to place it

pipeline = dai.Pipeline()
yoloSpatial = pipeline.create(dai.node.YoloSpatialDetectionNetwork)
dai::Pipeline pipeline;
auto yoloSpatial = pipeline.create<dai::node::YoloSpatialDetectionNetwork>();

Inputs and Outputs

               ┌───────────────────┐
input          │                   │       passthrough
──────────────►│-------------------├─────────────────►
               │     Yolo          │               out
               │     Spatial       ├─────────────────►
               │     Detection     │boundingBoxMapping
               │     Network       ├─────────────────►
inputDepth     │                   │  passthroughDepth
──────────────►│-------------------├─────────────────►
               └───────────────────┘

Message types

Usage

pipeline = dai.Pipeline()
yoloSpatial = pipeline.create(dai.node.YoloSpatialDetectionNetwork)
yoloSpatial.setBlobPath(nnBlobPath)

# Spatial detection specific parameters
yoloSpatial.setConfidenceThreshold(0.5)
yoloSpatial.input.setBlocking(False)
yoloSpatial.setBoundingBoxScaleFactor(0.5)
yoloSpatial.setDepthLowerThreshold(100) # Min 10 centimeters
yoloSpatial.setDepthUpperThreshold(5000) # Max 5 meters

# Yolo specific parameters
yoloSpatial.setNumClasses(80)
yoloSpatial.setCoordinateSize(4)
yoloSpatial.setAnchors([10,14, 23,27, 37,58, 81,82, 135,169, 344,319])
yoloSpatial.setAnchorMasks({ "side26": [1,2,3], "side13": [3,4,5] })
yoloSpatial.setIouThreshold(0.5)
dai::Pipeline pipeline;
auto yoloSpatial = pipeline.create<dai::node::YoloSpatialDetectionNetwork>();
yoloSpatial->setBlobPath(nnBlobPath);

// Spatial detection specific parameters
yoloSpatial->setConfidenceThreshold(0.5f);
yoloSpatial->input.setBlocking(false);
yoloSpatial->setBoundingBoxScaleFactor(0.5);
yoloSpatial->setDepthLowerThreshold(100); // Min 10 centimeters
yoloSpatial->setDepthUpperThreshold(5000); // Max 5 meters

// yolo specific parameters
yoloSpatial->setNumClasses(80);
yoloSpatial->setCoordinateSize(4);
yoloSpatial->setAnchors({10, 14, 23, 27, 37, 58, 81, 82, 135, 169, 344, 319});
yoloSpatial->setAnchorMasks({{"side13", {3, 4, 5}}, {"side26", {1, 2, 3}}});
yoloSpatial->setIouThreshold(0.5f);

Examples of functionality

Spatial coordinate system

OAK camera uses left-handed (Cartesian) coordinate system for all spatial coordiantes.

https://github.com/luxonis/depthai-python/assets/18037362/f9bfaa0c-0286-46c0-910c-77c1337493e1

Middle of the frame is 0,0 in terms of X,Y coordinates. If you go up, Y will increase, and if you go right, X will increase.

Reference

class depthai.node.YoloSpatialDetectionNetwork
class Id

Node identificator. Unique for every node on a single Pipeline

getAnchorMasks(self: depthai.node.YoloSpatialDetectionNetwork) → Dict[str, List[int]]
getAnchors(self: depthai.node.YoloSpatialDetectionNetwork) → List[float]
getAssetManager(*args, **kwargs)

Overloaded function.

  1. getAssetManager(self: depthai.Node) -> depthai.AssetManager

  2. getAssetManager(self: depthai.Node) -> depthai.AssetManager

getConfidenceThreshold(self: depthai.node.DetectionNetwork)float
getCoordinateSize(self: depthai.node.YoloSpatialDetectionNetwork)int
getInputRefs(*args, **kwargs)

Overloaded function.

  1. getInputRefs(self: depthai.Node) -> List[depthai.Node.Input]

  2. getInputRefs(self: depthai.Node) -> List[depthai.Node.Input]

getInputs(self: depthai.Node) → List[depthai.Node.Input]
getIouThreshold(self: depthai.node.YoloSpatialDetectionNetwork)float
getName(self: depthai.Node)str
getNumClasses(self: depthai.node.YoloSpatialDetectionNetwork)int
getNumInferenceThreads(self: depthai.node.NeuralNetwork)int
getOutputRefs(*args, **kwargs)

Overloaded function.

  1. getOutputRefs(self: depthai.Node) -> List[depthai.Node.Output]

  2. getOutputRefs(self: depthai.Node) -> List[depthai.Node.Output]

getOutputs(self: depthai.Node) → List[depthai.Node.Output]
getParentPipeline(*args, **kwargs)

Overloaded function.

  1. getParentPipeline(self: depthai.Node) -> depthai.Pipeline

  2. getParentPipeline(self: depthai.Node) -> depthai.Pipeline

setAnchorMasks(self: depthai.node.YoloSpatialDetectionNetwork, anchorMasks: Dict[str, List[int]])None
setAnchors(self: depthai.node.YoloSpatialDetectionNetwork, anchors: List[float])None
setBlob(*args, **kwargs)

Overloaded function.

  1. setBlob(self: depthai.node.NeuralNetwork, blob: depthai.OpenVINO.Blob) -> None

  2. setBlob(self: depthai.node.NeuralNetwork, path: Path) -> None

setBlobPath(self: depthai.node.NeuralNetwork, path: Path)None
setBoundingBoxScaleFactor(self: depthai.node.SpatialDetectionNetwork, scaleFactor: float)None
setConfidenceThreshold(self: depthai.node.DetectionNetwork, thresh: float)None
setCoordinateSize(self: depthai.node.YoloSpatialDetectionNetwork, coordinates: int)None
setDepthLowerThreshold(self: depthai.node.SpatialDetectionNetwork, lowerThreshold: int)None
setDepthUpperThreshold(self: depthai.node.SpatialDetectionNetwork, upperThreshold: int)None
setIouThreshold(self: depthai.node.YoloSpatialDetectionNetwork, thresh: float)None
setNumClasses(self: depthai.node.YoloSpatialDetectionNetwork, numClasses: int)None
setNumInferenceThreads(self: depthai.node.NeuralNetwork, numThreads: int)None
setNumNCEPerInferenceThread(self: depthai.node.NeuralNetwork, numNCEPerThread: int)None
setNumPoolFrames(self: depthai.node.NeuralNetwork, numFrames: int)None
setSpatialCalculationAlgorithm(self: depthai.node.SpatialDetectionNetwork, calculationAlgorithm: depthai.SpatialLocationCalculatorAlgorithm)None
setSpatialCalculationStepSize(self: depthai.node.SpatialDetectionNetwork, stepSize: int)None
class dai::node::YoloSpatialDetectionNetwork : public dai::NodeCRTP<SpatialDetectionNetwork, YoloSpatialDetectionNetwork, SpatialDetectionNetworkProperties>

YoloSpatialDetectionNetwork node. Yolo-based network with spatial location data.

Public Functions

YoloSpatialDetectionNetwork(const std::shared_ptr<PipelineImpl> &par, int64_t nodeId)
void setNumClasses(const int numClasses)

Set num classes.

void setCoordinateSize(const int coordinates)

Set coordianate size.

void setAnchors(std::vector<float> anchors)

Set anchors.

void setAnchorMasks(std::map<std::string, std::vector<int>> anchorMasks)

Set anchor masks.

void setIouThreshold(float thresh)

Set Iou threshold.

int getNumClasses() const

Get num classes.

int getCoordinateSize() const

Get coordianate size.

std::vector<float> getAnchors() const

Get anchors.

std::map<std::string, std::vector<int>> getAnchorMasks() const

Get anchor masks.

float getIouThreshold() const

Get Iou threshold.

Got questions?

Head over to Discussion Forum for technical support or any other questions you might have.