Halcon颜色分类-MLP

it2022-05-05  150

 简介:

                multilayer perceptron(MLP)即多层感知器。可用在颜色分类。

 

介绍:

draw_rectangle1(画一个与坐标轴平行的矩形) WindowHandle (input_control)  Window identifier.窗体Row1 (output_control)Row index of the left upper corner.左上角的行坐标Column1 (output_control) Column index of the left upper corner.左上角的列坐标Row2 (output_control) Row index of the right lower corner.右下角的行坐标Column2 (output_control)Column index of the right lower corner.右下角的列坐标 create_class_mlp (创建一个多层感知器用于分类或回归分析) NumInput (input_control)  Number of input variables (features) of the MLP. Default value: 20 Suggested values: 1, 2, 3, 4, 5, 8, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100 Restriction: NumInput >= 1MLP的输入特征数量NumHidden (input_control)  Number of hidden units of the MLP. Default value: 10 Suggested values: 1, 2, 3, 4, 5, 8, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 150 Restriction: NumHidden >= 1MLP的隐藏特征数量NumOutput (input_control)  Number of output variables (classes) of the MLP. Default value: 5 Suggested values: 1, 2, 3, 4, 5, 8, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 150 Restriction: NumOutput >= 1MLP的输出变量的数量OutputFunction (input_control) 

Type of the activation function in the output layer of the MLP. Default value: 'softmax' List of values: 'linear', 'logistic', 'softmax'

softmax必须配合使用classify_image_class_mlp对像素数据进行分类。参数Preprocessing和NumComponents可用于指定特征向量的预处理。参数Preprocessing= 'none',特征向量直接传递给MLP,在并忽略NumComponents。MLP的输出层中激活函数的类型Preprocessing (input_control)  

Type of preprocessing used to transform the feature vectors. Default value: 'normalization' List of values: 'canonical_variates', 'none', 'normalization', 'principal_components'

normalization特征向量归一化的方法是减去训练向量的均值,再除以训练向量各分量的标准差。因此,变换后的特征向量均值为0,标准差为1。归一化不改变特征向量的长度。忽略NumComponents。如果特征向量的均值和标准差分别与0和1相差很大,或者特征向量的分量在diff中测量的数据也可以使用这种转换。该转换可以使用如果特征向量的平均值和标准偏差明显不同于0和1,或数据的特征向量的分量以不同的单位(例如,如果一些数据灰度值特征和一些区域特性,或者混合区域特性,例如,“循环”(单位:标量)和“区域”(单位:像素的平方))。在这些情况下,训练网络的通常比没有规范化时需要更少的迭代。转换特征向量的预处理类型NumComponents (input_control)  Preprocessing parameter: Number of transformed features (ignored for Preprocessing = 'none' and Preprocessing = 'normalization'). Default value: 10 Suggested values: 1, 2, 3, 4, 5, 8, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100 Restriction: NumComponents >= 1预处理参数:转换后的特征数(Preprocessing = 'none'和Preprocessing = 'normalization'时忽略)RandSeed (input_control)  Seed value of the random number generator that is used to initialize the MLP with random values. Default value: 42用于用随机值初始化MLP的随机数生成器的种子值MLPHandle (output_control)  MLP handle.输出的MLP句柄 add_samples_image_class_mlp (将图像中的训练样本添加到多层感知器的训练数据中) Image (input_object) Training image.训练的图像ClassRegions (input_object) Regions of the classes to be trained.要训练的样本MLPHandle (input_control, state is modified)  MLP handle.MLP句柄 train_class_mlp (训练多层感知器). MLPHandle (input_control, state is modified)MLP handle.MLP句柄MaxIterations (input_control)  Maximum number of iterations of the optimization algorithm. Default value: 200 Suggested values: 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300优化算法的最大迭代次数WeightTolerance (input_control)  

Threshold for the difference of the weights of the MLP between two iterations of the optimization algorithm. Default value: 1.0 Suggested values: 1.0, 0.1, 0.01, 0.001, 0.0001, 0.00001 Restriction: WeightTolerance >= 1.0e-8

阈值为MLP在两次迭代之间进行优化算法的权值之差ErrorTolerance (input_control)Threshold for the difference of the mean error of the MLP on the training data between two iterations of the optimization algorithm. Default value: 0.01 Suggested values: 1.0, 0.1, 0.01, 0.001, 0.0001, 0.00001 Restriction: ErrorTolerance >= 1.0e-8阈值为MLP对训练数据的平均误差在两次迭代优化算法之间的差值Error (output_control)  Mean error of the MLP on the training data.MLP训练数据的平均误差ErrorLog (output_control) Mean error of the MLP on the training data as a function of the number of iterations of the optimization algorithm.MLP训练数据的平均误差作为优化算法迭代次数的函数 write_class_mlp(保存训练结果) MLPHandle (input_control)  MLP handle.MLP句柄FileName (input_control) File name. File extension: .gmc文件路径 clear_class_mlp (删除多层感知器) MLPHandle (input_control, state is modified)  MLP handle.MLP句柄 read_class_mlp(读取训练结果) FileName (input_control)  File name. File extension: .gmc文件路径MLPHandle (output_control)  MLP handle.MLP句柄 classify_image_class_mlp (用多层感知器对图像进行分类) Image (input_object)Input image.图像ClassRegions (output_object)  Segmented classes.输出的检测结果MLPHandle (input_control) MLP handle.MLP句柄RejectionThreshold (input_control)

Threshold for the rejection of the classification. Default value: 0.5 Suggested values: 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 Restriction: (RejectionThreshold >= 0.0) && (RejectionThreshold <= 1.0)

抛弃种类的阈值

 

使用:

搜集训练数据。创建MLP,得到MLP的识别符(句柄)。然后采集数据、训练(保存、清除和读取)长久保存时可使用)。MLP识别后分类。注意:识别得到的结果和特征值的索引是反序的,即color数组和ClassRegions数组取到区域的对应是反序的。 read_image (Image, 'E:/照片/RGB.jpg') *Red,Green,Blue,Dark(背景色) color :=['R', 'G', 'B','D'] gen_empty_obj (Classes) dev_set_draw ('margin') for i := 1 to |color| by 1 dev_display (Image) dev_display(Classes) draw_rectangle1 (3600, Row1, Column1, Row2, Column2) gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2) concat_obj (Rectangle, Classes, Classes) endfor pathFile := 'E:/照片/color.mlp' *创建分类器 create_class_mlp (3, 10, 4, 'softmax', 'normalization', 10, 42, MLPHandle) *采集 add_samples_image_class_mlp (Image, Classes, MLPHandle) *训练 train_class_mlp (MLPHandle, 100, 1, 0.01, Error, ErrorLog) *保存 write_class_mlp (MLPHandle, pathFile) *清除 clear_class_mlp (MLPHandle) *读取 read_class_mlp (pathFile, MLPHandle) *识别 classify_image_class_mlp (Image, ClassRegions, MLPHandle, 0.5) count_obj (ClassRegions, Number) for j := 1 to Number by 1 select_obj (ClassRegions, ObjectSelected, j) connection (ObjectSelected, ConnectedRegions) select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 200, 99999) area_center (SelectedRegions, Area, Row, Column) for k:= 0 to |Area|-1 by 1 disp_message (3600, color[|color| - j], 'image', Row[k], Column[k], 'black', 'true') endfor endfor RGB.jpg

 

搜集数据

 

 

 


最新回复(0)