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

  1. 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.

      ../../../_images/overexposed.png

      You can avoid overexposure by methods such as shading.

    • Left image, bad example: Dim image.

    • Right image, good example: Adequate exposure.

      ../../../_images/darker_lighting.png

      You can avoid dimming by methods such as supplementary light.

    • Left image, bad example: Color distortion.

    • Right image, good example: Normal color.

      ../../../_images/color_distortion.png

      Color distortion can be avoided by adjusting the white balance.

    • Left image, bad example: Blur.

    • Right image, good example: Clear.

      ../../../_images/obscure.png

      Please avoid capturing images when the camera or the objects are still moving.

    • Left image, bad example: Occluded by the robot arm.

    • Right image, good example: Occluded by a human.

      ../../../_images/occluded.png

      Please make sure there is no robot or human in the way from the camera to the objects.

  2. 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).

      ../../../_images/background_inconsistent.png

      Please make sure the background stays the same when capturing the training data and when deploying the project.

    • Bad example: The field of view and perspective in the training data (left) are different from that in the actual application (right).

      ../../../_images/field_mismatch.png

      Please make sure the field of view and perspective stay the same when capturing the training data and when deploying the project.

    • Bad example: The camera height in the training data (left) is different from the background in the actual application (right).

      ../../../_images/height_mismatch.png

      Please make sure the camera height stays the same when capturing the training data and when deploying the project.


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.

  1. Collect datasets

  2. Select datasets

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.

  1. Different orientations

    ../../../_images/collection_method_1.png
    ../../../_images/collection_method_2.png
    ../../../_images/collection_method_3.png
  2. Different positions

    ../../../_images/collection_method_4.png
    ../../../_images/collection_method_5.png

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.

    ../../../_images/project_case.png

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 needs to be considered, so 10 images were collected for objects inside the slot.

    ../../../_images/project_case_2.png

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.

    ../../../_images/project_case_3A.png
    ../../../_images/project_case_3B.png

Select the Right Dataset

  1. 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 model improvement later, and will make the training time longer.

  2. 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.

  3. 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.

  4. 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.

      ../../../_images/label.png

      The left image is the workpiece front and the right image is the workpiece back.

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.

../../../_images/cams.png