# Create Label (Labeling)

Labels are the user-generated input data that establish the ground truth for the tool. Ground truth refers to the undisputed facts about the images in your application, in other words, what you, as the human determine to be the key information within the image (feature, character, defect, class). Labels establish the ground truth, which is used for both training and performance analysis. So it is imperative that you label accurately.

## What is Labeling

Since the Deep Learning software is based on learning, what the network is taught about the images is vitally important. Within the Deep Learning parlance, this process is termed “labeling.” Labeling is the process of a user identifying features or defects, and graphically illustrating them on the image. The label represents the ground truth for the tools and is used to train the tools and validate their performance.

The label is the ground truth for the tool, in other words, you are telling the tool, "this is what it should learn." The most important part of programming the tools is ensuring that the images that are being used for training are completely and accurately labeled. Without knowing the ground truth data for the images, you cannot tell whether the tool is working properly or not. Also, without accurate labeling, the tool's training will not work as well.

When you are evaluating the performance of your tools and application, performance is always measured against the labeling that you provide. If your labeling does not reflect the actual ground truth for your images, then accurate and repeatable tool performance will not mean anything. When you train the Deep Learning tools, the goal for training – the cost function – is attempting to train the tool to produce a response that precisely matches the labeling that you provide.

For each of the tools, labeling is a manual operation (see below for the specifics of how labeling is performed for each tool). The most important characteristic of good labeling is that it is consistent, both between images and between observers and people performing the labeling. If you provide an image set to multiple people to label, and their labels do not agree, then the tool will likely not work well.

For each tool, there is a slightly different process, but the principle is the same. Once Labeling is completed, you will be ready to train the tool, and examine the Markings that the tool provides. You can toggle the display of labels and markings by either using the Alt + Left arrow and Alt + Right arrow keys, or from the right-click menu in the image.

You can also show overlay with enabling the "Label" at the Overlay Checkbox.

## Labeling in Red Analyze Focused Unsupervised

In Red Focused Unsupervised, the views provided to the training set are only Good views (in other words, the image does not contain any defects). Before training the tool you must first label the views as Good for constructing the training set. For the test set, you also need to include views with Bad label (in other words, the image contains defects) for proper evaluation of the tool's performance. It is very important that you correctly label the Views prior to training, because mislabeled Views can negatively affect training, by teaching the tools incorrectly what is or is not a defect.

When a View is labeled, the Views will be denoted by a Green or Red stripe on the top-right corner of the View:

"Good" Label | "Bad" Label
--- | ---

There are two different methods you can use to label Views:

1. Clicking once or twice on the View in the Image Display Area (GUI Overview).

   A single click labels the image as Good, double-clicking labels the image as Bad, and three clicks launches a dialog allowing you to reset the label to Good.

2. Using the Actions for N Views menu option from the Views List area:

   This option is particularly useful when you have a large number of images to label. Selecting this option launches the Label Views dialog, where you can define all of the images as either Good or Bad.

Note: Within the Red Analyze tool, the default region names are “deviation”, the name applied to Unsupervised mode regions, and “defect”, the name applied to Supervised mode regions. There is a potential to have a mix of region names in the tool. This can be encountered under the following conditions:

1. Create a Red Analyze tool and leave it in its default Unsupervised mode and set the tool’s ROI.
2. Open the Database Overview.
3. Launch the Edit Regions functionality, draw some defects and apply the changes.
4. With the Edit Regions editor still open, switch the tool from its default mode (Unsupervised) to Supervised.
5. Select another view, draw some defects and apply the changes.
6. Note that the thumbnails in the View list and in the Database Overview will be out of sync with the name in the Edit Regions editor.

To resolve the naming discrepancies, close the Edit Region editor and toggle the mode, which will cause the tool to merge and then correctly rename the regions.

Note: You can also import labels as image files, JSON files, or files in VisionPro Deep Learning internal label formats, see Cognex Label Import/Export Plug-in.

## How to Label Fast: Bootstrap Labeling

You can consider using the bootstrap method of labeling your images to speed up the labeling process for each tool. "Bootstrap" labeling refers to the process of beginning your labeling process by just labeling a small sample size of your images, then training the tool, and reviewing the results by accepting views with correct markings to convert them into labels, and removing incorrect markings and replacing them with correct labels. You can speed up this process further by dividing images into multiple views and only labeling a single view. In addition, you can also temporarily reduce the Epoch Count in Training parameters, which will make the training time shorter.

1. Label a few images in your Training Set.
2. Train the tool.
3. Review the images and results.
4. Accept the views where the tool's markings are accurate (right-click and select Accept View, or Ctrl + Shift + A). This will change the marking into a label. For the Red Analyze tool in Supervised mode, you may have to edit the defect region. For markings that are inaccurate, clear the markings from the image (right-click and select Clear Marking, or Ctrl + C), and then add the correct label.