NNData

This message carries tensors and its data. You can recieve 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]
Returns

Reference to internal buffer

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

Convinience function to retrieve float values from first layers FP16 tensor

Returns

Float data

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

Convinience function to retrieve INT32 values from first layers tensor

Returns

INT32 data

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

Convinience 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 infromation 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]

Convinience 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]

Convinience 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]

Convinience function to retrieve U8 data from layer

Parameter name:

Name of the layer

Returns

U8 binary data

getRaw(self: depthai.ADatatype)depthai.RawBuffer
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]) -> None

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

Parameter name:

Name of the layer

Parameter data:

Data to store

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

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]) -> None

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

Parameter name:

Name of the layer

Parameter data:

Data to store

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
void 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

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

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

Parameters
  • name: Name of the layer

  • data: Data to store

void 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

void 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 infromation 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

Convinience 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

Convinience 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

Convinience function to retrieve INT32 values from layers tensor

Return

INT32 data

Parameters
  • name: Name of the layer

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

Convinience function to retrieve U8 data from first layer

Return

U8 binary data

std::vector<float> getFirstLayerFp16() const

Convinience function to retrieve float values from first layers FP16 tensor

Return

Float data

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

Convinience function to retrieve INT32 values from first layers tensor

Return

INT32 data

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.