CN116168388A - Litchi epidermis defect identification method and system - Google Patents
Litchi epidermis defect identification method and system Download PDFInfo
- Publication number
- CN116168388A CN116168388A CN202211607412.2A CN202211607412A CN116168388A CN 116168388 A CN116168388 A CN 116168388A CN 202211607412 A CN202211607412 A CN 202211607412A CN 116168388 A CN116168388 A CN 116168388A
- Authority
- CN
- China
- Prior art keywords
- litchi
- bounding box
- defect
- skin defect
- bounding
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Withdrawn
Links
- 230000007547 defect Effects 0.000 title claims abstract description 266
- 241001629511 Litchi Species 0.000 title claims abstract description 233
- 238000000034 method Methods 0.000 title claims abstract description 38
- 210000002615 epidermis Anatomy 0.000 title claims abstract description 19
- 210000003491 skin Anatomy 0.000 claims abstract description 200
- 238000001514 detection method Methods 0.000 claims abstract description 154
- 238000000605 extraction Methods 0.000 claims abstract description 28
- 230000007246 mechanism Effects 0.000 claims abstract description 23
- 210000002569 neuron Anatomy 0.000 claims description 42
- 230000006870 function Effects 0.000 claims description 22
- 238000004364 calculation method Methods 0.000 claims description 15
- 238000012549 training Methods 0.000 claims description 14
- 238000012216 screening Methods 0.000 claims description 12
- 238000002372 labelling Methods 0.000 claims description 11
- 230000009466 transformation Effects 0.000 claims description 11
- 230000004927 fusion Effects 0.000 claims description 8
- 238000004590 computer program Methods 0.000 claims description 6
- 238000013434 data augmentation Methods 0.000 claims description 4
- 238000001914 filtration Methods 0.000 claims description 3
- 238000004422 calculation algorithm Methods 0.000 abstract description 9
- 244000183278 Nephelium litchi Species 0.000 description 9
- 235000015742 Nephelium litchi Nutrition 0.000 description 9
- 238000010586 diagram Methods 0.000 description 4
- 235000013399 edible fruits Nutrition 0.000 description 4
- 230000000694 effects Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 3
- 238000007689 inspection Methods 0.000 description 2
- 239000011159 matrix material Substances 0.000 description 2
- 230000008569 process Effects 0.000 description 2
- 230000001629 suppression Effects 0.000 description 2
- 230000004931 aggregating effect Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000015556 catabolic process Effects 0.000 description 1
- 238000006731 degradation reaction Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000018109 developmental process Effects 0.000 description 1
- 235000013305 food Nutrition 0.000 description 1
- 235000012055 fruits and vegetables Nutrition 0.000 description 1
- 230000001788 irregular Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
- 230000009467 reduction Effects 0.000 description 1
- 230000011218 segmentation Effects 0.000 description 1
- 238000012706 support-vector machine Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
- 238000011179 visual inspection Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V20/00—Scenes; Scene-specific elements
- G06V20/60—Type of objects
- G06V20/68—Food, e.g. fruit or vegetables
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/08—Learning methods
- G06N3/082—Learning methods modifying the architecture, e.g. adding, deleting or silencing nodes or connections
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V10/00—Arrangements for image or video recognition or understanding
- G06V10/20—Image preprocessing
- G06V10/22—Image preprocessing by selection of a specific region containing or referencing a pattern; Locating or processing of specific regions to guide the detection or recognition
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V10/00—Arrangements for image or video recognition or understanding
- G06V10/70—Arrangements for image or video recognition or understanding using pattern recognition or machine learning
- G06V10/764—Arrangements for image or video recognition or understanding using pattern recognition or machine learning using classification, e.g. of video objects
- G06V10/765—Arrangements for image or video recognition or understanding using pattern recognition or machine learning using classification, e.g. of video objects using rules for classification or partitioning the feature space
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V10/00—Arrangements for image or video recognition or understanding
- G06V10/70—Arrangements for image or video recognition or understanding using pattern recognition or machine learning
- G06V10/82—Arrangements for image or video recognition or understanding using pattern recognition or machine learning using neural networks
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02P—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
- Y02P90/00—Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
- Y02P90/30—Computing systems specially adapted for manufacturing
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Evolutionary Computation (AREA)
- Multimedia (AREA)
- Health & Medical Sciences (AREA)
- Computing Systems (AREA)
- Artificial Intelligence (AREA)
- General Health & Medical Sciences (AREA)
- Software Systems (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Databases & Information Systems (AREA)
- Medical Informatics (AREA)
- Biomedical Technology (AREA)
- Life Sciences & Earth Sciences (AREA)
- Biophysics (AREA)
- Computational Linguistics (AREA)
- Data Mining & Analysis (AREA)
- Molecular Biology (AREA)
- General Engineering & Computer Science (AREA)
- Mathematical Physics (AREA)
- Investigating Materials By The Use Of Optical Means Adapted For Particular Applications (AREA)
Abstract
本发明公开了一种荔枝表皮缺陷识别方法及系统,获取待检测荔枝表皮缺陷图像后,调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对荔枝表皮缺陷图像进行检测,先将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个标注后的荔枝表皮缺陷图像的网格得到各个网格中的多个边界框,对各个边界框中的荔枝表皮缺陷进行识别打分得到各个边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,根据最终检测框输出荔枝表皮缺陷图像上的缺陷位置,通过采用改进后的算法构建检测模型对荔枝缺陷进行识别分类,提出荔枝的表皮缺陷,可以提高模型检测准确率。
The invention discloses a litchi epidermis defect identification method and system. After obtaining the litchi epidermis defect image to be detected, the target detection model built by adding the improved attention mechanism SimAM network into the main feature extraction network is called to perform the litchi epidermis defect image. For detection, first adjust the litchi skin defect image to the same resolution, and then perform grid division on the litchi skin defect image, and traverse the grids of each marked litchi skin defect image to obtain multiple bounding boxes in each grid, Identify and score the skin defects of litchi in each bounding box to obtain the credibility score of each bounding box. According to the credibility score of the bounding box, select the bounding box larger than the preset requirements as the final detection frame, and output the litchi according to the final detection frame. Defect position on the skin defect image, by using the improved algorithm to build a detection model to identify and classify litchi defects, and propose litchi skin defects, which can improve the accuracy of model detection.
Description
技术领域technical field
本发明涉及目标检测技术领域,尤其涉及一种荔枝表皮缺陷识别方法及系统。The invention relates to the technical field of target detection, in particular to a method and system for identifying skin defects of litchi.
背景技术Background technique
传统的荔枝外观品质检测主要是依靠目测和选果板对比的方式进行人工分选,其劳动强度大,效率低,分级效果受到劳动者的疲劳程度及情绪波动等影响较大,造成分级品质残次不齐,分级效果差;而且荔枝经过人工挑选,会受到不同程度的损伤,造成二次污染,影响产品的食品卫生安全。The traditional appearance quality inspection of litchi mainly relies on manual sorting by visual inspection and fruit selection board comparison, which is labor-intensive and low in efficiency. The grading effect is poor due to irregular times; and the lychees will be damaged to varying degrees after manual selection, causing secondary pollution and affecting the food hygiene and safety of the product.
国内目前的荔枝分级机都是通过控制直径大小间隙来分选荔枝,不能对荔枝表面缺陷进行检测,并且分级过程中荔枝多次与机械磨碰,容易出现破损降级现象。针对以上现象,研发出一种荔枝表皮缺陷分类的识别方法,对降低果蔬产业后的劳动成本,对农业产品和农业经济的发展有着重要的意义。机器视觉是研发荔枝表皮缺陷分类的关键技术,为荔枝品质检测提供了技术手段。现有的利用计算机视觉检测农产品品质的技术。The current lychee grading machines in China sort lychees by controlling the gap between diameter and size. They cannot detect surface defects of lychees, and lychees are repeatedly rubbed against machinery during the grading process, which is prone to damage and degradation. In view of the above phenomena, a recognition method for the classification of litchi skin defects has been developed, which is of great significance to the reduction of labor costs after the fruit and vegetable industry, and to the development of agricultural products and agricultural economy. Machine vision is a key technology for the classification of litchi skin defects, and it provides a technical means for litchi quality inspection. Existing technologies that use computer vision to detect the quality of agricultural products.
现有的技术有基于颜色特征的缺陷提取算法及基于照度–反射模型,但这些算法需要设定阈值,自适应性不高,有些水果缺陷区域与正常区域有明显的边缘,因此提出了基于边缘信息的缺陷提取算法,在表皮光滑的水果上取得了较好的效果,在荔枝上的效果不理想。此外,还有基于贝叶斯分类器、SVM等传统监督学习的缺陷提取方法,根据像素值将像素点分为“正常”与“缺陷”2类,从而实现缺陷分割,由于荔枝表皮布满鳞斑状突起,上述的算法不能很好地应用于荔枝的表皮缺陷提取。Existing technologies include defect extraction algorithms based on color features and illuminance-reflection models, but these algorithms need to set thresholds, and the adaptability is not high. Some fruit defect areas have obvious edges with normal areas, so an edge-based The defect extraction algorithm of information has achieved good results on smooth-skinned fruits, but the effect on lychees is not ideal. In addition, there are defect extraction methods based on traditional supervised learning such as Bayesian classifiers and SVMs. According to the pixel value, the pixels are divided into two categories: "normal" and "defect", so as to realize defect segmentation. Spot-like protrusions, the above algorithm cannot be well applied to the extraction of epidermal defects of litchi.
发明内容Contents of the invention
本发明提供了一种荔枝表皮缺陷识别方法及系统,通过利用改进后的主干特征网络构建目标检测模型对荔枝缺陷进行识别分类,提高了目标检测模型检测的准确率和通用性。The invention provides a litchi epidermis defect identification method and system. By using the improved backbone feature network to build a target detection model to identify and classify litchi defects, the accuracy and versatility of the target detection model are improved.
为了解决上述技术问题,本发明实施例提供了一种荔枝表皮缺陷识别方法及系统,包括:In order to solve the above technical problems, the embodiment of the present invention provides a litchi skin defect identification method and system, including:
获取待检测荔枝表皮缺陷图像;Obtain an image of the skin defect of litchi to be detected;
调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对标注后的荔枝表皮缺陷图像进行检测,以使目标检测模型将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个标注后的荔枝表皮缺陷图像的网格得到各个网格中的多个边界框,对各个边界框中的荔枝表皮缺陷进行识别打分得到各个边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,根据最终检测框输出荔枝表皮缺陷检测结果,其中,荔枝表皮缺陷检测结果包括荔枝表皮缺陷图像上的缺陷位置。Call the target detection model built by adding the improved attention mechanism SimAM network to the backbone feature extraction network to detect the marked litchi skin defect image, so that after the target detection model adjusts the litchi skin defect image to the same resolution, After meshing the litchi skin defect image, traverse the grids of each marked litchi skin defect image to obtain multiple bounding boxes in each grid, and identify and score the litchi skin defects in each bounding box to obtain each bounding box According to the credibility score of the bounding box, the bounding box larger than the preset requirement is screened out as the final detection frame, and the detection result of the litchi skin defect is output according to the final detection frame, wherein, the detection result of the litchi skin defect includes the litchi skin defect The location of the defect on the image.
实施本实施例,获取待检测荔枝表皮缺陷图像,调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对荔枝表皮缺陷图像进行检测,目标检测模型先将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个荔枝表皮缺陷图像的网格得到各个网格中的多个边界框,对各个边界框中的所述荔枝表皮缺陷进行识别打分得到各个边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,根据最终检测框输出荔枝表皮缺陷图像上的缺陷位置。通过采用改进后的算法构建检测模型对荔枝缺陷进行识别分类,提出荔枝的表皮缺陷,可以提高模型检测准确率。Implement this embodiment, obtain the defect image of the litchi skin to be detected, and call the target detection model built by adding the improved attention mechanism SimAM network in the backbone feature extraction network to detect the defect image of the litchi skin. After the defect images are adjusted to the same resolution, after the litchi skin defect images are meshed, the grids of each litchi skin defect image are traversed to obtain multiple bounding boxes in each grid, and the litchi skin in each bounding box is Defects are identified and scored to obtain the reliability scores of each bounding box. According to the reliability scores of the bounding boxes, the bounding boxes larger than the preset requirements are selected as the final detection frame, and the defect position on the litchi skin defect image is output according to the final detection frame. By using the improved algorithm to build a detection model to identify and classify litchi defects, and to propose litchi skin defects, the accuracy of model detection can be improved.
作为优选方案,改进后的注意力机制SimAM网络通过对能量函数、求解公式以及特征提取过程进行重新定义得到的,具体为:As a preferred solution, the improved attention mechanism SimAM network is obtained by redefining the energy function, solution formula and feature extraction process, specifically:
通过采用二值标签,并添加正则项重新定义注意力机制SimAM网络的能量函数,其中,能量函数公式为:Redefine the energy function of the attention mechanism SimAM network by using binary labels and adding regular terms, where the energy function formula is:
其中,为t和xi的线性变换,其中,t和xi表示输入特征/>的单个通道中的目标神经元和其他神经元,C,H和W分别为通道注意力的长,高和宽,i是指数除以空间维度,M=H×W是通道上的神经元数量,ωt和bt分别表示变换的权值和偏置;in, is the linear transformation of t and xi , where t and xi represent input features/> The target neuron and other neurons in a single channel of , C, H and W are the length, height and width of the channel attention respectively, i is the index divided by the spatial dimension, M=H×W is the number of neurons on the channel , ω t and b t represent the weight and bias of the transformation, respectively;
利用求解公式更新能量函数求解方法,求解公式为:Use the solution formula to update the energy function solution method, and the solution formula is:
其中, μt表示对应通道中的除t以外的所有神经元的均值,/>表示对应通道中的除t以外的所有神经元的方差,/>表示能每个神经元的重要性。in, μ t represents the mean value of all neurons in the corresponding channel except t, /> Indicates the variance of all neurons in the corresponding channel except t, /> Indicates the importance of each neuron.
采用缩放的操作对缺陷特征进行提取,其中,特征提取过程为:The defect feature is extracted by zooming operation, where the feature extraction process is:
其中,E表示在所有通道和空间维度的汇总,sigmoid表示约束过大的值。Among them, E means Aggregated across all channels and spatial dimensions, sigmoid represents overly constrained values.
实施本发明实施例,通过采用二值标签,并添加正则项重新定义注意力机制SimAM网络的能量函数后,利用更新后的求解公式对能量函数进行求解,可以使构建好的目标检测模型在检测中能够提高计算效率,快速对荔枝的表皮缺陷特征进行提取。Implementing the embodiment of the present invention, by using binary labels and adding a regular term to redefine the energy function of the attention mechanism SimAM network, and using the updated solution formula to solve the energy function, the constructed target detection model can be detected In this method, the calculation efficiency can be improved, and the skin defect features of litchi can be extracted quickly.
作为优选方案,对边界框中的荔枝表皮缺陷进行识别打分得到边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,具体为:As an optimal solution, identify and score the skin defects of litchi in the bounding box to obtain the credibility score of the bounding box, and filter out the bounding box larger than the preset requirement according to the credibility score of the bounding box as the final detection box, specifically:
对边界框中的荔枝表皮缺陷进行识别打分得到边界框的可信度分数;Identify and score the litchi skin defects in the bounding box to obtain the confidence score of the bounding box;
将低于第一预设分数的边界框删除后,对剩余的边界框根据可信度分数按照从大到小排列得到边界框排列结果;After deleting the bounding boxes with scores lower than the first preset score, arrange the remaining bounding boxes according to the reliability scores from large to small to obtain bounding box arrangement results;
筛选出与在边界框排列结果中排名第一的边界框融合后低于预设误差的边界框得到第一边界框检测集,其中,第一边界框检测集的边界框根据可信度分数按照从大到小排列;Filter out bounding boxes that are lower than the preset error after being fused with the bounding box ranked first in the bounding box arrangement results to obtain the first bounding box detection set, wherein the bounding boxes of the first bounding box detection set are based on the confidence score according to Arranged from largest to smallest;
筛选出在第一边界框检测集中与在排名第二的边界框融合后低于预设误差的边界框后得到第二边界框检测集,并从第二边界框检测集筛选出排名第一的边界框作为最终检测框。After filtering out the bounding boxes that are lower than the preset error after the fusion of the first bounding box detection set and the second-ranked bounding box, the second bounding box detection set is obtained, and the first-ranked bounding box is filtered from the second bounding box detection set. The bounding box serves as the final detection box.
作为优选方案,对边界框中的所述荔枝表皮缺陷进行识别打分得到边界框的可信度分数,具体为:As a preferred solution, the lychee skin defects in the bounding box are identified and scored to obtain the confidence score of the bounding box, specifically:
对边界框中的所述荔枝表皮缺陷进行识别得到识别得分;Identifying the skin defect of litchi in the bounding box to obtain the recognition score;
根据边界框和实际缺陷框的覆盖面积得到IOU分数;The IOU score is obtained according to the coverage area of the bounding box and the actual defect box;
将识别得分和IOU分数相乘得到可信度分数。The confidence score is obtained by multiplying the recognition score and the IOU score.
作为优选方案,目标检测模型是通过训练方法进行训练得到的,训练方法为:As a preferred solution, the target detection model is obtained by training through a training method, and the training method is:
获取待检测荔枝表皮缺陷图像,并对各个荔枝缺陷图像进行过采样和数据增广得到荔枝表皮缺陷数据集;Obtain the image of litchi skin defect to be detected, and perform oversampling and data augmentation on each litchi defect image to obtain the litchi skin defect data set;
对荔枝表皮缺陷数据集中的各个荔枝表皮缺陷图像进行标注后得到标注后的荔枝表皮缺陷数据集;After labeling each litchi skin defect image in the litchi skin defect data set, an annotated litchi skin defect data set is obtained;
调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对标注后的荔枝表皮缺陷图像进行检测,以使目标检测模型将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个标注后的荔枝表皮缺陷图像的网格得到各个网格中的边界框后,对边界框中的荔枝表皮缺陷进行识别打分得到边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框;Call the target detection model built by adding the improved attention mechanism SimAM network to the backbone feature extraction network to detect the marked litchi skin defect image, so that after the target detection model adjusts the litchi skin defect image to the same resolution, After meshing the litchi skin defect image, traverse the grids of each marked litchi skin defect image to obtain the bounding box in each grid, and then identify and score the litchi skin defect in the bounding box to obtain the credibility of the bounding box Degree score, according to the confidence score of the bounding box, the bounding box larger than the preset requirement is screened out as the final detection box;
采用损失函数计算最终检测框和预期结果的误差对目标检测模型进行评估后更新模型参数,选取荔枝表皮缺陷数据集中未检测过的荔枝表皮缺陷图像进行检测直到达到预设训练次数得到目标检测模型。The loss function is used to calculate the error between the final detection frame and the expected result to evaluate the target detection model, and then update the model parameters. Select undetected litchi skin defect images in the litchi skin defect dataset for detection until the preset training times are reached to obtain the target detection model.
作为优选方案,对荔枝表皮缺陷数据集中的各个荔枝表皮缺陷图像进行标注后得到标注后的荔枝表皮缺陷数据集,具体为:As a preferred solution, after labeling each litchi skin defect image in the litchi skin defect data set, the marked litchi skin defect data set is obtained, specifically:
对荔枝表皮缺陷图像中的荔枝表皮缺陷使用矩形框将图像中的荔枝缺陷区域标注出来得到多个边界框;Use a rectangular frame to mark out the litchi defect area in the image to obtain multiple bounding boxes for the litchi skin defect in the litchi skin defect image;
根据边界框设置对应的标签类型,其中,标签类型包括黑点掉落和裂纹。Set the corresponding label type according to the bounding box, where the label type includes black dot drop and crack.
作为优选方案,为了解决相同的技术问题,本发明实施例还提供了一种荔枝表皮缺陷识别系统,包括样本获取模块、标注模块和检测模块;As a preferred solution, in order to solve the same technical problem, an embodiment of the present invention also provides a litchi skin defect identification system, including a sample acquisition module, a labeling module and a detection module;
其中,样本获取模块用于获取待检测荔枝表皮缺陷图像;Wherein, the sample acquisition module is used to acquire the image of the skin defect of litchi to be detected;
标注模块用于对待检测荔枝表皮缺陷图像进行标注后得到标注后的荔枝表皮缺陷图像,其中,标注后的荔枝表皮缺陷图像中包括多个真实框;The marking module is used to mark the litchi skin defect image to be detected to obtain the marked litchi skin defect image, wherein the marked litchi skin defect image includes a plurality of real frames;
检测模块用于调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对标注后的荔枝表皮缺陷图像进行检测,以使目标检测模型将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个标注后的荔枝表皮缺陷图像的网格得到各个网格中的多个边界框,对各个边界框中的所述荔枝表皮缺陷进行识别打分得到各个边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,根据所述最终检测框输出荔枝表皮缺陷检测结果,其中,荔枝表皮缺陷检测结果包括荔枝表皮缺陷图像上的缺陷位置。The detection module is used to call the target detection model built by adding the improved attention mechanism SimAM network to the backbone feature extraction network to detect the marked litchi skin defect image, so that the target detection model adjusts the litchi skin defect image to the same After the resolution, after the litchi skin defect image is meshed, the grid of the litchi skin defect image after each label is traversed to obtain a plurality of bounding boxes in each grid, and the litchi skin defect in each bounding box is carried out Recognize and score to obtain the credibility scores of each bounding box, screen out the bounding boxes larger than the preset requirements according to the credibility scores of the bounding boxes as the final detection frame, and output the detection results of litchi skin defects according to the final detection frame, wherein, litchi The skin defect detection results include defect locations on the litchi skin defect image.
作为优选方案,检测模块包括可信度分数计算单元、边界框排列单元、第一筛选单元和第二筛选单元,As a preferred solution, the detection module includes a credibility score calculation unit, a bounding box arrangement unit, a first screening unit and a second screening unit,
可信度分数计算单元用于对边界框中的所述荔枝表皮缺陷进行识别打分得到边界框的可信度分数;The credibility score calculation unit is used to identify and score the litchi skin defects in the bounding box to obtain the credibility score of the bounding box;
边界框排列单元用于将低于第一预设分数的边界框删除后,对剩余的边界框根据可信度分数按照从大到小排列得到边界框排列结果;The bounding box arranging unit is used to delete the bounding boxes with scores lower than the first preset score, and then arrange the remaining bounding boxes according to the reliability scores in descending order to obtain the bounding box arrangement result;
第一筛选单元用于筛选出与在边界框排列结果中排名第一的边界框融合后低于预设误差的边界框得到第一边界框检测集,其中,第一边界框检测集的边界框根据所述可信度分数按照从大到小排列;The first screening unit is used to filter out bounding boxes that are lower than the preset error after being fused with the bounding box ranked first in the bounding box arrangement result to obtain the first bounding box detection set, wherein the bounding boxes of the first bounding box detection set According to the credibility scores, they are arranged in descending order;
第二筛选单元用于筛选出在第一边界框检测集中与在排名第二的边界框融合后低于预设误差的边界框后得到第二边界框检测集,并从第二边界框检测集筛选出排名第一的边界框作为最终检测框。The second screening unit is used to filter out the bounding boxes that are lower than the preset error after the fusion of the first bounding box detection set and the second-ranked bounding box to obtain the second bounding box detection set, and from the second bounding box detection set Filter out the top bounding box as the final detection box.
作为优选方案,为了解决相同的技术问题,本发明实施例还提供了一种终端设备,包括:存储器,处理器及存储在存储器上并可在处理器上运行的计算机程序,处理器执行程序时实现如本发明实施例所示的荔枝表皮缺陷识别方法。As a preferred solution, in order to solve the same technical problem, an embodiment of the present invention also provides a terminal device, including: a memory, a processor, and a computer program stored on the memory and operable on the processor, when the processor executes the program Realize the litchi epidermis defect recognition method as shown in the embodiment of the present invention.
作为优选方案,为了解决相同的技术问题,本发明实施例还提供了一种计算机可读存储介质,计算机可读存储介质存储有计算机可执行程序,计算机可执行程序用于使计算机执行如本发明实施例所示的荔枝表皮缺陷识别方法的步骤。As a preferred solution, in order to solve the same technical problem, the embodiment of the present invention also provides a computer-readable storage medium, the computer-readable storage medium stores a computer-executable program, and the computer-executable program is used to enable the computer to execute the present invention. The steps of the litchi skin defect recognition method shown in the embodiment.
获取待检测荔枝表皮缺陷图像,调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对标注后的荔枝表皮缺陷图像进行检测,目标检测模型先将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个标注后的荔枝表皮缺陷图像的网格得到各个网格中的多个边界框,对各个边界框中的所述荔枝表皮缺陷进行识别打分得到各个边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,根据最终检测框输出荔枝表皮缺陷图像上的缺陷位置。通过采用改进后的算法构建检测模型对荔枝缺陷进行识别分类,提出荔枝的表皮缺陷,可以提高模型检测准确率。Obtain the image of litchi skin defect to be detected, and call the target detection model built by adding the improved attention mechanism SimAM network to the backbone feature extraction network to detect the marked litchi skin defect image. The target detection model first takes the litchi skin defect image After adjusting to the same resolution, after the litchi skin defect image is meshed, traverse the grids of each marked litchi skin defect image to obtain multiple bounding boxes in each grid, and for the litchi skin defect images in each bounding box Identify and score the skin defects to obtain the credibility scores of each bounding box, screen out the bounding boxes larger than the preset requirements according to the credibility scores of the bounding boxes as the final detection frame, and output the defect position on the litchi skin defect image according to the final detection frame . By using the improved algorithm to build a detection model to identify and classify litchi defects, and to propose litchi skin defects, the accuracy of model detection can be improved.
附图说明Description of drawings
图1:为本发明提供的荔枝表皮缺陷识别方法的一种实施例的流程示意图;Fig. 1: a schematic flow chart of an embodiment of the litchi skin defect identification method provided by the present invention;
图2:为本发明提供的荔枝表皮缺陷识别方法的一种实施例的改进后的YOLOv7主干网络结构示意图;Figure 2: Schematic diagram of the improved YOLOv7 backbone network structure of an embodiment of the litchi skin defect recognition method provided by the present invention;
图3:为本发明提供的荔枝表皮缺陷识别方法的一种实施例的模型训练流程示意图;Fig. 3: a schematic diagram of the model training process of an embodiment of the litchi skin defect recognition method provided by the present invention;
图4:为本发明提供的荔枝表皮缺陷识别方法的另一种实施例的结构示意图。Fig. 4: A structural schematic diagram of another embodiment of the method for identifying skin defects of litchi provided by the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of the present invention.
实施例一Embodiment one
请参照图1,为本发明实施例提供的荔枝表皮缺陷识别方法,该荔枝表皮缺陷识别方法包括步骤101至步骤102,各步骤具体如下:Please refer to Fig. 1, which is a method for identifying skin defects of litchi provided by an embodiment of the present invention. The method for identifying skin defects of litchi includes
步骤101:获取待检测荔枝表皮缺陷图像。Step 101: Obtain an image of skin defects of litchi to be detected.
在本实施例中,获取待检测荔枝表皮缺陷图像。In this embodiment, an image of skin defects of litchi to be detected is acquired.
步骤102:调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对标注后的荔枝表皮缺陷图像进行检测,以使目标检测模型将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个标注后的荔枝表皮缺陷图像的网格得到各个网格中的多个边界框,对各个边界框中的所述荔枝表皮缺陷进行识别打分得到各个边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,根据最终检测框输出荔枝表皮缺陷检测结果,其中,荔枝表皮缺陷检测结果包括荔枝表皮缺陷图像上的缺陷位置。Step 102: Call the target detection model built by adding the improved attention mechanism SimAM network to the backbone feature extraction network to detect the marked litchi skin defect image, so that the target detection model adjusts the litchi skin defect image to the same resolution After performing grid division on the litchi skin defect image, traverse the grids of each marked litchi skin defect image to obtain a plurality of bounding boxes in each grid, and identify the litchi skin defect in each bounding box Score to get the credibility score of each bounding box, screen out the bounding box larger than the preset requirement according to the credibility score of the bounding box as the final detection frame, and output the detection result of litchi skin defect according to the final detection frame, among which, litchi skin defect detection The results include defect locations on the litchi skin defect image.
可选的,改进后的注意力机制SimAM网络通过对能量函数、求解公式以及特征提取过程进行重新定义得到的,具体为:Optionally, the improved attention mechanism SimAM network is obtained by redefining the energy function, solution formula and feature extraction process, specifically:
通过采用二值标签,并添加正则项重新定义注意力机制SimAM网络的能量函数,其中,能量函数公式为:Redefine the energy function of the attention mechanism SimAM network by using binary labels and adding regular terms, where the energy function formula is:
其中,为t和xi的线性变换,其中,t和xi表示输入特征/>的单个通道中的目标神经元和其他神经元,C,H和W分别为通道注意力的长,高和宽,i是指数除以空间维度,M=H×W是通道上的神经元数量,ωt和bt分别表示变换的权值和偏置;in, is the linear transformation of t and xi , where t and xi represent input features/> The target neuron and other neurons in a single channel of , C, H and W are the length, height and width of the channel attention respectively, i is the index divided by the spatial dimension, M=H×W is the number of neurons on the channel , ω t and b t represent the weight and bias of the transformation, respectively;
利用求解公式更新能量函数求解方法,求解公式为:Use the solution formula to update the energy function solution method, and the solution formula is:
其中,μt表示对应通道中的除t以外的所有神经元的均值,/>表示对应通道中的除t以外的所有神经元的方差,/>表示能每个神经元的重要性。in, μ t represents the mean value of all neurons in the corresponding channel except t, /> Indicates the variance of all neurons in the corresponding channel except t, /> Indicates the importance of each neuron.
采用缩放的操作对缺陷特征进行提取,其中,特征提取过程为:The defect feature is extracted by zooming operation, where the feature extraction process is:
可选的,对边界框中的荔枝表皮缺陷进行识别打分得到边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,具体为:Optionally, identify and score the litchi skin defects in the bounding box to obtain the confidence score of the bounding box, and filter out the bounding box larger than the preset requirement as the final detection box according to the credibility score of the bounding box, specifically:
对边界框中的荔枝表皮缺陷进行识别打分得到边界框的可信度分数;Identify and score the litchi skin defects in the bounding box to obtain the confidence score of the bounding box;
将低于第一预设分数的边界框删除后,对剩余的边界框根据可信度分数按照从大到小排列得到边界框排列结果;After deleting the bounding boxes with scores lower than the first preset score, arrange the remaining bounding boxes according to the reliability scores from large to small to obtain bounding box arrangement results;
筛选出与在边界框排列结果中排名第一的边界框融合后低于预设误差的边界框得到第一边界框检测集,其中,第一边界框检测集的边界框根据可信度分数按照从大到小排列;Filter out bounding boxes that are lower than the preset error after being fused with the bounding box ranked first in the bounding box arrangement results to obtain the first bounding box detection set, wherein the bounding boxes of the first bounding box detection set are based on the confidence score according to Arranged from largest to smallest;
筛选出在第一边界框检测集中与在排名第二的边界框融合后低于预设误差的边界框后得到第二边界框检测集,并从第二边界框检测集筛选出排名第一的边界框作为最终检测框。After filtering out the bounding boxes that are lower than the preset error after the fusion of the first bounding box detection set and the second-ranked bounding box, the second bounding box detection set is obtained, and the first-ranked bounding box is filtered from the second bounding box detection set. The bounding box serves as the final detection box.
可选的,对边界框中的荔枝表皮缺陷进行识别打分得到边界框的可信度分数,具体为:Optionally, identify and score the litchi skin defects in the bounding box to obtain the confidence score of the bounding box, specifically:
对边界框中的荔枝表皮缺陷进行识别得到识别得分;Identify the litchi skin defects in the bounding box to obtain the recognition score;
根据边界框和实际缺陷框的覆盖面积得到IOU分数;The IOU score is obtained according to the coverage area of the bounding box and the actual defect box;
将识别得分和IOU分数相乘得到可信度分数。The confidence score is obtained by multiplying the recognition score and the IOU score.
具体地,在本实施例中,目标检测模型的主干特征提取网络为改进后的YOLOv7主干网络,由YOLOv7主干网络中加入注意力机制SimAM构成,改进后的YOLOv7主干网络结构如图2所示。Specifically, in this embodiment, the backbone feature extraction network of the target detection model is an improved YOLOv7 backbone network, which is composed of the attention mechanism SimAM added to the YOLOv7 backbone network. The improved YOLOv7 backbone network structure is shown in Figure 2.
注意力机制SimAM无需向原始网络添加参数,而是在一层中推断特征图的3-D关注权重,其可以采用最简单的寻找重要神经元的方法:度量神经元之间的线性可分性,针对每个神经元定义了如下的能量函数:The attention mechanism SimAM does not need to add parameters to the original network, but infers the 3-D attention weights of the feature map in one layer, which can adopt the simplest method of finding important neurons: measuring the linear separability between neurons , the following energy function is defined for each neuron:
其中,为t和xi的线性变换,其中,t和xi表示输入特征/>的单个通道中的目标神经元和其他神经元,C,H和W分别为通道注意力的长,高和宽,i是指数除以空间维度,M=H×W是通道上的神经元数量,ωt和bt分别表示变换的权值和偏置;in, is the linear transformation of t and xi , where t and xi represent input features/> The target neuron and other neurons in a single channel of , C, H and W are the length, height and width of the channel attention respectively, i is the index divided by the spatial dimension, M=H×W is the number of neurons on the channel , ω t and b t represent the weight and bias of the transformation, respectively;
当t=t时,获得最小值。通过将该方程最小化,等价于找到目标神经元t与同一通道中所有其他神经元之间的线性可分离性,为简单起见,可以采用二值标签,并添加正则项,最终的能量函数定义如下:When t= t , the minimum value is obtained. By minimizing this equation, which is equivalent to finding the linear separability between the target neuron t and all other neurons in the same channel, binary labels can be taken for simplicity, and a regularization term added, the final energy function It is defined as follows:
其中,为t和xi的线性变换,其中,t和xi表示输入特征/>的单个通道中的目标神经元和其他神经元,C,H和W分别为通道注意力的长,高和宽,i是指数除以空间维度,M=H×W是通道上的神经元数量,ωt和bt分别表示变换的权值和偏置;in, is the linear transformation of t and xi , where t and xi represent input features/> The target neuron and other neurons in a single channel of , C, H and W are the length, height and width of the channel attention respectively, i is the index divided by the spatial dimension, M=H×W is the number of neurons on the channel , ω t and b t represent the weight and bias of the transformation, respectively;
因为每个通道都有M个能量函数,采用以下公式可以快速求得解析解,公式如下所示:Because each channel has M energy functions, the analytical solution can be quickly obtained by using the following formula, which is as follows:
其中, μt表示对应通道中的除t以外的所有神经元的均值,/>表示对应通道中的除t以外的所有神经元的方差,/>表示能每个神经元的重要性。in, μ t represents the mean value of all neurons in the corresponding channel except t, /> Indicates the variance of all neurons in the corresponding channel except t, /> Indicates the importance of each neuron.
从上述两个公式可以看出解析解都是在单通道上得到的,因此可以合理的推测同一个通道的其他神经元也满足相同的分布。基于这个假设,在所有神经元上计算均值和方差,在同一通道上的所有神经元都可以复用这个均值和方差。因此可以避免了对每个位置的μ和σ的反复计算,降低计算成本。最后最小能量可由下式计算:From the above two formulas, it can be seen that the analytical solutions are all obtained on a single channel, so it is reasonable to speculate that other neurons of the same channel also satisfy the same distribution. Based on this assumption, the mean and variance are calculated on all neurons, and all neurons on the same channel can reuse this mean and variance. Therefore, the repeated calculation of μ and σ for each position can be avoided, and the calculation cost can be reduced. The final minimum energy can be calculated by the following formula:
其中,μt表示对应通道中的除t以外的所有神经元的均值,/>表示对应通道中的除t以外的所有神经元的方差,/>表示能每个神经元的重要性。in, μ t represents the mean value of all neurons in the corresponding channel except t, /> Indicates the variance of all neurons in the corresponding channel except t, /> Indicates the importance of each neuron.
最小能量公式说明,能量越低,神经元t和周围神经元的区别越大,在视觉处理中也越重要。因此,通过/>来表示每个神经元的重要性。在特征提取中,采用缩放的操作来做特征提炼,提炼过程如下:Minimum Energy Formula Explanation, Energy The lower it is, the greater the difference between neuron t and surrounding neurons, and the more important it is in visual processing. Therefore, by /> to represent the importance of each neuron. In feature extraction, the scaling operation is used for feature extraction, and the extraction process is as follows:
其中E是在所有通道和空间维度的汇总,sigmoid是用来约束过大的值,sigmoid是单调函数,不会影响每个神经元的相对大小。where E is Aggregating across all channels and spatial dimensions, sigmoid is used to constrain overly large values, and sigmoid is a monotonic function that does not affect the relative size of each neuron.
构建好目标检测模型后,调用目标检测模型对检测荔枝表皮缺陷图像进行检测,首先把检测荔枝表皮缺陷图像整理成相同分辨率,然后对荔枝表皮缺陷图片进行划网格,遍历网格找出每个荔枝表皮缺陷区域所对应的标签,每个网格单元负责检测一个荔枝表皮缺陷区域,网格单元根据系统设定采用边界框将缺陷区域标出来,然后对边界框的记性可信度进行评分,可信度计算包括识别的得分和边界框所覆盖的IOU的乘积,将产生的边界框和分类信息存在矩阵里。After the target detection model is built, the target detection model is called to detect the detection image of litchi skin defects. First, the detection images of litchi skin defects are sorted into the same resolution, and then the litchi skin defect images are drawn into a grid, and the grid is traversed to find each Each grid unit is responsible for detecting a litchi skin defect area. The grid unit uses a bounding box to mark the defect area according to the system settings, and then scores the memory reliability of the bounding box. , the credibility calculation includes the product of the recognition score and the IOU covered by the bounding box, and the generated bounding box and classification information are stored in the matrix.
然后进行损失计算,损失主要包括三个部分,第一个是对边界框位置的误差进行计算,在计算框位置时选择可信度分数最高的边界框进行计算。第二个就是IOU误差,IOU误差选择每个待检测荔枝表皮缺陷图像的最高得分边界框和剩下的边界框。Then perform loss calculation. The loss mainly includes three parts. The first is to calculate the error of the bounding box position. When calculating the box position, select the bounding box with the highest reliability score for calculation. The second is the IOU error, which selects the highest scoring bounding box and the remaining bounding boxes for each litchi skin defect image to be detected.
在计算得到每个边界框的记性可信度分数后,把低于预设值的边界框删除,优选地,预设值可定位0.2。之后根据边界框的记性可信度分数对剩余的边界框做一个从小到大的排序后得到排列结果,选取排列结果中最大的边界框,然后查找与最大的边界框融合超过第二预设值的其它边界框,采用非极大致抑制将这些超过第二预设值的其它边界框删除,把与最大的边界框融合超过低于第二预设值的边界框保存,优选地,第二预设值可选0.5。在剩下的边界框中,将排名第二的边界框作为对比框,查找与排名第二的边界框融合低于第二预设值的其它边界框并保存,最后在剩下的边界框中,选取一个最大得分的框作为最终检测框。After the memory reliability score of each bounding box is calculated, the bounding boxes lower than the preset value are deleted. Preferably, the preset value can be set at 0.2. Afterwards, according to the memory reliability score of the bounding box, sort the remaining bounding boxes from small to large to obtain the arrangement result, select the largest bounding box in the arrangement result, and then find the fusion with the largest bounding box that exceeds the second preset value other bounding boxes, use non-extreme suppression to delete these other bounding boxes that exceed the second preset value, and save the bounding box that is fused with the largest bounding box and exceeds the second preset value. Preferably, the second preset The setting value can be 0.5. Among the remaining bounding boxes, use the second-ranked bounding box as a comparison box, find and save other bounding boxes that are lower than the second preset value when fused with the second-ranked bounding box, and finally in the remaining bounding boxes , select a box with the largest score as the final detection box.
可选的,目标检测模型是通过训练方法进行训练得到的,训练方法为:Optionally, the target detection model is obtained by training through a training method, and the training method is:
获取待检测荔枝表皮缺陷图像,并对各个荔枝缺陷图像进行过采样和数据增广得到荔枝表皮缺陷数据集;Obtain the image of litchi skin defect to be detected, and perform oversampling and data augmentation on each litchi defect image to obtain the litchi skin defect data set;
对荔枝表皮缺陷数据集中的各个所述荔枝表皮缺陷图像进行标注后得到标注后的荔枝表皮缺陷数据集;Annotated litchi skin defect data set is obtained after marking each of the litchi skin defect images in the litchi skin defect data set;
调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对标注后的荔枝表皮缺陷图像进行检测,以使目标检测模型将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个标注后的荔枝表皮缺陷图像的网格得到各个网格中的边界框后,对边界框中的所述荔枝表皮缺陷进行识别打分得到边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框;Call the target detection model built by adding the improved attention mechanism SimAM network to the backbone feature extraction network to detect the marked litchi skin defect image, so that after the target detection model adjusts the litchi skin defect image to the same resolution, After meshing the litchi skin defect image, traversing the grids of each marked litchi skin defect image to obtain the bounding box in each grid, identifying and scoring the litchi skin defect in the bounding box to obtain the bounding box Confidence score, according to the confidence score of the bounding box, the bounding box larger than the preset requirement is screened out as the final detection box;
采用损失函数计算最终检测框和预期结果的误差对目标检测模型进行评估后更新模型参数,选取荔枝表皮缺陷数据集中未检测过的所述荔枝表皮缺陷图像进行检测直到达到预设训练次数得到目标检测模型。Use the loss function to calculate the error between the final detection frame and the expected result. Evaluate the target detection model and update the model parameters. Select the undetected litchi skin defect image in the litchi skin defect data set for detection until the preset training times are reached to obtain the target detection. Model.
可选的,对荔枝表皮缺陷数据集中的各个荔枝表皮缺陷图像进行标注后得到标注后的荔枝表皮缺陷数据集,具体为:Optionally, after labeling each litchi skin defect image in the litchi skin defect data set, an annotated litchi skin defect data set is obtained, specifically:
对荔枝表皮缺陷图像中的荔枝表皮缺陷使用矩形框将图像中的荔枝缺陷区域标注出来得到多个边界框;Use a rectangular frame to mark out the litchi defect area in the image to obtain multiple bounding boxes for the litchi skin defect in the litchi skin defect image;
根据边界框设置对应的标签类型,其中,标签类型包括黑点掉落和裂纹。Set the corresponding label type according to the bounding box, where the label type includes black dot drop and crack.
在本实施例中,利用荔枝表皮缺陷图像对目标检测模型进行训练,如图3所示,收集荔枝表皮缺陷图像,制作荔枝表皮缺陷数据集,由于部分缺陷类别图像数量较少,导致样本分布不均匀,进而导致训练效果较差。为了防止模型过拟合,需要对图片进行过采样和数据增广,使得荔枝缺陷样本保持平衡。过采样就是将类别较少的样本进行复制,数据增广的具体措施如下:In this embodiment, the target detection model is trained using litchi skin defect images. As shown in Figure 3, the litchi skin defect images are collected to create a litchi skin defect data set. Due to the small number of partial defect category images, the distribution of samples is uneven. Uniformity, which leads to poor training effect. In order to prevent the model from overfitting, it is necessary to oversample the image and augment the data to keep the litchi defect samples in balance. Oversampling is to copy samples with fewer categories. The specific measures for data augmentation are as follows:
(1)随机旋转:将图片按照中点随机旋转。(1) Random rotation: Randomly rotate the image according to the midpoint.
(2)图像亮度变换:将原始图像的亮度在预设亮度值之间变换。(2) Image brightness transformation: transform the brightness of the original image between preset brightness values.
作为本实施例的一种举例,旋转角度可定为(-20°,20°),预设亮度值可定为0.5~1.5。As an example of this embodiment, the rotation angle may be set as (-20°, 20°), and the preset brightness value may be set as 0.5˜1.5.
对每一张采集的荔枝表皮缺陷图像进行标注,生成保存标注结果的TXT文件。使用LabelImg标注工具对荔枝表皮缺陷进行分类标注,使用矩形框将图像中的荔枝果实区域标注出来,获得真实框,并设置对应的标签,标签类型包括dark spot、fall off和crack,以区分不同缺陷类别的荔枝,一张荔枝表皮缺陷图像中包含多个缺陷,则标注出对应数量的边界框。Annotate each collected litchi skin defect image, and generate a TXT file to save the annotation results. Use the LabelImg labeling tool to classify and label litchi skin defects, use a rectangular frame to mark the litchi fruit area in the image, obtain the real frame, and set the corresponding label. The label types include dark spot, fall off and crack to distinguish different defects category of lychee, if a lychee skin defect image contains multiple defects, the corresponding number of bounding boxes are marked.
调用搭建荔枝表皮缺陷检测模型依次对不同缺陷类别的荔枝缺陷图像进行检测,首先把检测荔枝表皮缺陷图像整理成相同分辨率,然后对荔枝表皮缺陷图片进行划网格,遍历网格找出每个荔枝表皮缺陷区域所对应的标签,每个网格单元负责检测一个荔枝表皮缺陷区域,网格单元根据系统设定采用边界框将缺陷区域标出来,然后对边界框的记性可信度进行评分,可信度计算包括识别的得分和边界框所覆盖的IOU的乘积,将产生的边界框和分类信息存在矩阵里。Call and build the litchi skin defect detection model to detect litchi defect images of different defect categories in sequence. First, organize the detected litchi skin defect images into the same resolution, and then draw a grid on the litchi skin defect image, and traverse the grid to find each The label corresponding to the defect area of litchi skin. Each grid unit is responsible for detecting a defect area of litchi skin. The grid unit uses the bounding box to mark the defect area according to the system settings, and then scores the memory reliability of the bounding box. The credibility calculation includes the product of the recognition score and the IOU covered by the bounding box, and the generated bounding box and classification information are stored in the matrix.
然后进行损失计算,损失主要包括三个部分,第一个是对边界框位置的误差进行计算,在计算边界框位置时选择可信度分数最高的边界框进行计算。第二个就是IOU误差,IOU误差选择每个待检测荔枝表皮缺陷图像的最高得分边界框框和剩下的边界框。Then perform loss calculation. The loss mainly includes three parts. The first is to calculate the error of the bounding box position. When calculating the bounding box position, select the bounding box with the highest reliability score for calculation. The second is the IOU error, which selects the highest scoring bounding box and the remaining bounding boxes for each litchi skin defect image to be detected.
在计算得到每个边界框的记性可信度分数后,把低于预设值的边界框删除,优选地,预设值可定位0.2。之后根据边界框的记性可信度分数对剩余的边界框做一个从小到大的排序后得到排列结果,选取排列结果中最大的边界框,然后查找与最大的边界框融合超过第二预设值的其它边界框,采用非极大致抑制将这些超过第二预设值的其它边界框删除,把与最大的边界框融合超过低于第二预设值的边界框保存,优选地,第二预设值可选0.5。在剩下的边界框中,将排名第二的边界框作为对比框,查找与排名第二的边界框融合低于第二预设值的其它边界框并保存,最后在剩下的边界框中,选取一个最大得分的框作为最终检测框。After the memory reliability score of each bounding box is calculated, the bounding boxes lower than the preset value are deleted. Preferably, the preset value can be set at 0.2. Afterwards, according to the memory reliability score of the bounding box, sort the remaining bounding boxes from small to large to obtain the arrangement result, select the largest bounding box in the arrangement result, and then find the fusion with the largest bounding box that exceeds the second preset value other bounding boxes, use non-extreme suppression to delete these other bounding boxes that exceed the second preset value, and save the bounding box that is fused with the largest bounding box and exceeds the second preset value. Preferably, the second preset The setting value can be 0.5. Among the remaining bounding boxes, use the second-ranked bounding box as a comparison box, find and save other bounding boxes that are lower than the second preset value when fused with the second-ranked bounding box, and finally in the remaining bounding boxes , select a box with the largest score as the final detection box.
最后采用损失函数计算最终检测框和预期结果的误差对目标检测模型进行评估后更新模型参数,选取荔枝表皮缺陷数据集中未检测过的荔枝表皮缺陷图像进行检测直到达到预设训练次数得到目标检测模型。Finally, the loss function is used to calculate the error between the final detection frame and the expected result. After evaluating the target detection model, the model parameters are updated, and the undetected litchi skin defect images in the litchi skin defect data set are selected for detection until the preset training times are reached to obtain the target detection model. .
获取待检测荔枝表皮缺陷图像后,调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对荔枝表皮缺陷图像进行检测,目标检测模型先将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个荔枝表皮缺陷图像的网格得到各个网格中的多个边界框,对各个边界框中的所述荔枝表皮缺陷进行识别打分得到各个边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,根据最终检测框输出荔枝表皮缺陷图像上的缺陷位置。通过采用改进后的算法构建检测模型对荔枝缺陷进行识别分类,提出荔枝的表皮缺陷,提高了模型检测准确率。After obtaining the litchi skin defect image to be detected, call the target detection model built by adding the improved attention mechanism SimAM network to the backbone feature extraction network to detect the litchi skin defect image. The target detection model first adjusts the litchi skin defect image to After the same resolution, after meshing the litchi skin defect image, traverse the grids of each litchi skin defect image to obtain multiple bounding boxes in each grid, and identify and score the litchi skin defects in each bounding box The confidence scores of each bounding box are obtained, and the bounding boxes larger than the preset requirements are selected according to the confidence scores of the bounding boxes as the final detection frame, and the defect position on the litchi skin defect image is output according to the final detection frame. By using the improved algorithm to build a detection model to identify and classify litchi defects, the skin defects of litchi were proposed, which improved the accuracy of model detection.
实施例二Embodiment two
相应地,参见图3,图3是本发明提供的一种荔枝表皮缺陷识别系统结构示意图。如图所示,该荔枝表皮缺陷识别系统,包括:样本获取模块401、标注模块402和检测模块403;Correspondingly, refer to FIG. 3 , which is a schematic structural diagram of a litchi skin defect recognition system provided by the present invention. As shown in the figure, the litchi skin defect recognition system includes: a
其中,样本获取模块401用于获取待检测荔枝表皮缺陷图像;Wherein, the
标注模块402用于对待检测荔枝表皮缺陷图像进行标注后得到标注后的荔枝表皮缺陷图像,其中,标注后的荔枝表皮缺陷图像中包括多个真实框;The marking
检测模块403用于调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对标注后的荔枝表皮缺陷图像进行检测,以使目标检测模型将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个标注后的荔枝表皮缺陷图像的网格得到各个网格中的多个边界框,对各个边界框中的所述荔枝表皮缺陷进行识别打分得到各个边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,根据所述最终检测框输出荔枝表皮缺陷检测结果,其中,荔枝表皮缺陷检测结果包括荔枝表皮缺陷图像上的缺陷位置。The
作为优选方案,检测模块403包括可信度分数计算单元4031、边界框排列单元4032、第一筛选单元4033和第二筛选单元4034,As a preferred solution, the
可信度分数计算单元4031用于对边界框中的所述荔枝表皮缺陷进行识别打分得到边界框的可信度分数;The credibility
边界框排列单元4032用于将低于第一预设分数的边界框删除后,对剩余的边界框根据可信度分数按照从大到小排列得到边界框排列结果;The bounding
第一筛选单元4033用于筛选出与在边界框排列结果中排名第一的边界框融合后低于预设误差的边界框得到第一边界框检测集,其中,第一边界框检测集的边界框根据所述可信度分数按照从大到小排列;The
第二筛选单元4034用于筛选出在第一边界框检测集中与在排名第二的边界框融合后低于预设误差的边界框后得到第二边界框检测集,并从第二边界框检测集筛选出排名第一的边界框作为最终检测框。The second screening unit 4034 is used to filter out the bounding boxes that are lower than the preset error after the fusion of the first bounding box detection set and the second-ranked bounding box to obtain the second bounding box detection set, and detect from the second bounding box Set to filter out the top bounding box as the final detection box.
作为优选方案,本发明提供的一种终端设备,包括:存储器,处理器及存储在存储器上并可在处理器上运行的计算机程序,处理器执行程序时实现如本发明实施例一所示的荔枝表皮缺陷识别方法。As a preferred solution, a terminal device provided by the present invention includes: a memory, a processor, and a computer program stored on the memory and operable on the processor. When the processor executes the program, it implements the Litchi epidermis defect identification method.
作为优选方案,本发明提供的一种计算机可读存储介质,计算机可读存储介质存储有计算机可执行程序,计算机可执行程序用于使计算机执行如本发明实施例一所示的荔枝表皮缺陷识别方法的步骤。As a preferred solution, the present invention provides a computer-readable storage medium, the computer-readable storage medium stores a computer-executable program, and the computer-executable program is used to enable the computer to perform the identification of litchi skin defects as shown in
相比于现有技术,本发明获取待检测荔枝表皮缺陷图像后,调用通过在主干特征提取网络中加入改进后的注意力机制SimAM网络搭建的目标检测模型对荔枝表皮缺陷图像进行检测,目标检测模型先将荔枝表皮缺陷图像调整为相同分辨率后,对荔枝表皮缺陷图像进行网格划分后,遍历各个标注后的荔枝表皮缺陷图像的网格得到各个网格中的多个边界框,对各个边界框中的荔枝表皮缺陷进行识别打分得到各个边界框的可信度分数,根据边界框的可信度分数筛选出大于预设要求的边界框作为最终检测框,根据最终检测框输出荔枝表皮缺陷图像上的缺陷位置,通过采用改进后的算法构建检测模型对荔枝缺陷进行识别分类,提出荔枝的表皮缺陷,可以提高模型检测准确率。Compared with the prior art, after the present invention obtains the defect image of the litchi skin to be detected, it calls the target detection model built by adding the improved attention mechanism SimAM network in the backbone feature extraction network to detect the defect image of the litchi skin, and the target detection The model first adjusts the litchi skin defect image to the same resolution, and then performs grid division on the litchi skin defect image, and traverses the grids of each marked litchi skin defect image to obtain multiple bounding boxes in each grid. The litchi skin defects in the bounding box are identified and scored to obtain the credibility scores of each bounding box, and the bounding boxes larger than the preset requirements are selected according to the credibility scores of the bounding boxes as the final detection frame, and the litchi skin defects are output according to the final detection frame The position of the defect on the image, by using the improved algorithm to build a detection model to identify and classify litchi defects, and propose the skin defects of litchi, which can improve the accuracy of model detection.
以上所述的具体实施例,对本发明的目的、技术方案和有益效果进行了进一步的详细说明,应当理解,以上所述仅为本发明的具体实施例而已,并不用于限定本发明的保护范围。特别指出,对于本领域技术人员来说,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The specific embodiments described above have further described the purpose, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above descriptions are only specific embodiments of the present invention and are not intended to limit the protection scope of the present invention. . In particular, for those skilled in the art, any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211607412.2A CN116168388A (en) | 2022-12-14 | 2022-12-14 | Litchi epidermis defect identification method and system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211607412.2A CN116168388A (en) | 2022-12-14 | 2022-12-14 | Litchi epidermis defect identification method and system |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116168388A true CN116168388A (en) | 2023-05-26 |
Family
ID=86415450
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211607412.2A Withdrawn CN116168388A (en) | 2022-12-14 | 2022-12-14 | Litchi epidermis defect identification method and system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116168388A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118781439A (en) * | 2024-09-11 | 2024-10-15 | 广东省人民医院 | A capsule endoscopy lesion recognition method and system based on artificial intelligence |
-
2022
- 2022-12-14 CN CN202211607412.2A patent/CN116168388A/en not_active Withdrawn
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118781439A (en) * | 2024-09-11 | 2024-10-15 | 广东省人民医院 | A capsule endoscopy lesion recognition method and system based on artificial intelligence |
CN118781439B (en) * | 2024-09-11 | 2024-11-22 | 广东省人民医院 | Capsule endoscope lesion recognition method and system based on artificial intelligence |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108562589B (en) | Method for detecting surface defects of magnetic circuit material | |
CN110543837B (en) | Visible light airport airplane detection method based on potential target point | |
CN106960195B (en) | Crowd counting method and device based on deep learning | |
CN111582294B (en) | Method for constructing convolutional neural network model for surface defect detection and application thereof | |
CN113592845A (en) | Defect detection method and device for battery coating and storage medium | |
JP2024509411A (en) | Defect detection method, device and system | |
CN111951249A (en) | Visual detection method of mobile phone light guide plate defects based on multi-task learning network | |
CN111310826B (en) | Method and device for detecting labeling abnormality of sample set and electronic equipment | |
CN111242899B (en) | Image-based flaw detection method and computer-readable storage medium | |
CN115131283B (en) | Defect detection and model training method, device, equipment and medium for target object | |
CN112580748B (en) | Method for counting classified cells of stain image | |
CN116245882A (en) | Circuit board electronic element detection method and device and computer equipment | |
CN110766017A (en) | Mobile terminal character recognition method and system based on deep learning | |
CN111951218A (en) | Lipstick quality inspection system of mixed deep learning model | |
CN113095445B (en) | Target identification method and device | |
CN117368226A (en) | Method and system for detecting label printing defects based on machine vision | |
CN111932639B (en) | Detection method of unbalanced defect sample based on convolutional neural network | |
CN116168388A (en) | Litchi epidermis defect identification method and system | |
CN117314826A (en) | Performance detection method of display screen | |
CN115457026A (en) | Paper defect detection method based on improved YOLOv5 | |
KR20230052169A (en) | Apparatus and method for generating image annotation based on shap | |
CN118941553A (en) | A Yarn Detection System Based on Image Processing | |
CN112730437A (en) | Spinneret plate surface defect detection method and device based on depth separable convolutional neural network, storage medium and equipment | |
CN116523916B (en) | Product surface defect detection method and device, electronic equipment and storage medium | |
CN113052234A (en) | Jade classification method based on image features and deep learning technology |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
WW01 | Invention patent application withdrawn after publication |
Application publication date: 20230526 |
|
WW01 | Invention patent application withdrawn after publication |