Example Code

LabVIEW and ONNX Runtime (artificial neural network)

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Operating System

  • Linux
  • Windows

    Programming Language

  • C
  • C++
  • LabVIEW G

    Other

  • ONNX Runtime library

Code and Documents

Third-Party Code Repository

Some users manage their code in repositories outside of ni.com. Use your best judgment when following links to third-party sites. https://github.com/IvanLisRus/LabVIEW-ONNX_Runtime

Description

This example demonstrates how to use an ANN (artificial neural network) in LabVIEW.

It includes a wrapper over the ONNX Runtime, allowing you to:

  • initiate ONNX model;
  • obtain input/output information and metadata;
  • load data into ANN and obtain results.

 

Image processing is implemented using the following logic:

Stage 1: Detection (YOLOv8n ANN):

  • Convert the [1024, 1024] image to a [1, 3, 1024, 1024] tensor and feed it to the ANN input
  • Convert the data received from the ANN to a readable form, filter by threshold and NMS
  • Display the detection result

Stage 2: Rotation angle compensation (custom ANN):

  • Image segmentation (based on the results of stage 1)
  • Image resizing [x, x] -> [512, 512]
  • Convert the [512, 512] image to a [1, 3, 512, 512] tensor and feed it to the ANN input
  • Convert the [sin, cos] data received from the ANN to an angle and compensate for it
  • Display the result (segmentation, scaling, rotation)

Stage 3: Identification (ANN EfficientNet-B4):

  • Image resizing [512, 512] -> [380, 380]
  • Transform image [380, 380] into tensor [1, 3, 380, 380] and feed it to ANN input
  • Transform data received from ANN into probabilities for each of the two classes [Avers, Revers]
  • Display result

Example using VIs

blobid1775065679991.png

blobid1775065725580.png

blobid1775065760982.png

blobid1775065787629.png

Example using Class

blobid1775065898093.png

blobid1775065910922.png

Related Links

LabVIEW ONNX Runtime (code) on GitHub: https://github.com/IvanLisRus/LabVIEW-ONNX_Runtime

ONNX Runtime on GitHub: https://github.com/microsoft/onnxruntime/

Demo Video: https://youtu.be/AT9D4SQ7oe0 or rutube.ru

On Windows OS, you may need to install Microsoft Visual C++ Redistributable: https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors