Halcon颜色分类-MLP

 简介:

                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 >= 1
MLP的输入特征数量
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 >= 1
MLP的隐藏特征数量
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 >= 1
MLP的输出变量的数量
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)

抛弃种类的阈值

 

使用:

  1. 搜集训练数据。
  2. 创建MLP,得到MLP的识别符(句柄)。然后采集数据、训练(保存、清除和读取)长久保存时可使用)。
  3. 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

 

搜集数据

 

 

 

  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值