# NNData

该消息携带张量及其数据。[NeuralNetwork](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/neural_network.md) 节点输出 NNData。

## 创建 NNData

您也可以在主机上创建此消息（[示例在此](https://github.com/luxonis/oak-examples/blob/cd4a1e2be64a7c0319870cf80b4be3bd0561e9a0/gen2-efficientnet-classification/main.py#L125-L127)）或
[Script](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/script.md) 节点（[Script NNData
示例](https://docs.luxonis.com/software-v3/depthai/examples/script_nndata_example.md)），用数据填充张量，然后将消息发送到
[NeuralNetwork](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/neural_network.md) 节点的 input。

## 参考

### dai::NNData

Kind: class

NNData message. Carries tensors and their metadata

#### std::vector< TensorInfo > tensors

Kind: variable

#### unsigned int batchSize

Kind: variable

#### std::optional< ImgTransformation > transformation

Kind: variable

#### NNData()

Kind: function

Construct NNData message.

#### NNData(size_t size)

Kind: function

#### ~NNData()

Kind: function

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

Kind: function

return: Names of all layers added

#### std::vector< TensorInfo > getAllLayers()

Kind: function

return: All layers and their information

#### std::optional< TensorInfo > getTensorInfo(const std::string & name)

Kind: function

Retrieve tensor information parameters: name: Name of the tensor return: Tensor information

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

Kind: function

Retrieve layers tensor information parameters: name: Name of the layer; tensor: Outputs tensor information of that layer return:
True if layer exists, false otherwise

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

Kind: function

Checks if given layer exists parameters: name: Name of the layer return: True if layer exists, false otherwise

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

Kind: function

Retrieve datatype of a layers tensor parameters: name: Name of the layer; datatype: Datatype of layers tensor return: True if
layer exists, false otherwise

#### TensorInfo::DataType getTensorDatatype(const std::string & name)

Kind: function

Get the datatype of a given tensor return: TensorInfo::DataType tensor datatype

#### TensorInfo::DataType getFirstTensorDatatype()

Kind: function

Get the datatype of the first tensor return: TensorInfo::DataType tensor datatype

#### span< std::uint8_t > emplaceTensor(TensorInfo & tensor)

Kind: function

Emplace a tensor This function allocates memory for the tensor and return over the said memory. It is up to the caller to fill the
memory out with meaningful data. return: Span over the allocated memory

#### void serialize(std::vector< std::uint8_t > & metadata, DatatypeEnum & datatype)

Kind: function

#### DatatypeEnum getDatatype()

Kind: function

Get the datatype of this specific message.

return: DatatypeEnum

#### DEPTHAI_SERIALIZE(NNData, Buffer::sequenceNum, Buffer::ts, Buffer::tsDevice, Buffer::tsSystem, tensors, batchSize,
transformation)

Kind: function

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
