> For the complete documentation index, see [llms.txt](https://robopipe.gitbook.io/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://robopipe.gitbook.io/doc/api/rest-api-reference/neural-network.md).

# Neural Network

Each camera is capable of running a [neural network](https://en.wikipedia.org/wiki/Neural_network_\(machine_learning\)) and feeding it data from a selected stream. Our API can currently handle only models in the MyriadX blob format. To read more about this format and how to convert your models to MyriadX blob format, please refer to [Luxonis conversion guide](https://docs.luxonis.com/software/ai-inference/conversion).

{% hint style="warning" %}
Deploying an AI model on the camera takes some time (usually \~20s, but may take up to a minute), during this time, the camera will be inaccessible via the API, since it needs to restart in order to deploy the model. All running streams from the particular camera will be paused and will resume when the camera is up again.
{% endhint %}

## API Reference

## POST /cameras/{mxid}/streams/{stream\_name}/nn

> Deploy Neural Network

```json
{"openapi":"3.1.0","info":{"title":"Robopipe API","version":"0.2.1.dev12"},"servers":[{"url":"http://localhost:8080","description":"Locally running server"}],"paths":{"/cameras/{mxid}/streams/{stream_name}/nn":{"post":{"tags":["streams","streams","nn"],"summary":"Deploy Neural Network","operationId":"deploy_neural_network_cameras__mxid__streams__stream_name__nn_post","parameters":[{"name":"stream_name","in":"path","required":true,"schema":{"type":"string","pattern":"CAM_[A-H]|DEPTH_[A-H]_[A-H]","title":"Stream Name"}},{"name":"mxid","in":"path","required":true,"schema":{"type":"string","pattern":"[A-Z0-9]+","title":"Mxid"}}],"requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"$ref":"#/components/schemas/Body_deploy_neural_network_cameras__mxid__streams__stream_name__nn_post"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"404":{"description":"Camera or stream not found"},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"Body_deploy_neural_network_cameras__mxid__streams__stream_name__nn_post":{"properties":{"model":{"type":"string","format":"binary","title":"Model"},"config":{"type":"string","title":"Config"}},"type":"object","required":["model","config"],"title":"Body_deploy_neural_network_cameras__mxid__streams__stream_name__nn_post"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}}}
```

### NNConfig Description

The deploy neural network endpoint accepts form-data body. This body shall contain two fields - *model*, which is a binary file containing the neural network in the MyriadX blob format and *nn\_config*, stringified json containing the neural network configuration. The *nn\_config* format is described below

| NNConfig Field                                | Description                                                                                                                                                                                              |                             |
| --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| <kbd>type</kbd> (*required*)                  | <p>Type of the neural network being deployed.<br><br>Possible values are:</p><ul><li><code>Generic</code></li><li><code>YOLO</code></li><li><code>MobileNet</code></li></ul><p>Type: <kbd>enum</kbd></p> |                             |
| <kbd>num\_inference\_threads</kbd> (optional) | <p>Number of CPU to run inference on.</p><p></p><p>Type: <kbd>number</kbd><br>Default: <kbd>2</kbd></p>                                                                                                  |                             |
| <kbd>nn\_config</kbd> (*optional*)            | <p>Type-specific configuration for the deployed model.<br><br>Type: <kbd>NNYoloConfig                                                                                                                    | NNMobileNetConfig</kbd></p> |

#### NNYoloConfig

| NNYoloConfig Field                       | Description |
| ---------------------------------------- | ----------- |
| <kbd>anchor\_masks</kbd> (*optional*)    |             |
| <kbd>anchors</kbd> (*optional*)          |             |
| <kbd>coordinate\_size</kbd> (*optional*) |             |
| <kbd>iou\_threshold</kbd> (*optional*)   |             |
| <kbd>num\_classes</kbd> (*optional*)     |             |

#### NNMobileNetConfig

| NNMobileNetConfig Field                       | Description |
| --------------------------------------------- | ----------- |
| <kbd>confidence\_threshold</kbd> (*optional*) |             |

## DELETE /cameras/{mxid}/streams/{stream\_name}/nn

> Delete Neural Network

```json
{"openapi":"3.1.0","info":{"title":"Robopipe API","version":"0.2.1.dev12"},"servers":[{"url":"http://localhost:8080","description":"Locally running server"}],"paths":{"/cameras/{mxid}/streams/{stream_name}/nn":{"delete":{"tags":["streams","streams","nn"],"summary":"Delete Neural Network","operationId":"delete_neural_network_cameras__mxid__streams__stream_name__nn_delete","parameters":[{"name":"stream_name","in":"path","required":true,"schema":{"type":"string","pattern":"CAM_[A-H]|DEPTH_[A-H]_[A-H]","title":"Stream Name"}},{"name":"mxid","in":"path","required":true,"schema":{"type":"string","pattern":"[A-Z0-9]+","title":"Mxid"}}],"responses":{"202":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"404":{"description":"Camera or stream not found"},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}}}
```
