NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Merge remote-tracking branch 'origin/master' into dev
Blake Blackshear61d285ba13bb
diff --cc docs/docs/configuration/object_detectors.mdindex e0aca2b87e,fa2fde3457..89734efb93--- a/docs/docs/configuration/object_detectors.md+++ b/docs/docs/configuration/object_detectors.md@@@ -196,17 -190,22 +196,17 @@@ There are improved capabilities in newe### Generate Models-The model used for TensorRT must be preprocessed on the same hardware platform that they will run on. This means that each user must run additional setup to generate a model file for the TensorRT library. A script is provided that will build several common models.+The model used for TensorRT must be preprocessed on the same hardware platform that they will run on. This means that each user must run additional setup to generate a model file for the TensorRT library. A script is included that will build several common models.- The Frigate image will generate model files during startup if the specified model is not found. Processed models are stored in the `/config/model_cache` folder. Typically the `/config` path is mapped to a directory on the host already and the `model_cache` does not need to be mapped separately unless the user wants to store it in a different location on the host.-To generate model files, create a new folder to save the models, download the script, and launch a docker container that will run the script.++The Frigate image will generate model files during startup if the specified model is not found. Processed models are stored in the `/config/model_cache` folder. Typically the `/config` path is mapped to a directory on the host already and the `model_cache` does not need to be mapped separately unless the user wants to store it in a different location on the host.-```bash-mkdir trt-models-wget https://github.com/blakeblackshear/frigate/raw/master/docker/tensorrt_models.sh-chmod +x tensorrt_models.sh-docker run --gpus=all --rm -it -v `pwd`/trt-models:/tensorrt_models -v `pwd`/tensorrt_models.sh:/tensorrt_models.sh nvcr.io/nvidia/tensorrt:22.07-py3 /tensorrt_models.sh-```+By default, the `yolov7-320` model will be generated, but this can be overridden by specifying the `YOLO_MODELS` environment variable in Docker. One or more models may be listed in a comma-separated format, and each one will be generated. To select no model generation, set the variable to an empty string, `YOLO_MODELS=""`. Models will only be generated if the corresponding `{model}.trt` file is not present in the `model_cache` folder, so you can force a model to be regenerated by deleting it from your Frigate data folder.-The `trt-models` folder can then be mapped into your Frigate container as `trt-models` and the models referenced from the config.+If you have a Jetson device with DLAs (Xavier or Orin), you can generate a model that will run on the DLA by appending `-dla` to your model name, e.g. specify `YOLO_MODELS=yolov7-320-dla`. The model will run on DLA0 (Frigate does not currently support DLA1). DLA-incompatible layers will fall back to running on the GPU.-If your GPU does not support FP16 operations, you can pass the environment variable `-e USE_FP16=False` to the `docker run` command to disable it.+If your GPU does not support FP16 operations, you can pass the environment variable `USE_FP16=False` to disable it.-Specific models can be selected by passing an environment variable to the `docker run` command. Use the form `-e YOLO_MODELS=yolov4-416,yolov4-tiny-416` to select one or more model names. The models available are shown below.+Specific models can be selected by passing an environment variable to the `docker run` command or in your `docker-compose.yml` file. Use the form `-e YOLO_MODELS=yolov4-416,yolov4-tiny-416` to select one or more model names. The models available are shown below.```yolov3-288@@@ -236,23 -235,6 +236,23 @@@ yolov7x-64yolov7x-320```+An example `docker-compose.yml` fragment that converts the `yolov4-608` and `yolov7x-640` models for a Pascal card would look something like this:++```yml+frigate:+ environment:+ - YOLO_MODELS=yolov4-608,yolov7x-640+ - USE_FP16=false+```+- If you have multiple GPUs passed through to Frigate, you can specify which one to use for the model conversion. The conversion script will use the first visible GPU, however in systems with mixed GPU models you may not want to use the default index for object detection. Add the `TRT_MODEL_PREP_DEVICE` environment variable to select a specific GPU.++If you have multiple GPUs passed through to Frigate, you can specify which one to use for the model conversion. The conversion script will use the first visible GPU, however in systems with mixed GPU models you may not want to use the default index for object detection. Add the `TRT_MODEL_PREP_DEVICE` environment variable to select a specific GPU.++```yml+frigate:+ environment:+ - TRT_MODEL_PREP_DEVICE=0 # Optionally, select which GPU is used for model optimization+```+### Configuration ParametersThe TensorRT detector can be selected by specifying `tensorrt` as the model type. The GPU will need to be passed through to the docker container using the same methods described in the [Hardware Acceleration](hardware_acceleration.md#nvidia-gpu) section. If you pass through multiple GPUs, you can select which GPU is used for a detector with the `device` configuration parameter. The `device` parameter is an integer value of the GPU index, as shown by `nvidia-smi` within the container.@@@ -266,132 -248,9 +266,134 @@@ detectorsdevice: 0 #This is the default, select the first GPUmodel:- path: /trt-models/yolov7-tiny-416.trt+ path: /config/model_cache/tensorrt/yolov7-320.trtinput_tensor: nchwinput_pixel_format: rgb- width: 416- height: 416+ width: 320+ height: 320+```++## Deepstack / CodeProject.AI Server Detector++The Deepstack / CodeProject.AI Server detector for Frigate allows you to integrate Deepstack and CodeProject.AI object detection capabilities into Frigate. CodeProject.AI and DeepStack are open-source AI platforms that can be run on various devices such as the Raspberry Pi, Nvidia Jetson, and other compatible hardware. It is important to note that the integration is performed over the network, so the inference times may not be as fast as native Frigate detectors, but it still provides an efficient and reliable solution for object detection and tracking.++### Setup++To get started with CodeProject.AI, visit their [official website](https://www.codeproject.com/Articles/5322557/CodeProject-AI-Server-AI-the-easy-way) to follow the instructions to download and install the AI server on your preferred device. Detailed setup instructions for CodeProject.AI are outside the scope of the Frigate documentation.++To integrate CodeProject.AI into Frigate, you'll need to make the following changes to your Frigate configuration file:++```yaml+detectors:+ deepstack:+ api_url: http://<your_codeproject_ai_server_ip>:<port>/v1/vision/detection+ type: deepstack+ api_timeout: 0.1 # seconds+```++Replace `<your_codeproject_ai_server_ip>` and `<port>` with the IP address and port of your CodeProject.AI server.++To verify that the integration is working correctly, start Frigate and observe the logs for any error messages related to CodeProject.AI. Additionally, you can check the Frigate web interface to see if the objects detected by CodeProject.AI are being displayed and tracked properly.+-+# Community Supported Detectors++## Rockchip RKNN-Toolkit-Lite2++This detector is only available if one of the following Rockchip SoCs is used:+++- RK3588/RK3588S+- RK3568+- RK3566+- RK3562++These SoCs come with a NPU that will highly speed up detection.++### Setup++Use a frigate docker image with `-rk` suffix and enable privileged mode by adding the `--privileged` flag to your docker run command or `privileged: true` to your `docker-compose.yml` file.++### Configuration++This `config.yml` shows all relevant options to configure the detector and explains them. All values shown are the default values (except for one). Lines that are required at least to use the detector are labeled as required, all other lines are optional.++```yaml- detectors: # required- rknn: # required- type: rknn # required++detectors: # required++ rknn: # required++ type: rknn # required+ # core mask for npu+ core_mask: 0+- model: # required++model: # required+ # name of yolov8 model or path to your own .rknn model file+ # possible values are:+ # - default-yolov8n+ # - default-yolov8s+ # - default-yolov8m+ # - default-yolov8l+ # - default-yolov8x+ # - /config/model_cache/rknn/your_custom_model.rknn+ path: default-yolov8n+ # width and height of detection frames+ width: 320+ height: 320+ # pixel format of detection frame+ # default value is rgb but yolov models usually use bgr format- input_pixel_format: bgr # required++ input_pixel_format: bgr # required+ # shape of detection frame+ input_tensor: nhwc+```++Explanation for rknn specific options:+++- **core mask** controls which cores of your NPU should be used. This option applies only to SoCs with a multicore NPU (at the time of writing this in only the RK3588/S). The easiest way is to pass the value as a binary number. To do so, use the prefix `0b` and write a `0` to disable a core and a `1` to enable a core, whereas the last digit coresponds to core0, the second last to core1, etc. You also have to use the cores in ascending order (so you can't use core0 and core2; but you can use core0 and core1). Enabling more cores can reduce the inference speed, especially when using bigger models (see section below). Examples:+ - `core_mask: 0b000` or just `core_mask: 0` let the NPU decide which cores should be used. Default and recommended value.+ - `core_mask: 0b001` use only core0.+ - `core_mask: 0b011` use core0 and core1.+ - `core_mask: 0b110` use core1 and core2. **This does not** work, since core0 is disabled.++### Choosing a model++There are 5 default yolov8 models that differ in size and therefore load the NPU more or less. In ascending order, with the top one being the smallest and least computationally intensive model:++| Model | Size in mb |+| ------- | ---------- |+| yolov8n | 9 |+| yolov8s | 25 |+| yolov8m | 54 |+| yolov8l | 90 |+| yolov8x | 136 |++:::tip++You can get the load of your NPU with the following command:++```bash+$ cat /sys/kernel/debug/rknpu/load+>> NPU load: Core0: 0%, Core1: 0%, Core2: 0%,+```++:::++- By default the rknn detector uses the yolov8n model (`model: path: default-yolov8n`). This model comes with the image, so no further steps than those mentioned above are necessary.+- If you want to use a more precise model, you can pass `default-yolov8s`, `default-yolov8m`, `default-yolov8l` or `default-yolov8x` as `model: path:` option.+ - If the model does not exist, it will be automatically downloaded to `/config/model_cache/rknn`.+ - If your server has no internet connection, you can download the model from [this Github repository](https://github.com/MarcA711/rknn-models/releases) using another device and place it in the `config/model_cache/rknn` on your system.+- Finally, you can also provide your own model. Note that only yolov8 models are currently supported. Moreover, you will need to convert your model to the rknn format using `rknn-toolkit2` on a x86 machine. Afterwards, you can place your `.rknn` model file in the `config/model_cache/rknn` directory on your system. Then you need to pass the path to your model using the `path` option of your `model` block like this:+++```yaml+model:+ path: /config/model_cache/rknn/my-rknn-model.rknn+```++:::tip++When you have a multicore NPU, you can enable all cores to reduce inference times. You should consider activating all cores if you use a larger model like yolov8l. If your NPU has 3 cores (like rk3588/S SoCs), you can enable all 3 cores using:++```yaml+detectors:+ rknn:+ type: rknn+ core_mask: 0b111```++:::