The deep learning (DL) functionalities of HALCON 17.12 enable users to train a DL classifier for their specific application without the tedious feature extraction process required by traditional image classification methods. There are, however, a few preparational steps required in order to successfully train a deep learning classifier.
HALCON provides two pretrained convolutional neural networks (CNNs): the compact and the enhanced network. Both are optimized for industrial applications, however, the compact network is designed for speed and efficiency whereas the enhanced network is designed to solve more complex classification tasks. To fulfill the requirements of these pretrained networks, it is necessary to preprocess both the training and inference images.
There are four requirements when preprocessing images:
(1) Segmentation – the images must show only one instance of the object to be classified; otherwise the objects need to be isolated, e.g., by segmentation, and saved in separate files.
(2) Labelling – Images used for training a deep learning classifier in HALCON must be labelled, i.e., assigned to the proper class. This is easily achieved by saving images into corresponding sub-directories named for each class (see Figure 1, top).
(3) Resizing – Both of the pretrained networks require images to be sized to 224 x 224 pixels. It is important to verify that the relevant features, e.g., defects, are visible in the images at this size. If not, one solution may be to divide the original image into smaller individual images.
(4) Number of images – For best results you should have enough images for each class to adequately represent the full range of possible conditions. We recommend >500 images per class, although you may use fewer.
HALCON comes with two procedures to simplify the preprocessing steps:
read_dl_classifier_data_set() compiles the data-set of images from a given path and extracts the assigned labels automatically.
preprocess_dl_classifier_images() preprocesses the images according to the requirements of the pretrained classifier.
Depending on the images, further preprocessing steps might be beneficial, like cropping to the relevant area. All additional preprocessing steps should be implemented in an external procedure since images in the inference (run-time) mode will need to be preprocessed in the same way. Every preprocessed image should be saved as an .hobj file into a directory with the label name for fast access during training (see Fig. 1, bottom).
This done, you are ready to start training your DL classifier.