ACAP FAQFrequently Asked Questions related to Axis camera application development
ACAP FAQ
Overview
Creating a deep learning based ACAP application that make use of accelerated edge inference can be a bit of a struggle. This is mostly due to the lack of instructions, documentation and productivity tools, this can be compared to what already today exists for e.g. cloud based deep learning. This is something we at FixedIT are working to solve.
We have identified a few different situations where companies want to train and deploy deep learning models for the Axis network cameras. We have divided the edge function into four distinct categories:
Depending on which of these categories your use case falls under, the project will be a bit different. Possibly the most important factor is if you already have a model that you are regularly retraining and that you are using in the cloud. This is typically the case if your use case falls under the alternative category. In contrast, if your use case falls under the primary category, then you will likely start from scratch and have better possibilities to research model architectures and training frameworks that are compatible and efficient with the runtime and accelerator hardware in the Axis cameras.
To make use of the existing inference API and the acceleration hardware in the Axis cameras, you need to create the deep learning models for TensorFlow Lite. Deployment to this environment is only supported from TensorFlow.
From experience, we know that most of the companies that are already training their own deep learning models are doing so in the PyTorch framework. This framework is not directly compatible with TensorFlow Lite.
Reimplementing the model in TensorFlow would not only be a large initial effort, but also pose operational challenges. If your company is continuing to train and deploy models to the cloud, there is suddenly a need to retrain two different models in two different frameworks each time you have received new training data.
Other options includes frameworks that can automatically convert a model trained in PyTorch to a model that can be loaded into TensorFlow (and then exported to TensorFlow Lite). None of these frameworks are however feature complete or robust, and not all models can be converted. Some of these frameworks include onnx-to-keras, MMdnn, and onnx2keras.
Do note that there are a lot of frameworks available that compiles models from a wide range of training frameworks to source code, using e.g. the Apache TVM compiler. This approach is however not compatible with the Axis cameras since the models need to run using the deep learning API (Larod) to get access to the DLPU accelerator hardware.
It is important to understand that even the new Axis cameras with capable deep learning accelerators are very limited compared to a cloud server. You can not expect to take the latest state-of-the-art models and run them in the camera, this is not possible due to the large size of the model parameters, and even if it was possible the inference time would be extreme.
There are, however, many experiments and much research showing that even a small model can be trained to achieve high quality results. These models do, however, require time invested in optimization.
The approach we have found to work well at FixedIT may at first seem counter-intuitive since it starts from what may seem to be the last step. The approach is roughly outlined below.
Run the model
One of the earliest steps we do when exploring different model architectures is to try the model in the device. The deep learning frameworks supports thousands of operations, as an example, there are over 1400 operations in TensorFlow. Looking at TensorFlow Lite, which is used in the camera, there are only about 130 supported operations (read more about these challenges). Add to this the memory constrains. This means that there is a large risk a specific model will not compile or run in the camera.
Before we invest a lot of time in training or benchmarking a model we first go through the conversion step and make it run in the camera. At this point, the model does not need to be trained, and will thus return garbage data, but we can make sure the model has a chance to work in the camera. There is no need to do pre or post processing at this point since we can feed it with garbage and only monitor for crashes or errors.
Benchmark the model
The next step we do is to benchmark the model throughput and the inference time. With a simple implementation we can measure the total inference time in the camera. For an early estimate, this too can be done before the model is trained.
The next step in the benchmarking is that we train the model and evaluate the accuracy. The throughput needed and the accuracy is frequently intertwined since a lower accuracy model can be improved by aggregating over multiple frames. At this step we will get good insights into the feasibility of the edge based inference. Detailed knowledge about the use case is key in this step.
Finally, when we know what we require from the model inference we can create optimized inference code. The throughput of the model can be increased by parallelizing preprocessing and sometimes by using other camera hardware such as the GPU or ACE to accelerate the preprocessing of the images. With knowledge about the use case you can make a tradeoff between low latency or high throughput.
Create automated pipelines
Training models, optimizing models with e.g. quantization, converting and sometimes compiling models makes it a lot of steps that is needed before a new model can be used in the camera. On top of this, there are multiple different DLPU accelerators in the different models of Axis cameras that need models that have been converted and compiled in different ways.
To deal with these challenges, the final step is to automate the steps either using automated pipelines or at least by scripts that are easy to execute in the right order.
Deploying and monitoring the application
Once the trained model is included in an ACAP application, the challenges are the same as for other applications. You need to deploy the application to multiple cameras and you need to monitor the health of the applications. For this, refer to our other information on ACAP development.
In summary, you need to understand the limitations of the devices. This understanding is best gained by experimenting with the devices. Start with simple models to get to know the Axis DLPU hardware. Then perform experiments to verify if what you want to do is possible or not.
This process does today look different from use case to use case and we can assist you in the process. We are working on a more structured approach and better tool sets, but as of today, you need to accept that the field is not yet standardized and projects will need to be agile and experimental to find the right way to solve your specific use case.