Configuration of norm_type

Parameters

Parameter: norm_type

This parameter is the input data pre-processing method added in the model.

  • Parameter value ranges and descriptions:
    • no_preprocess: No data preprocessing will be added.
    • data_mean: Provides mean-subtraction preprocessing.
    • data_scale: Provide multiply by scale coefficient preprocessing.
    • data_mean_and_scale: Provides preprocessing by subtracting the mean and then multiplying by the scale coefficient.
Attention

When there is more than one input node, the node order should be strictly consistent with the order in input_name.

Parameter: mean_value

This parameter means the average value subtracted from the image of specified preprocessing method.

  • Note: This parameter is required when norm_type takes the value data_mean_and_scale or data_mean.
  • Parameter descriptions:
    • When there is only one input node, only one value needs to be configured, which indicates that all channels need to subtract this mean value.
    • When there are multiple nodes, provide values consistent with the number of channels (these values are separated by spaces), indicating that each channel is subtracted by a different mean value.
Attention
  1. The number of input nodes configured must match the number of nodes configured in norm_type.
  2. If there exists a node that does not require mean processing, configure 'None' for that node.

Parameter: scale_value

This parameter indicates the numerical scale coefficient for the specified preprocessing method.

  • Note: This parameter is required when norm_type takes the value data_mean_and_scale or data_scale.
  • Parameter descriptions:
    • When there is only one input node, only one value needs to be configured, indicating that all channels are multiplied by this coefficient.
    • When there are multiple nodes, provide values consistent with the number of channels (these values are separated by spaces), indicating that each channel is multiplied by a different coefficient.
Attention
  1. The number of input nodes configured must match the number of nodes configured in norm_type.
  2. If there exists a node that does not require scale processing, configure 'None' for that node.

Formulas and Samples

The following combines the data normalization formulas for model training to provide you with an understanding of the process:

The mean and scale parameters in the YAML file need to be converted with the mean and std during training.

The calculation of the data normalization operation in the preprocess node is: norm_data=(datamean)scalenorm\_data = ( data - mean ) * scale.

Taking YOLOv3 as an example, its preprocessing code during the training is as follows:

def base_transform(image, size, mean, std): x = cv2.resize(image, (size, size).astype(np.float32)) x /= 255 x -= mean x /= std return x class BaseTransform: def __init__(self, size, mean=(0.406, 0.456, 0.485), std=(0.225, 0.224, 0.229)): self.size = size self.mean = np.array(mean, dtype=np.float32) self.std = np.array(std, dtype=np.float32)

Then the calculation formula is norm_data=(data255mean)1stdnorm\_data= (\frac{data}{255}-mean) * \frac{1}{std}.

Rewrite it to the computation for preprocessing nodes is: norm_data=(data255mean)1std=(data255mean)1255stdnorm\_data= (\frac{data}{255}-mean) * \frac{1}{std} =(data-255*mean) * \frac{1}{255*std}.

Then mean_yaml=255mean,scale_yaml=1255stdmean\_yaml = 255*mean, scale\_yaml= \frac{1}{255*std}.