Skip to main content

Test your model

Introduction

Before developing an application to run your model on a device, it's important to test the model to ensure it meets your requirements and is suitable for your use case. Testing the model allows you to evaluate its performance and make any necessary adjustments before proceeding with application development.

Test your model on the device

To test your model on the device, you can use the larod-client tool. Follow these steps:

  1. Connect to your device using ssh (see instructions).
  2. Run the following command:
larod-client -a

This command will provide you with a list of all the interfaces that larod can use to run your model.

List all interfaces
$ larod-client -a
> 2024-12-17T13:49:01.531 Connecting to larod...
> 2024-12-17T13:49:01.904 Connected
> 2024-12-17T13:49:01.904 Devices:
> ___________________________________________
> Name Instance
> ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
> cpu-tflite 0
> armnn-cpu-tflite 0
> cpu-proc 0
> a9-dlpu-tflite 0
> a9-gpu-proc 0
> ___________________________________________

To test the performance of your model on the DLPU, you can use the larod-client command with the following options:

Benchmark model
larod-client -g <model_file> -c a9-dlpu-tflite -R 100 -w 5 -i ''

This command runs the specified model on the ARTPEC-9 DLPU and performs 100 inferences. The -i '' option indicates that no input is required, as you are only testing the speed.

Before running this command, make sure that the model is loaded on the device.

When you run the command, the output will be displayed in the console. It will show the connection status, model loading status, setup of input tensors, and the execution time for the job. Here is an example of the output:

$ larod-client -g ./mobilenet_v2_1.0_224_quant.tflite -c a9-dlpu-tflite -R 100 -w 5 -i ''
> 2024-12-17T12:59:15.250 Connecting to larod...
> 2024-12-17T12:59:16.143 Connected
> 2024-12-17T13:00:32.945 Model mobilenet_v2_1.0_224_quant.tflite loaded
> 2024-12-17T13:00:32.945 Setting up randomly generated input tensors using random seed 1734440432
> 2024-12-17T13:00:32.970 Running 5 warm-up job(s)...
> 2024-12-17T13:00:32.986 Running job for 100 round(s)...
> 2024-12-17T13:00:33.239 Mean execution time for job: 2.92 ms

The output provides information about the connection status, model loading status, setup of input tensors, and the mean execution time for the job, which in this case was 2.92 ms.

Input and output with the model

If you are interested in providing an input and obtaining an output from the model, you can use the -i option to specify the input file for the model, and the -o option to specify the output file.

To specify the input and output files when using the larod-client command, use the following syntax:

Specify input and output
larod-client -g <model_file> -c a9-dlpu-tflite -R 1 -o <output_file> -i <input_file>

The <input_file> should be a binary file containing the input for the model. There is also a major difference in the input format between ARTPEC-7/8/9 and CV25, for ARTPEC the input is expected to be rgb-interleaved, while for CV25 the input is expected to be rgb-planar.

You can use the following Python code snippets to convert an image to the required binary format for an ARTPEC device:

Convert input to format expected by ARTPEC
import numpy as np
import cv2

img = cv2.imread('image.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img.tofile('input.bin')

For CV25, the input is expected to be rgb-planar, so you need to transpose the image before saving it to the binary file:

Convert input to format expected by CV25
import numpy as np
import cv2

img = cv2.imread('image.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = img.transpose(2, 0, 1)
img.tofile('input.bin')

Running the above command will produce the same results as before, but the output will be saved in the file specified by the -o option. The output file will be a binary file containing the output of the model. You will need to parse it according to your model output format.

Here is an example of running the command with input and output files specified:

$ larod-client -g ./mobilenet_v2_1.0_224_quant.tflite -c a9-dlpu-tflite -R 1 -i ./input.bin -o output.bin
> 2024-12-17T13:25:42.708 Connecting to larod...
> 2024-12-17T13:25:42.723 Connected
> 2024-12-17T13:25:43.037 Model mobilenet_v2_1.0_224_quant.tflite loaded
> 2024-12-17T13:25:43.039 Running job for 1 round(s)...
> 2024-12-17T13:25:43.043 Mean execution time for job: 3.59 ms

Retrieve device logs

If you encounter any errors with the commands mentioned above, you can retrieve the device logs by using the following command:

Retrieve logs
journalctl -u larod

This command will provide you with the logs from the larod service, which can help you identify and understand the issue you are experiencing. Common messages you may encounter indicate that certain layers in your network are not supported. To ensure proper functionality, ensure that your network only includes supported layers. For more information, refer to supported frameworks.