Train a High-Quality Model¶
This section introduces several factors that most affect the model quality and how to train a high-quality image classification model.
Ensure Image Quality¶
Avoid overexposure, dimming, color distortion, blur, occlusion, etc. These conditions will lead to the loss of features that the deep learning model relies on, which will affect the model training effect.
Left image, bad example: Overexposure.
Right image, good example: Adequate exposure.
Left image, bad example: Dim image.
Right image, good example: Adequate exposure.
Left image, bad example: Color distortion.
Right image, good example: Normal color.
Left image, bad example: Blur.
Right image, good example: Clear.
Left image, bad example: Occluded by the robot arm.
Right image, good example: Occluded by a human.
Ensure that the background, perspective, and height of the image capturing process are consistent with the actual application. Any inconsistency will reduce the effect of deep learning in practical applications. In severe cases, data must be re-collected. Please confirm the conditions of the actual application in advance.
Bad example: The background in the training data (left) is different from the background in the actual application (right).
Bad example: The field of view and perspective in the training data (left) are different from that in the actual application (right).
Bad example: The camera height in the training data (left) is different from the background in the actual application (right).
Attention
The quality of image classification is sensitive to lighting, and the lighting conditions need to be consistent during collection; if the light is inconsistent in the morning and evening, it needs to be collected separately according to the situation.
Ensure Dataset Quality¶
The “Classification” module obtains a model by learning the features of existing images and applies what is learned to the actual application.
Therefore, to train a high-quality model, the conditions of the collected and selected dataset must be consistent with those of the actual applications.
Collect Datasets¶
Various placement conditions need to be properly allocated. For example, if there are horizontal and vertical incoming materials in actual production, but only the data of horizontal incoming materials are collected for training, the classification effect of vertical incoming materials cannot be guaranteed.
Therefore, when collecting data, it is necessary to consider various conditions of the actual application, including the features present given different object placement orientations and positions.
Different orientations
Different positions
Data Collection Examples¶
A valve tube project
Single object class.
Distinguishing between the front and back sides of the valve tubes is needed.
Positions are generally fixed with small deviations.
15 images for the front and back sides each were collected.
An engine valve assembly project
Single object class.
Determining whether the object is correctly placed in the slot is needed.
Since outside the slot, the object may appear in various positions and orientations, it is necessary to consider different positions and orientations. 20 images were collected for objects outside the slot.
In the slot, only the factor of different positions need to be considered, so 10 images were collected for objects inside the slot.
A sheet metal project
Two object classes. Different object sizes need to be recognized.
Objects may come in different positions and orientations.
20 images were collected for the front and back sides each.
Select the Right Dataset¶
Control dataset image quantities
For the first-time model building of the “Classification” module, capturing 30 images is recommended.
It is not true that the larger the number of images the better. Adding a large number of inadequate images in the early stage is not conducive to the later model improvement, and will make the training time longer.
Collect representative data
Dataset image capturing should consider all the conditions in terms of illumination, color, size, etc. of the objects to recognize.
Lighting: Project sites usually have environmental lighting changes, and the datasets should contain images with different lighting conditions.
Color: Objects may come in different colors, and the datasets should contain images of objects of all the colors.
Size: Objects may come in different sizes, and the datasets should contain images of objects of all existing sizes.
Attention
If the actual on-site objects may be rotated, scaled in images, etc., and the corresponding image datasets cannot be collected, the datasets can be supplemented by adjusting the data augmentation training parameters to ensure that all on-site conditions are included in the datasets.
Balance data proportion
The number of images of different conditions/object classes in the datasets should be proportioned according to the actual project; otherwise, the training effect will be affected.
Dataset images should be consistent with those from the application site
The factors that need to be consistent include lighting conditions, object features, background, field of view, etc.
Ensure Labeling Quality¶
Please ensure there are no missed or incorrect labelings.
Left image, bad example: Wrong label.
Right image, good example: Correct label.
Class Activation Maps¶
After the training of the image classification model is completed, click on Generate CAM to generate the class activation maps, and click on Show class activation maps (CAM).
The class activation maps show the feature regions in the images that are paid attention to when training the model, and they help check the classification performance, thus providing references for optimizing the mode.