NNData

This message carries tensors and its data. NeuralNetwork node outputs NNData.

Creating NNData

You can also create this message on the host (example here) or Script node (example here), populate the tensor with the data, and send the message to the input of the NeuralNetwork node.

Reference

class depthai.NNData
getAllLayerNames(self: depthai.NNData)list[str]
getAllLayers(self: depthai.NNData)list[depthai.TensorInfo]
getData(self: object) → numpy.ndarray[numpy.uint8]
getFirstLayerFp16(self: depthai.NNData)list[float]
getFirstLayerInt32(self: depthai.NNData)list[int]
getFirstLayerUInt8(self: depthai.NNData)list[int]
getLayer(self: depthai.NNData, name: str, tensor: depthai.TensorInfo)bool
getLayerDatatype(self: depthai.NNData, name: str, datatype: depthai.TensorInfo.DataType)bool
getLayerFp16(self: depthai.NNData, name: str)list[float]
getLayerInt32(self: depthai.NNData, name: str)list[int]
getLayerUInt8(self: depthai.NNData, name: str)list[int]
getRaw(self: depthai.ADatatype)depthai.RawBuffer
getSequenceNum(self: depthai.NNData)int
getTimestamp(self: depthai.NNData)datetime.timedelta
getTimestampDevice(self: depthai.NNData)datetime.timedelta
hasLayer(self: depthai.NNData, name: str)bool
setData(*args, **kwargs)

Overloaded function.

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

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

setLayer(*args, **kwargs)

Overloaded function.

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

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

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

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

setSequenceNum(self: depthai.NNData, arg0: int)depthai.NNData
setTimestamp(self: depthai.NNData, arg0: datetime.timedelta)depthai.NNData
setTimestampDevice(self: depthai.NNData, arg0: datetime.timedelta)depthai.NNData
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

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?

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