Developers Corner

Training a deep learning classifier with HALCON on the embedded board Jetson TX2

Learn how to train a deep learning classifier with HALCON on both a PC and an embedded Jetson TX2 board, from image acquisition to model training and inference, for efficient machine vision applications.

Deep learning technologies allow a wide range of applications for machine vision. Based on these technologies, MVTec offers various operators and tools within HALCON and MERLIC – often in combination with embedded boards and platforms (more information about this can be found in our section about Embedded Vision).

In this article, we describe how to train a deep learning classifier with HALCON on a standard PC together with the embedded board NVIDIA Jetson TX2 and a Basler GigEVision camera.

Prerequisites

Therefore, we set up the following technical components:

  • Standard PC with a powerful NVIDIA GPU with HALCON 17.12 installation or above.
  • System with a NVIDIA GPU with HALCON 17.12 installation or above (we used NVIDIA Jetson TX2 + power supply and HALCON 17.12 for Arm-based x64 systems).
  • 2 HALCON dongles (dependent upon you want to switch the dongles between the systems)

To set up a live system – and not working only with offline images – you additionally need the items below. You can see, within the brackets, what we used.

  • GigEVision camera (Basler ace acA1300-30gc ICX445)
  • Lens (6mm, V.S. Technologies SV-0614 (B1211), 0.5mm distance ring, polarizing filter to avoid specular reflections)
  • Lighting setup (EFFI-Ring including polarizing filter to avoid specular reflections)
  • Stativ system (Newport opto-mechanical mounting sets)
  • Additional parts for identification (NVIDIA Jetson TX2, Raspberry Pi 3, background and our hands)

For a comfortable handling, we applied a switch for connecting the camera to the PC and the NVIDIA Jetson. Otherwise, you have to plug and unplug the camera in between the systems. If you don’t want to use an external power supply for the camera, you need a PoE-camera and an active switch.

Acquiring the images

Starting from scratch, using deep learning technologies, requires millions of images. With HALCON’s pretrained deep learning nets, only around 400 images per class are required. For speedy and easy acquisition of the data, we developed a simple recording script, which can be downloaded on this site. Please note that for the execution of this script, some external procedures are needed. You may find them in the complete download package at the end of this site.

If you press your mouse button down, the images grabbed from the camera are stored on the HDD in the correct folder structure ( ./images/XXXX/imgNNNN, where XXXX is the name of the class and NNNN the sequence number). You may configure the script to fit your objects you would like to distinguish.

Please make sure, you have Jumbo Frames activated for your network interface card where the camera is connected. On Linux-based systems, you may do so by typing: udo ifconfig eth0 mtu 1492

Rules for acquiring the images:

  • Make sure that the object covers most of the image. This is especially important if you have the background as a class.
  • The classifier uses – if you do not preprocess the images – the complete image content, including the background as well. Therefore, you should make sure, that the object itself covers a larger portion of the images. Otherwise, the classifier may train the background and not the appearance of the object.
  • Provide every perspective of the object that may occur in the target application.
  • Check if the objects are distinguishable on the target size of 224x224. If this is not the case, you may think about dissecting your image in smaller portions and performing the inference on them. Doing so, you need to combine the single decisions to a final one.

For our system, we performed the acquisition of the training images on the PC, since the training itself is also performed here. Basically, it does not matter if the acquisition takes place on the embedded board or the PC, as long as the same setup is used for training as for the live inference of the net. But of course, the data can be acquired on the embedded board and transferred to the PC afterward for the next step. Please note: For easier operation, the script crops the images shown in the live view to the space without the red overlay.

Please note: For easier operation, the script crops the images shown in the live view to the space without the red overlay.

Train the model

Basically, the training can be done on both platforms. However, we highly recommend doing it on the more performant system (PC in our case) since the training may take some time depending on the configuration, e.g. the used batch size, and the used hardware. The script reads the training images and prepares them for the training, which is mostly resizing the image to 225x225. It is also possible to automatically vary the given training set by a process called augmentation. The corresponding convenience procedure augment_images may automatically alter the image content by rotation, cropping, mirroring and local or global brightness variation.

The process of the training can be checked by the graphics provided by the script. The values for training and validation error should start at a high value and lower during the iterations. After the training converges, the classifier is written to disk in order to transfer it to the target platform if necessary.

Transfer the model

The *.hdl file created by the script in the previous step can be transferred from the PC to the Jetson TX2. This can be done comfortably using a network connection and a transfer software like WinSCP or by simply using a USB-Stick.

Perform the inference

After all previous steps are completed, the system is ready to use. The last script is pretty straightforward – it grabs images from the camera, applies the deep learning net and show the results. The output should look similar to the output of the acquisition script besides the inference result.

For easier handling, you may use a SSH client like PuTTY. This allows to show the output of the Jetson on the PC. Please make sure you enabled X11 forwarding and started an X-server on the PC to display the graphical output of the script on your remote platform. Furthermore, make sure you activate the high-performance mode of the Jetson. On the development system we used, the script jetson_clocks.sh can be executed to use all available cores. If this is activated, you should see the CPU fan rotating.

Download complete source code

Further articles

Visualize Object Model 3D
Improve your surface-based matching with two helpful features
Do you sometimes have objects, which have rather small symmetry-breaking elements (such as small boreholes on an object)? Does your surface-based 3D matching not find the correct orientation?
Read more
Developers Corner
Deep OCR Interface
Deep OCR recognition training – the next level
HALCON’s Deep OCR is very powerful and can detect and recognize text in various industrial scenes. However, what if you have a special font, or want to read foreign characters? With HALCON 22.05 it is possible to train the recognition model to read s…
Read more
Developers Corner
Fitted primitives distance threshold
Metrology Model – Quality of Fit
"For most applications, the standard parameter values are sufficient." This sentence is often read in the HALCON Solution Guide. But what if the results do not meet your expectations? The Metrology Model allows lightning-fast measurement of geometric…
Read more
Developers Corner
Review of Acquisition Modes
This article gives an overview of HALCON’s image acquisition modes, explaining how continuous, triggered, and synchronous acquisition work, and clarifying common misconceptions for practical applications.
Read more
Developers Corner
Deep OCR – Tips and Tricks
Have you already experienced the performance boost by using Deep OCR compared to the classical rule‑based approaches? In this article, we’ll show you practical tips and tricks to further improve your Deep OCR results.
Read more
Developers Corner
Easy text and code reading with MERLIC standard tools
If you want to build an MVApp that reads for example QR codes or bar codes you can do so with just a few clicks. You can even combine the tools to get all available information printed on a product in different formats without the need for programmin…
Read more
Developers Corner
About MVTec's Heatmap
Imagine you intend to deliver a HALCON deep-learning-based classification application. And you are about to evaluate a trained model. You are therefore looking for feedback about this model, i.e. about its performances, biases, and other possible def…
Read more
Developers Corner
Gabor filter: What is it for?
Gabor filters, which are well known in the realm of time series analyses, can also be used in HALCON for 2D image analysis. They are particularly useful for detecting textures, patterns, and orientations in complex images.
Read more
Developers Corner
Introduction to new sub-pixel feature of bar code reader
Do you have small resolution bar codes to read but don't get any good results? Then please try our new feature – the subpixel bar code reader.
Read more
Developers Corner
Introduction to XYZ-Mappings (part 2)
This technical article continues our introduction to XYZ-mappings. In the last article, we answered the question "What are XYZ-mappings?" and gave a short preview towards "Why is using XYZ-mappings beneficial for many 3D applications?". Today, we wil…
Read more
Developers Corner
Introduction to XYZ-Mappings (part 1)
This technical article explores the benefits of XYZ-mappings in HALCON, showing how they increase speed, flexibility, and ease of use for many 3D applications.
Read more
Developers Corner
Deep learning: Why is the dataset key for a success result?
Deep learning success starts with the dataset: Learn why acquiring high-quality, well-labeled training data is crucial for reliable classification, detection, segmentation, and anomaly detection in your machine vision applications.
Read more
Developers Corner
How to prepare 3D height images for further processing with MERLIC’s standard tools
Learn how to prepare 3D height images in MERLIC for further processing: convert non-byte images to byte images to enable alignment, embossed text reading, and defect detection with standard easyTouch tools.
Read more
Developers Corner
Deflectrometry demo HALCON
Inspection of specular surfaces with deflectometry in HALCON
Inspect flat and curved reflective surfaces quickly and reliably with HALCON deflectometry: detect scratches, dents, and other defects with synchronized image acquisition and flexible image processing.
Read more
Developers Corner
Add touch input to the HSmartWindowControlWPF
Learn how to easily add touch input, including pinch-to-zoom, to the HSmartWindowControlWPF in HALCON, leveraging WPF’s built-in multi-touch events for intuitive image control.
Read more
Developers Corner
Increasing Speed in Deflectometry Set-ups
Discover three approaches to increase speed in deflectometry setups, from simple software-based synchronization to hardware triggers and FPGA-based real-time control, enabling faster and more precise inspection of reflective surfaces.
Read more
Developers Corner
HDevelop matching assistant speedup greediness
Speeding up shape-based matching with "Greediness"
Learn how the 'Greediness' parameter in shape-based matching balances speed and detection completeness, enabling faster searches while maintaining robust results in HALCON.
Read more
Developers Corner
Best practice for classification and OCR
Discover best practices for setting up classification and OCR in HALCON using the HDevelop OCR Training File Browser – quickly review, correct, and optimize your training data to improve segmentation and classification results.
Read more
Developers Corner
Rejection all classes 1.5
How to use rejection classes in MVTec HALCON
Learn how to handle outlier samples in MVTec HALCON by using rejection classes in MLP classifiers – automatically generate samples outside the training classes to improve classification reliability.
Read more
Developers Corner
Using regularization Weight prior 0.1 large
Using Regularization in MLP Classification
Learn how to use regularization in HALCON to prevent overfitting in MLP classifiers, smooth decision boundaries, and achieve better generalization for new and unseen data.
Read more
Developers Corner
MVTec Software