NNData

This message carries tensors and its data. You can receive this message from the NeuralNetwork node or you could create this message on the host, populate the tensor with the data and send the message to the input of the NeuralNetwork node.

Reference

class depthai.NNData

NNData message. Carries tensors and their metadata

getAllLayerNames(self: depthai.NNData) → List[str]
Returns

Names of all layers added

getAllLayers(self: depthai.NNData) → List[depthai.TensorInfo]
Returns

All layers and their information

getData(self: object) → numpy.ndarray[numpy.uint8]

Get non-owning reference to internal buffer

Returns

Reference to internal buffer

getFirstLayerFp16(self: depthai.NNData) → List[float]

Convenience function to retrieve float values from first layers FP16 tensor

Returns

Float data

getFirstLayerInt32(self: depthai.NNData) → List[int]

Convenience function to retrieve INT32 values from first layers tensor

Returns

INT32 data

getFirstLayerUInt8(self: depthai.NNData) → List[int]

Convenience function to retrieve U8 data from first layer

Returns

U8 binary data

getLayer(self: depthai.NNData, name: str, tensor: depthai.TensorInfo)bool

Retrieve layers tensor information

Parameter name:

Name of the layer

Parameter tensor:

Outputs tensor information of that layer

Returns

True if layer exists, false otherwise

getLayerDatatype(self: depthai.NNData, name: str, datatype: depthai.TensorInfo.DataType)bool

Retrieve datatype of a layers tensor

Parameter name:

Name of the layer

Parameter datatype:

Datatype of layers tensor

Returns

True if layer exists, false otherwise

getLayerFp16(self: depthai.NNData, name: str) → List[float]

Convenience function to retrieve float values from layers FP16 tensor

Parameter name:

Name of the layer

Returns

Float data

getLayerInt32(self: depthai.NNData, name: str) → List[int]

Convenience function to retrieve INT32 values from layers tensor

Parameter name:

Name of the layer

Returns

INT32 data

getLayerUInt8(self: depthai.NNData, name: str) → List[int]

Convenience function to retrieve U8 data from layer

Parameter name:

Name of the layer

Returns

U8 binary data

getRaw(self: depthai.ADatatype)depthai.RawBuffer
getSequenceNum(self: depthai.NNData)int

Retrieves image sequence number

getTimestamp(self: depthai.NNData)datetime.timedelta

Retrieves image timestamp related to dai::Clock::now()

getTimestampDevice(self: depthai.NNData)datetime.timedelta

Retrieves image timestamp directly captured from device’s monotonic clock, not synchronized to host time. Used mostly for debugging

hasLayer(self: depthai.NNData, name: str)bool

Checks if given layer exists

Parameter name:

Name of the layer

Returns

True if layer exists, false otherwise

setData(*args, **kwargs)

Overloaded function.

  1. setData(self: depthai.Buffer, arg0: List[int]) -> None

Parameter data:

Copies data to internal buffer

  1. setData(self: depthai.Buffer, arg0: numpy.ndarray[numpy.uint8]) -> None

Parameter data:

Copies data to internal buffer

setLayer(*args, **kwargs)

Overloaded function.

  1. setLayer(self: depthai.NNData, name: str, data: numpy.ndarray[numpy.uint8]) -> None

Set a layer with datatype U8.

Parameter name:

Name of the layer

Parameter data:

Data to store

  1. setLayer(self: depthai.NNData, name: str, data: List[int]) -> depthai.NNData

Set a layer with datatype U8. Integers are cast to bytes.

Parameter name:

Name of the layer

Parameter data:

Data to store

  1. setLayer(self: depthai.NNData, name: str, data: List[float]) -> depthai.NNData

Set a layer with datatype FP16. Float values are converted to FP16.

Parameter name:

Name of the layer

Parameter data:

Data to store

  1. setLayer(self: depthai.NNData, name: str, data: List[float]) -> depthai.NNData

Set a layer with datatype FP16. Double values are converted to FP16.

Parameter name:

Name of the layer

Parameter data:

Data to store

setSequenceNum(self: depthai.NNData, arg0: int)depthai.NNData

Retrieves image sequence number

setTimestamp(self: depthai.NNData, arg0: datetime.timedelta)depthai.NNData

Sets image timestamp related to dai::Clock::now()

setTimestampDevice(self: depthai.NNData, arg0: datetime.timedelta)depthai.NNData

Sets image timestamp related to dai::Clock::now()

class dai::NNData : public dai::Buffer

NNData message. Carries tensors and their metadata

Public Functions

NNData()

Construct NNData message.

NNData(std::shared_ptr<RawNNData> ptr)
~NNData() = default
NNData &setLayer(const std::string &name, std::vector<std::uint8_t> data)

Set a layer with datatype U8.

Parameters
  • name: Name of the layer

  • data: Data to store

NNData &setLayer(const std::string &name, const std::vector<int> &data)

Set a layer with datatype U8. Integers are cast to bytes.

Parameters
  • name: Name of the layer

  • data: Data to store

NNData &setLayer(const std::string &name, std::vector<float> data)

Set a layer with datatype FP16. Float values are converted to FP16.

Parameters
  • name: Name of the layer

  • data: Data to store

NNData &setLayer(const std::string &name, std::vector<double> data)

Set a layer with datatype FP16. Double values are converted to FP16.

Parameters
  • name: Name of the layer

  • data: Data to store

std::vector<std::string> getAllLayerNames() const

Return

Names of all layers added

std::vector<TensorInfo> getAllLayers() const

Return

All layers and their information

bool getLayer(const std::string &name, TensorInfo &tensor) const

Retrieve layers tensor information

Return

True if layer exists, false otherwise

Parameters
  • name: Name of the layer

  • [out] tensor: Outputs tensor information of that layer

bool hasLayer(const std::string &name) const

Checks if given layer exists

Return

True if layer exists, false otherwise

Parameters
  • name: Name of the layer

bool getLayerDatatype(const std::string &name, TensorInfo::DataType &datatype) const

Retrieve datatype of a layers tensor

Return

True if layer exists, false otherwise

Parameters
  • name: Name of the layer

  • [out] datatype: Datatype of layers tensor

std::vector<std::uint8_t> getLayerUInt8(const std::string &name) const

Convenience function to retrieve U8 data from layer

Return

U8 binary data

Parameters
  • name: Name of the layer

std::vector<float> getLayerFp16(const std::string &name) const

Convenience function to retrieve float values from layers FP16 tensor

Return

Float data

Parameters
  • name: Name of the layer

std::vector<std::int32_t> getLayerInt32(const std::string &name) const

Convenience function to retrieve INT32 values from layers tensor

Return

INT32 data

Parameters
  • name: Name of the layer

std::vector<std::uint8_t> getFirstLayerUInt8() const

Convenience function to retrieve U8 data from first layer

Return

U8 binary data

std::vector<float> getFirstLayerFp16() const

Convenience function to retrieve float values from first layers FP16 tensor

Return

Float data

std::vector<std::int32_t> getFirstLayerInt32() const

Convenience function to retrieve INT32 values from first layers tensor

Return

INT32 data

std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> getTimestamp() const

Retrieves image timestamp related to dai::Clock::now()

std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> getTimestampDevice() const

Retrieves image timestamp directly captured from device’s monotonic clock, not synchronized to host time. Used mostly for debugging

int64_t getSequenceNum() const

Retrieves image sequence number

NNData &setTimestamp(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> timestamp)

Sets image timestamp related to dai::Clock::now()

NNData &setTimestampDevice(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> timestamp)

Sets image timestamp related to dai::Clock::now()

NNData &setSequenceNum(int64_t sequenceNum)

Retrieves image sequence number

Private Functions

std::shared_ptr<RawBuffer> serialize() const override

Private Members

RawNNData &rawNn
std::unordered_map<std::string, std::vector<std::uint8_t>> u8Data
std::unordered_map<std::string, std::vector<std::uint16_t>> fp16Data

Private Static Attributes

constexpr int DATA_ALIGNMENT = 64

Got questions?

We’re always happy to help with code or other questions you might have.