# 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"}}}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://robopipe.gitbook.io/doc/api/rest-api-reference/neural-network.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
