TWI762193B - Image defect detection method, image defect detection device, electronic device and storage media - Google Patents

Image defect detection method, image defect detection device, electronic device and storage media Download PDF

Info

Publication number
TWI762193B
TWI762193B TW110105182A TW110105182A TWI762193B TW I762193 B TWI762193 B TW I762193B TW 110105182 A TW110105182 A TW 110105182A TW 110105182 A TW110105182 A TW 110105182A TW I762193 B TWI762193 B TW I762193B
Authority
TW
Taiwan
Prior art keywords
image
probability distribution
latent feature
error
encoder
Prior art date
Application number
TW110105182A
Other languages
Chinese (zh)
Other versions
TW202232382A (en
Inventor
簡士超
郭錦斌
蔡東佐
Original Assignee
鴻海精密工業股份有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 鴻海精密工業股份有限公司 filed Critical 鴻海精密工業股份有限公司
Priority to TW110105182A priority Critical patent/TWI762193B/en
Application granted granted Critical
Publication of TWI762193B publication Critical patent/TWI762193B/en
Publication of TW202232382A publication Critical patent/TW202232382A/en

Links

Images

Landscapes

  • Image Analysis (AREA)

Abstract

The present application provides an image defect detection method, an image defect detection device, an electronic device and storage medium. The method includes: entering flawless sample training image into a self-encoder, calculating a first submersion feature through encoding layers of the self-encoder, entering the first submersion feature into decoding layers of the self-encoder to obtain first reconstruction images, and calculating first reconstruction error using an error function, entering the first subliminal feature into a deep learning model and a Gauss hybrid model to obtain a first probability distribution and a second probability distribution, calculating a dispersion between the first probability distribution and the second probability distribution, and calculating a total loss according to the first reconstruction error and the dispersion, setting a threshold based on the total loss, obtaining a testing sample image and calculating a total error to determine whether the testing sample image is a defective image.

Description

圖像瑕疵檢測方法、裝置、電子設備及存儲介質 Image defect detection method, device, electronic device and storage medium

本發明涉及圖像檢測領域,提供瑕疵檢測和電腦視覺技術領域,具體涉及一種圖像瑕疵檢測方法、裝置、電子設備及存儲介質。 The invention relates to the field of image detection, provides the technical field of defect detection and computer vision, and in particular relates to an image defect detection method, device, electronic equipment and storage medium.

為了提高工業產品的品質,在對工業產品進行打包前,通常會對工業產品進行一定的瑕疵檢測。由於目前的基於高斯混合模型的瑕疵檢測方法通常有龐大的計算量,使得程式速度無法優化,執行時間無法減少。 In order to improve the quality of industrial products, certain defects are usually detected on industrial products before they are packaged. Because the current flaw detection method based on Gaussian mixture model usually has a huge amount of calculation, the program speed cannot be optimized, and the execution time cannot be reduced.

鑒於以上內容,有必要提出一種圖像瑕疵檢測方法、裝置、電子設備及存儲介質以提升瑕疵圖像檢測效率。 In view of the above content, it is necessary to propose an image defect detection method, device, electronic device and storage medium to improve the efficiency of defect image detection.

本申請的第一方面提供一種圖像瑕疵檢測方法,包括:獲取無瑕疵樣本訓練圖像;將所述無瑕疵樣本訓練圖像輸入自編碼器,藉由所述自編碼器的編碼層計算得到所述無瑕疵樣本訓練圖像的第一潛特徵;將所述第一潛特徵輸入所述自編碼器的解碼層並計算得到所述無瑕疵樣本訓練圖像的第一重構圖像,並使用預設的誤差函數計算所述無瑕疵樣本訓練 圖像和所述第一重構圖像得到所述無瑕疵樣本訓練圖像和所述第一重構圖像之間的第一重構誤差;將所述第一潛特徵輸入深度學習模型並計算得到所述第一潛特徵的第一概率分佈;將所述第一潛特徵輸入高斯混合模型並計算得到所述第一潛特徵的第二概率分佈;計算所述第一概率分佈和所述第二概率分佈之間的庫爾貝克-萊布勒散度;根據所述第一重構誤差和所述庫爾貝克-萊布勒散度得到總損失,根據所述總損失優化所述自編碼器、所述深度學習模型及所述高斯混合模型,並根據所述總損失設定閾值;獲取測試樣本圖像,將所述測試樣本圖像輸入所述自編碼器,藉由所述自編碼器的編碼層計算得到所述測試樣本圖像的第二潛特徵,將所述第二潛特徵輸入所述自編碼器的解碼層並計算得到所述測試樣本圖像的第二重構圖像,並使用所述預設的誤差函數計算所述測試樣本圖像和所述第二重構圖像之間的第二重構誤差,將所述第二潛特徵輸入訓練完成的深度學習模型並計算得到所述第二潛特徵的第三概率分佈,根據所述第三概率分佈和所述第二重構誤差計算總誤差;當所述總誤差大於或等於所述閾值時,確定所述測試樣本圖像為瑕疵圖像,當所述總誤差小於所述閾值時,確定所述測試樣本圖像為無瑕疵圖像。 A first aspect of the present application provides an image defect detection method, which includes: acquiring a training image of a flawless sample; inputting the training image of a flawless sample into an autoencoder, and obtaining it by calculating the coding layer of the autoencoder The first latent feature of the flawless sample training image; inputting the first latent feature into the decoding layer of the self-encoder and calculating the first reconstructed image of the flawless sample training image, and Compute the flawless sample training using a preset error function image and the first reconstructed image to obtain the first reconstruction error between the flawless sample training image and the first reconstructed image; input the first latent feature into the deep learning model and generate a Calculate the first probability distribution of the first latent feature; input the first latent feature into a Gaussian mixture model and calculate the second probability distribution of the first latent feature; calculate the first probability distribution and the the Kulbeck-Leibler divergence between the second probability distributions; a total loss is obtained from the first reconstruction error and the Kulbec-Leibler divergence, and the self-optimization is based on the total loss encoder, the deep learning model and the Gaussian mixture model, and set a threshold according to the total loss; obtain a test sample image, input the test sample image into the autoencoder, and use the autoencoder The coding layer of the encoder obtains the second latent feature of the test sample image, and the second latent feature is input into the decoding layer of the self-encoder to calculate the second reconstructed image of the test sample image. , and use the preset error function to calculate the second reconstruction error between the test sample image and the second reconstructed image, input the second latent feature into the trained deep learning model and Calculate a third probability distribution of the second latent feature, and calculate a total error according to the third probability distribution and the second reconstruction error; when the total error is greater than or equal to the threshold, determine the test The sample image is a flawed image, and when the total error is less than the threshold, it is determined that the test sample image is a flawless image.

優選地,所述藉由所述自編碼器的編碼層計算得到所述無瑕疵樣本訓練圖像的第一潛特徵包括:將所述無瑕疵樣本訓練圖像進行向量化處理,得到所述無瑕疵樣本訓練圖像的特徵向量; 利用所述自編碼器中的所述編碼層對所述無瑕疵樣本訓練圖像的所述特徵向量進行運算,得到所述第一潛特徵。 Preferably, calculating the first latent feature of the flawless sample training image by the coding layer of the self-encoder includes: performing vectorization processing on the flawless sample training image to obtain the flawless sample training image. The feature vector of the flawed sample training image; The first latent feature is obtained by operating on the feature vector of the flawless sample training image by using the encoding layer in the autoencoder.

優選地,所述將所述第一潛特徵輸入所述自編碼器的解碼層並計算得到所述無瑕疵樣本訓練圖像的第一重構圖像包括:利用所述自編碼器中的所述解碼層對所述第一潛特徵進行運算;對運算後得到的向量進行還原處理,得到所述第一重建圖像。 Preferably, the inputting the first latent feature into the decoding layer of the self-encoder and calculating the first reconstructed image of the flawless sample training image comprises: using all the data in the self-encoder The decoding layer operates on the first latent feature; and performs restoration processing on the vector obtained after the operation to obtain the first reconstructed image.

優選地,所述將所述第一潛特徵輸入深度學習模型並計算得到所述第一潛特徵的第一概率分佈包括:將所述第一潛特徵輸入所述深度學習模型;藉由所述深度學習模型中卷積層、池化層和至少一個隱藏層中的一個或多個對所述第一潛特徵進行運算,得到所述第一概率分佈。 Preferably, the inputting the first latent feature into a deep learning model and calculating the first probability distribution of the first latent feature comprises: inputting the first latent feature into the deep learning model; One or more of a convolution layer, a pooling layer, and at least one hidden layer in the deep learning model operate on the first latent feature to obtain the first probability distribution.

優選地,所述計算所述第一概率分佈和所述第二概率分佈之間的庫爾貝克-萊布勒散度包括: 根據公式

Figure 110105182-A0305-02-0005-22
計算所述第一概率分佈和所述第二概率分佈的庫爾貝克-萊布勒散度,其中,D KL (P||Q)為所述第一概率分佈和所述第二概率分佈的庫爾貝克-萊布勒散度,P(i)為所述第二概率分佈,Q(i)為所述第一概率分佈。 Preferably, the calculating the Kulbec-Leibler divergence between the first probability distribution and the second probability distribution comprises: according to the formula
Figure 110105182-A0305-02-0005-22
Calculate the Kulbec-Leibler divergence of the first probability distribution and the second probability distribution, wherein D KL ( P || Q ) is the difference between the first probability distribution and the second probability distribution Kulbec-Leibler divergence, P ( i ) is the second probability distribution, and Q ( i ) is the first probability distribution.

優選地,所述根據所述第一重構誤差和所述庫爾貝克-萊布勒散度得到總損失,根據所述總損失優化所述自編碼器、所述深度學習模型及所述高斯混合模型包括:計算所述第一重構誤差與所述庫爾貝克-萊布勒散度的乘積,得到所述總損失;調整所述自編碼器、所述深度學習模型及所述高斯混合模型的參數對所述總損失進行最小化處理。 Preferably, the total loss is obtained according to the first reconstruction error and the Kulbec-Leibler divergence, and the autoencoder, the deep learning model and the Gaussian are optimized according to the total loss The mixture model includes: calculating the product of the first reconstruction error and the Kulbeck-Leibler divergence to obtain the total loss; adjusting the autoencoder, the deep learning model and the Gaussian mixture The parameters of the model minimize the total loss.

優選地,所述根據所述第三概率分佈和所述第二重構誤差計算總誤差包括:對所述第三概率分佈和所述第二重構誤差求和得到總誤差。 Preferably, the calculating a total error according to the third probability distribution and the second reconstruction error includes: summing the third probability distribution and the second reconstruction error to obtain a total error.

本申請的第二方面提供一種圖像瑕疵檢測裝置,所述裝置包括:訓練圖像獲取模組,用於獲取無瑕疵樣本訓練圖像;第一潛特徵獲取模組,用於將所述無瑕疵樣本訓練圖像輸入自編碼器,藉由所述自編碼器的編碼層計算得到所述無瑕疵樣本訓練圖像的第一潛特徵;第一重構誤差獲取模組,用於將所述第一潛特徵輸入所述自編碼器的解碼層並計算得到所述無瑕疵樣本訓練圖像的第一重構圖像,並使用預設的誤差函數計算所述無瑕疵樣本訓練圖像和所述第一重構圖像得到所述無瑕疵樣本訓練圖像和所述第一重構圖像之間的第一重構誤差;第一概率分佈計算模組,用於將所述第一潛特徵輸入深度學習模型並計算得到所述第一潛特徵的第一概率分佈;第二概率分佈計算模組,用於將所述第一潛特徵輸入高斯混合模型並計算得到所述第一潛特徵的第二概率分佈;散度計算模組,用於計算所述第一概率分佈和所述第二概率分佈之間的庫爾貝克-萊布勒散度;模型訓練模組,用於根據所述第一重構誤差和所述庫爾貝克-萊布勒散度得到總損失,根據所述總損失優化所述自編碼器、所述深度學習模型及所述高斯混合模型,並根據所述總損失設定閾值;總誤差計算模組,用於獲取測試樣本圖像,將所述測試樣本圖像輸入所述自編碼器,藉由所述自編碼器的編碼層計算得到所述測試樣本圖像的第二潛特徵,將所述第二潛特徵輸入所述自編碼器的解碼層並計算得到所述測試樣本圖像的第二重構圖像,並使用所述預設的誤差函數計算所述測試樣本圖像和所述 第二重構圖像之間的第二重構誤差,將所述第二潛特徵輸入訓練完成的深度學習模型並計算得到所述第二潛特徵的第三概率分佈,根據所述第三概率分佈和所述第二重構誤差計算總誤差;判斷模組,用於當所述總誤差大於或等於所述閾值時,確定所述測試樣本圖像為瑕疵圖像,當所述總誤差小於所述閾值時,確定所述測試樣本圖像為無瑕疵圖像。 A second aspect of the present application provides an image defect detection device, the device includes: a training image acquisition module for acquiring flawless sample training images; a first latent feature acquisition module for The flawed sample training image is input into the self-encoder, and the first latent feature of the flawless sample training image is calculated by the coding layer of the self-encoder; the first reconstruction error acquisition module is used to The first latent feature is input into the decoding layer of the self-encoder and the first reconstructed image of the flawless sample training image is obtained by calculation, and a preset error function is used to calculate the flawless sample training image and all samples. The first reconstructed image obtains the first reconstruction error between the flawless sample training image and the first reconstructed image; the first probability distribution calculation module is used to calculate the first latent image. The feature is input into the deep learning model and the first probability distribution of the first latent feature is obtained by calculation; the second probability distribution calculation module is used to input the first latent feature into the Gaussian mixture model and calculate the first latent feature. The second probability distribution of A total loss is obtained from the first reconstruction error and the Kulbec-Leibler divergence, and the autoencoder, the deep learning model and the Gaussian mixture model are optimized according to the total loss, and according to the The total loss is set as a threshold; the total error calculation module is used to obtain the test sample image, input the test sample image into the self-encoder, and calculate the test sample image by the coding layer of the self-encoder The second latent feature of the image, input the second latent feature into the decoding layer of the self-encoder and calculate the second reconstructed image of the test sample image, and use the preset error function to calculate The test sample image and the For the second reconstruction error between the second reconstructed images, the second latent feature is input into the trained deep learning model and the third probability distribution of the second latent feature is calculated to obtain, according to the third probability distribution and the second reconstruction error to calculate a total error; a judgment module, configured to determine that the test sample image is a defective image when the total error is greater than or equal to the threshold, and when the total error is less than or equal to the threshold When the threshold value is set, it is determined that the test sample image is a flawless image.

本申請的第三方面提供一種電子設備,所述電子設備包括:記憶體,存儲至少一個指令;及處理器,執行所述記憶體中存儲的指令以實現所述瑕疵檢測方法。 A third aspect of the present application provides an electronic device, the electronic device comprising: a memory storing at least one instruction; and a processor executing the instruction stored in the memory to implement the defect detection method.

本申請的第四方面提供一種電腦存儲介質,其上存儲有電腦程式,所述電腦程式被處理器執行時實現所述的圖像瑕疵檢測方法。 A fourth aspect of the present application provides a computer storage medium on which a computer program is stored, and when the computer program is executed by a processor, the image defect detection method is implemented.

本發明中,藉由同時訓練自編碼器、深度學習模型和高斯混合模型,使得深度學習模型和高斯混合模型可以輸出相同的概率分佈預測,從而可以使用深度學習模型替代高斯混合模型,在進行瑕疵檢測時實現更高的效率。 In the present invention, by training the autoencoder, the deep learning model and the Gaussian mixture model at the same time, the deep learning model and the Gaussian mixture model can output the same probability distribution prediction, so that the deep learning model can be used to replace the Gaussian mixture model. Achieve greater efficiency in detection.

30:圖像瑕疵檢測裝置 30: Image defect detection device

301:訓練圖像獲取模組 301: Train image acquisition module

302:第一潛特徵獲取模組 302: The first latent feature acquisition module

303:第一重構誤差獲取模組 303: The first reconstruction error acquisition module

304:第一概率分佈計算模組 304: The first probability distribution calculation module

305:第二概率分佈計算模組 305: Second probability distribution calculation module

306:散度計算模組 306: Divergence calculation module

307:模型訓練模組 307: Model training module

308:總誤差計算模組 308: Total error calculation module

309:判斷模組 309: Judgment Module

6:電子設備 6: Electronic equipment

61:記憶體 61: Memory

62:處理器 62: Processor

63:電腦程式 63: Computer Programs

S11~S19:步驟 S11~S19: Steps

圖1為本發明一實施方式中圖像瑕疵檢測方法的流程圖。 FIG. 1 is a flowchart of an image defect detection method according to an embodiment of the present invention.

圖2為本發明一實施方式中圖像瑕疵檢測裝置的結構圖。 FIG. 2 is a structural diagram of an image defect detection apparatus according to an embodiment of the present invention.

圖3為本發明一實施方式中電子設備的示意圖。 FIG. 3 is a schematic diagram of an electronic device in an embodiment of the present invention.

為了能夠更清楚地理解本發明的上述目的、特徵和優點,下面結合附圖和具體實施例對本發明進行詳細描述。需要說明的是,在不衝突的情況下,本申請的實施例及實施例中的特徵可以相互組合。 In order to more clearly understand the above objects, features and advantages of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that the embodiments of the present application and the features in the embodiments may be combined with each other in the case of no conflict.

在下面的描述中闡述了很多具體細節以便於充分理解本發明,所描述的實施例僅僅是本發明一部分實施例,而不是全部的實施例。基於本發明中的實施例,本領域普通技術人員在沒有做出創造性勞動前提下所獲得的所有其他實施例,都屬於本發明保護的範圍。 In the following description, many specific details are set forth in order to facilitate a full understanding of the present invention, and the described embodiments are only some, but not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

除非另有定義,本文所使用的所有的技術和科學術語與屬於本發明的技術領域的技術人員通常理解的含義相同。本文中在本發明的說明書中所使用的術語只是為了描述具體地實施例的目的,不是旨在於限制本發明。 Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terms used herein in the description of the present invention are for the purpose of describing specific embodiments only, and are not intended to limit the present invention.

優選地,本發明圖像瑕疵檢測方法應用在一個或者多個電子設備中。所述電子設備是一種能夠按照事先設定或存儲的指令,自動進行數值計算和/或資訊處理的設備,其硬體包括但不限於微處理器、專用積體電路(Application Specific Integrated Circuit,ASIC)、可程式設計閘陣列(Field-Programmable Gate Array,FPGA)、數位訊號處理器(Digital Signal Processor,DSP)、嵌入式設備等。 Preferably, the image defect detection method of the present invention is applied in one or more electronic devices. The electronic device is a device that can automatically perform numerical calculations and/or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (ASICs) , Programmable Gate Array (Field-Programmable Gate Array, FPGA), Digital Signal Processor (Digital Signal Processor, DSP), embedded devices, etc.

所述電子設備可以是桌上型電腦、筆記型電腦、平板電腦及雲端伺服器等計算設備。所述電子設備可以與使用者藉由鍵盤、滑鼠、遙控器、觸控板或聲控設備等方式進行人機交互。 The electronic device may be a computing device such as a desktop computer, a notebook computer, a tablet computer, and a cloud server. The electronic device can perform human-computer interaction with the user by means of a keyboard, a mouse, a remote control, a touch pad or a voice control device.

實施例1 Example 1

圖1是本發明一實施方式中圖像瑕疵檢測方法的流程圖。所述圖像瑕疵檢測方法應用於電子設備中。根據不同的需求,所述流程圖中步驟的順序可以改變,某些步驟可以省略。 FIG. 1 is a flowchart of an image defect detection method in an embodiment of the present invention. The image defect detection method is applied in electronic equipment. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.

參閱圖1所示,所述圖像瑕疵檢測方法具體包括以下步驟。 Referring to FIG. 1 , the image defect detection method specifically includes the following steps.

步驟S11,獲取無瑕疵樣本訓練圖像。 In step S11, a training image of a flawless sample is obtained.

步驟S12,將所述無瑕疵樣本訓練圖像輸入自編碼器,藉由所述自編碼器的編碼層計算得到所述無瑕疵樣本訓練圖像的第一潛特徵。 Step S12: Input the flawless sample training image into an auto-encoder, and calculate the first latent feature of the flawless sample training image through the coding layer of the auto-encoder.

在本發明的至少一個實施例中,所述藉由所述自編碼器的編碼層計算得到所述無瑕疵樣本訓練圖像的第一潛特徵包括:將所述無瑕疵樣本訓練圖像進行向量化處理,得到所述無瑕疵樣本訓練圖像的特徵向量;利用所述自編碼器中的所述編碼層對所述無瑕疵樣本訓練圖像的所述特徵向量進行運算,得到所述第一潛特徵。 In at least one embodiment of the present invention, calculating the first latent feature of the flawless sample training image by the coding layer of the autoencoder includes: performing a vector to obtain the feature vector of the flawless sample training image; use the coding layer in the self-encoder to operate on the feature vector of the flawless sample training image to obtain the first latent features.

步驟S13,將所述第一潛特徵輸入所述自編碼器的解碼層並計算得到所述無瑕疵樣本訓練圖像的第一重構圖像,並使用預設的誤差函數計算所述無瑕疵樣本訓練圖像和所述第一重構圖像得到所述無瑕疵樣本訓練圖像和所述第一重構圖像之間的第一重構誤差。 Step S13, input the first latent feature into the decoding layer of the auto-encoder and calculate the first reconstructed image of the flawless sample training image, and use a preset error function to calculate the flawless The sample training image and the first reconstructed image obtain a first reconstruction error between the flawless sample training image and the first reconstructed image.

優選地,所述將所述第一潛特徵輸入所述自編碼器的解碼層並計算得到所述無瑕疵樣本訓練圖像的第一重構圖像包括:利用所述自編碼器中的所述解碼層對所述第一潛特徵進行運算;對運算後得到的向量進行還原處理,得到所述第一重建圖像。 Preferably, the inputting the first latent feature into the decoding layer of the self-encoder and calculating the first reconstructed image of the flawless sample training image comprises: using all the data in the self-encoder The decoding layer operates on the first latent feature; and performs restoration processing on the vector obtained after the operation to obtain the first reconstructed image.

步驟S14,將所述第一潛特徵輸入深度學習模型並計算得到所述第一潛特徵的第一概率分佈。 Step S14, inputting the first latent feature into a deep learning model and calculating a first probability distribution of the first latent feature.

在本發明的至少一個實施例中,所述將所述第一潛特徵輸入深度學習模型並計算得到所述第一潛特徵的第一概率分佈包括:將所述第一潛特徵輸入所述深度學習模型;藉由所述深度學習模型中卷積層、池化層和至少一個隱藏層中的一個或多個對所述第一潛特徵進行運算,得到所述第一概率分佈。 In at least one embodiment of the present invention, the inputting the first latent feature into a deep learning model and calculating the first probability distribution of the first latent feature includes: inputting the first latent feature into the depth learning model; the first probability distribution is obtained by operating on the first latent feature by one or more of a convolution layer, a pooling layer and at least one hidden layer in the deep learning model.

步驟S15,將所述第一潛特徵輸入高斯混合模型並計算得到所述第一潛特徵的第二概率分佈。 Step S15, the first latent feature is input into a Gaussian mixture model and a second probability distribution of the first latent feature is obtained by calculation.

在本發明的至少一個實施例中,將所述第一潛特徵輸入高斯混合模型並計算得到所述第一潛特徵的第二概率分佈包括: 將所述第一潛特徵輸入所述高斯混合模型; 藉由所述高斯混合模型擬合所述第一潛特徵的概率分佈,得到所述第二概率分佈。 In at least one embodiment of the present invention, inputting the first latent feature into a Gaussian mixture model and calculating a second probability distribution of the first latent feature includes: inputting the first latent feature into the Gaussian mixture model; The second probability distribution is obtained by fitting the probability distribution of the first latent feature by the Gaussian mixture model.

具體地,所述高斯混合模型為

Figure 110105182-A0305-02-0010-21
其中,x i 表示第一潛特徵對應的向量,t=1,2,3...,M,M為第一潛特徵的維度,α k 為第k個高斯分佈的權重,μ k ,σ k 分別時第k個高斯分佈的均值和方差,N(x i k k )表示向量x i 符合均值為μ k 且方差為σ k 的正態分佈,K至少為3。 Specifically, the Gaussian mixture model is
Figure 110105182-A0305-02-0010-21
Among them, x i represents the vector corresponding to the first latent feature, t=1, 2, 3..., M, M is the dimension of the first latent feature, α k is the weight of the kth Gaussian distribution, μ k , σ k is the mean and variance of the k-th Gaussian distribution, respectively, N ( x i k k ) means that the vector x i conforms to a normal distribution with mean μ k and variance σ k , and K is at least 3.

步驟S16,計算所述第一概率分佈和所述第二概率分佈之間的庫爾貝克-萊布勒散度。 Step S16: Calculate the Kulbeck-Leebler divergence between the first probability distribution and the second probability distribution.

優選地,所述計算所述第一概率分佈和所述第二概率分佈之間的庫爾貝克-萊布勒散度包括: 根據公式

Figure 110105182-A0305-02-0010-2
計算所述第一概率分佈和所述第二概率分佈的庫爾貝克-萊布勒散度,其中,D KL (P||Q)為所述第一概率分佈和所述第二概率分佈的庫爾貝克-萊布勒散度,P(i)為所述第二概率分佈,Q(i)為所述第一概率分佈。 Preferably, the calculating the Kulbec-Leibler divergence between the first probability distribution and the second probability distribution comprises: according to the formula
Figure 110105182-A0305-02-0010-2
Calculate the Kulbec-Leibler divergence of the first probability distribution and the second probability distribution, wherein D KL ( P || Q ) is the difference between the first probability distribution and the second probability distribution Kulbec-Leibler divergence, P ( i ) is the second probability distribution, and Q ( i ) is the first probability distribution.

步驟S17,根據所述第一重構誤差和所述庫爾貝克-萊布勒散度得到總損失,根據所述總損失優化所述自編碼器、所述深度學習模型及所述高斯混合模型,並根據所述總損失設定閾值。 Step S17: Obtain a total loss according to the first reconstruction error and the Kulbec-Leibler divergence, and optimize the autoencoder, the deep learning model and the Gaussian mixture model according to the total loss , and set a threshold based on the total loss.

在本發明的至少一個實施例中,所述根據所述第一重構誤差和所述庫爾貝克-萊布勒散度得到總損失,根據所述總損失優化所述自編碼器、所述深度學習模型及所述高斯混合模型包括: 計算所述第一重構誤差與所述庫爾貝克-萊布勒散度的乘積,得到所述總損失; 調整所述自編碼器、所述深度學習模型及所述高斯混合模型的參數對所述總損失進行最小化處理。 In at least one embodiment of the present invention, a total loss is obtained according to the first reconstruction error and the Kurbeck-Leebler divergence, and the self-encoder, the self-encoder are optimized according to the total loss The deep learning model and the Gaussian mixture model include: calculating the product of the first reconstruction error and the Kulbec-Leebler divergence to obtain the total loss; The total loss is minimized by adjusting parameters of the autoencoder, the deep learning model and the Gaussian mixture model.

在本發明的至少一個實施例中,調整所述自編碼器、所述深度學習模型及所述高斯混合模型的參數對所述總損失進行最小化處理的目的是優化所述自編碼器、所述深度學習模型及所述高斯混合模型,使得所述深度學習模型與所述高斯混合模型根據所述自編碼器生成的重構圖像具有相同的概率分佈。 In at least one embodiment of the present invention, the purpose of adjusting the parameters of the autoencoder, the deep learning model and the Gaussian mixture model to minimize the total loss is to optimize the autoencoder, the The deep learning model and the Gaussian mixture model are configured so that the deep learning model and the Gaussian mixture model have the same probability distribution according to the reconstructed image generated by the autoencoder.

步驟S18,獲取測試樣本圖像,將所述測試樣本圖像輸入所述自編碼器,藉由所述自編碼器的編碼層計算得到所述測試樣本圖像的第二潛特徵,將所述第二潛特徵輸入所述自編碼器的解碼層並計算得到所述測試樣本圖像的第二重構圖像,並使用所述預設的誤差函數計算所述測試樣本圖像和所述第二重構圖像之間的第二重構誤差,將所述第二潛特徵輸入訓練完成的深度學習模型並計算得到所述第二潛特徵的第三概率分佈,根據所述第三概率分佈和所述第二重構誤差計算總誤差。 In step S18, a test sample image is acquired, the test sample image is input into the self-encoder, the second latent feature of the test sample image is calculated by the coding layer of the self-encoder, and the second latent feature of the test sample image is obtained. The second latent feature is input to the decoding layer of the auto-encoder to obtain a second reconstructed image of the test sample image, and the preset error function is used to calculate the test sample image and the first reconstructed image of the test sample image. For the second reconstruction error between the two reconstructed images, the second latent feature is input into the trained deep learning model and the third probability distribution of the second latent feature is obtained by calculation. According to the third probability distribution and the second reconstruction error to calculate the total error.

在本發明的至少一個實施例中,所述根據所述第三概率分佈和所述第二重構誤差計算總誤差包括:對所述第三概率分佈和所述第二重構誤差求和得到總誤差。 In at least one embodiment of the present invention, the calculating a total error according to the third probability distribution and the second reconstruction error includes: summing the third probability distribution and the second reconstruction error to obtain total error.

步驟S19,當所述總誤差大於或等於所述閾值時,確定所述測試樣本圖像為瑕疵圖像,當所述總誤差小於所述閾值時,確定所述測試樣本圖像為無瑕疵圖像。 Step S19, when the total error is greater than or equal to the threshold, determine that the test sample image is a flawed image, and when the total error is less than the threshold, determine that the test sample image is a flawless image picture.

本發明中,藉由同時訓練自編碼器、深度學習模型和高斯混合模型,使得深度學習模型和高斯混合模型可以輸出相同的概率分佈預測,從而可以使用深度學習模型替代高斯混合模型,在進行瑕疵檢測時實現更高的效率。 In the present invention, by training the autoencoder, the deep learning model and the Gaussian mixture model at the same time, the deep learning model and the Gaussian mixture model can output the same probability distribution prediction, so that the deep learning model can be used to replace the Gaussian mixture model. Achieve greater efficiency in detection.

實施例2 Example 2

圖2為本發明一實施方式中圖像瑕疵檢測裝置30的結構圖。 FIG. 2 is a structural diagram of an image defect detection apparatus 30 in an embodiment of the present invention.

在一些實施例中,所述圖像瑕疵檢測裝置30運行於電子設備中。所述圖像瑕疵檢測裝置30可以包括多個由程式碼段所組成的功能模組。所述圖像瑕疵檢測裝置30中的各個程式段的程式碼可以存儲於記憶體中,並由至少一個處理器所執行,以執行圖像瑕疵檢測功能。 In some embodiments, the image flaw detection apparatus 30 operates in an electronic device. The image defect detection apparatus 30 may include a plurality of functional modules composed of program code segments. The program codes of each program section in the image defect detection apparatus 30 can be stored in the memory and executed by at least one processor to perform the image defect detection function.

本實施例中,所述圖像瑕疵檢測裝置30根據其所執行的功能,可以被劃分為多個功能模組。參閱圖2所示,所述圖像瑕疵檢測裝置30可以包括訓練圖像獲取模組301,第一潛特徵獲取模組302,第一重構誤差獲取模組303,第一概率分佈計算模組304、第二概率分佈計算模組305、散度計算模組306、模型訓練模組307、總誤差計算模組308及判斷模組309。本發明所稱的模組是指一種能夠被至少一個處理器所執行並且能夠完成固定功能的一系列電腦程式段,其存儲在記憶體中。所述在一些實施例中,關於各模組的功能將在後續的實施例中詳述。 In this embodiment, the image defect detection apparatus 30 can be divided into a plurality of functional modules according to the functions performed by the image defect detection apparatus 30 . Referring to FIG. 2, the image defect detection device 30 may include a training image acquisition module 301, a first latent feature acquisition module 302, a first reconstruction error acquisition module 303, and a first probability distribution calculation module 304 , a second probability distribution calculation module 305 , a divergence calculation module 306 , a model training module 307 , a total error calculation module 308 and a judgment module 309 . The module referred to in the present invention refers to a series of computer program segments that can be executed by at least one processor and can perform fixed functions, and are stored in a memory. In some embodiments, the functions of each module will be described in detail in subsequent embodiments.

所述訓練圖像獲取模組301獲取無瑕疵樣本訓練圖像。 The training image acquisition module 301 acquires flawless sample training images.

所述第一潛特徵獲取模組302將所述無瑕疵樣本訓練圖像輸入自編碼器,藉由所述自編碼器的編碼層計算得到所述無瑕疵樣本訓練圖像的第一潛特徵。 The first latent feature acquisition module 302 inputs the flawless sample training image into an autoencoder, and calculates the first latent feature of the flawless sample training image through the coding layer of the autoencoder.

在本發明的至少一個實施例中,所述第一潛特徵獲取模組302藉由所述自編碼器的編碼層計算得到所述無瑕疵樣本訓練圖像的第一潛特徵包括:將所述無瑕疵樣本訓練圖像進行向量化處理,得到所述無瑕疵樣本訓練圖像的特徵向量; 利用所述自編碼器中的所述編碼層對所述無瑕疵樣本訓練圖像的所述特徵向量進行運算,得到所述第一潛特徵。 In at least one embodiment of the present invention, the first latent feature obtaining module 302 calculates the first latent feature of the flawless sample training image through the coding layer of the autoencoder, comprising: The flawless sample training image is vectorized to obtain the feature vector of the flawless sample training image; The first latent feature is obtained by operating on the feature vector of the flawless sample training image by using the encoding layer in the autoencoder.

所述第一重構誤差獲取模組303將所述第一潛特徵輸入所述自編碼器的解碼層並計算得到所述無瑕疵樣本訓練圖像的第一重構圖像,並使用預設的誤差函數計算所述無瑕疵樣本訓練圖像和所述第一重構圖像得到所述無瑕疵樣本訓練圖像和所述第一重構圖像之間的第一重構誤差。 The first reconstruction error acquisition module 303 inputs the first latent feature into the decoding layer of the self-encoder and calculates the first reconstructed image of the flawless sample training image, and uses a preset Calculate the error function of the flawless sample training image and the first reconstructed image to obtain the first reconstruction error between the flawless sample training image and the first reconstructed image.

在本發明的至少一個實施例中,所述第一重構誤差獲取模組303將所述第一潛特徵輸入所述自編碼器的解碼層並計算得到所述無瑕疵樣本訓練圖像的第一重構圖像包括:利用所述自編碼器中的所述解碼層對所述第一潛特徵進行運算;對運算後得到的向量進行還原處理,得到所述第一重建圖像。 In at least one embodiment of the present invention, the first reconstruction error obtaining module 303 inputs the first latent feature into the decoding layer of the auto-encoder and calculates the first image of the flawless sample training image. A reconstructed image includes: using the decoding layer in the self-encoder to operate on the first latent feature; and performing restoration processing on the vector obtained after the operation to obtain the first reconstructed image.

所述第一概率分佈計算模組304將所述第一潛特徵輸入深度學習模型並計算得到所述第一潛特徵的第一概率分佈。 The first probability distribution calculation module 304 inputs the first latent feature into a deep learning model and calculates the first probability distribution of the first latent feature.

在本發明的至少一個實施例中,所述第一概率分佈計算模組304將所述第一潛特徵輸入深度學習模型並計算得到所述第一潛特徵的第一概率分佈包括:將所述第一潛特徵輸入所述深度學習模型;藉由所述深度學習模型中卷積層、池化層和至少一個隱藏層中的一個或多個對所述第一潛特徵進行運算,得到所述第一概率分佈。 In at least one embodiment of the present invention, the first probability distribution calculation module 304 inputs the first latent feature into a deep learning model and calculates to obtain the first probability distribution of the first latent feature includes: The first latent feature is input into the deep learning model; the first latent feature is operated by one or more of the convolutional layer, the pooling layer and at least one hidden layer in the deep learning model, and the first latent feature is obtained. a probability distribution.

所述第二概率分佈計算模組305將所述第一潛特徵輸入高斯混合模型並計算得到所述第一潛特徵的第二概率分佈。 The second probability distribution calculation module 305 inputs the first latent feature into a Gaussian mixture model and calculates a second probability distribution of the first latent feature.

在本發明的至少一個實施例中,所述第二概率分佈計算模組305將所述第一潛特徵輸入高斯混合模型並計算得到所述第一潛特徵的第二概率分佈包括:將所述第一潛特徵輸入所述高斯混合模型;藉由所述高斯混合模型擬合所述第一潛特徵的概率分佈,得到所述第二概率分佈。 In at least one embodiment of the present invention, the second probability distribution calculation module 305 inputs the first latent feature into a Gaussian mixture model and obtains the second probability distribution of the first latent feature by calculating: The first latent feature is input into the Gaussian mixture model; the probability distribution of the first latent feature is fitted by the Gaussian mixture model to obtain the second probability distribution.

具體地,所述高斯混合模型為

Figure 110105182-A0305-02-0014-3
其中,x i 表示第一潛特徵對應的向量,t=1,2,3...,M,M為第一潛特徵的維度,α k 為第k個高斯分佈的權重,μ k ,σ k 分別時第k個高斯分佈的均值和方差,N(x i k k )表示向量x i 符合均值為μ k 且方差為σ k 的正態分佈,K至少為3。 Specifically, the Gaussian mixture model is
Figure 110105182-A0305-02-0014-3
Among them, x i represents the vector corresponding to the first latent feature, t=1, 2, 3..., M, M is the dimension of the first latent feature, α k is the weight of the kth Gaussian distribution, μ k , σ k is the mean and variance of the k-th Gaussian distribution, respectively, N ( x i k k ) means that the vector x i conforms to a normal distribution with mean μ k and variance σ k , and K is at least 3.

所述散度計算模組306計算所述第一概率分佈和所述第二概率分佈之間的庫爾貝克-萊布勒散度。 The divergence calculation module 306 calculates the Kulbec-Leebler divergence between the first probability distribution and the second probability distribution.

優選地,所述計算所述第一概率分佈和所述第二概率分佈之間的庫爾貝克-萊布勒散度包括:根據公式

Figure 110105182-A0305-02-0014-5
計算所述第一概率分佈和所述第二概率分佈的庫爾貝克-萊布勒散度,其中,D KL (P||Q)為所述第一概率分佈和所述第二概率分佈的庫爾貝克-萊布勒散度,P(i)為所述第二概率分佈,Q(i)為所述第一概率分佈。 Preferably, the calculating the Kulbec-Leibler divergence between the first probability distribution and the second probability distribution includes: according to the formula
Figure 110105182-A0305-02-0014-5
Calculate the Kulbec-Leibler divergence of the first probability distribution and the second probability distribution, wherein D KL ( P || Q ) is the difference between the first probability distribution and the second probability distribution Kulbec-Leibler divergence, P ( i ) is the second probability distribution, and Q ( i ) is the first probability distribution.

所述模型訓練模組307根據所述第一重構誤差和所述庫爾貝克-萊布勒散度得到總損失,根據所述總損失優化所述自編碼器、所述深度學習模型及所述高斯混合模型,並根據所述總損失設定閾值。 The model training module 307 obtains a total loss according to the first reconstruction error and the Kulbec-Leibler divergence, and optimizes the autoencoder, the deep learning model and all the methods according to the total loss. The Gaussian mixture model is described, and the threshold is set according to the total loss.

在本發明的至少一個實施例中,所述模型訓練模組307根據所述第一重構誤差和所述庫爾貝克-萊布勒散度得到總損失,根據所述總損失優化所述自編碼器、所述深度學習模型及所述高斯混合模型包括:計算所述第一重構誤差與所述庫爾貝克-萊布勒散度的乘積,得到所述總損失;調整所述自編碼器、所述深度學習模型及所述高斯混合模型的參數對所述總損失進行最小化處理。 In at least one embodiment of the present invention, the model training module 307 obtains a total loss according to the first reconstruction error and the Kulbec-Leibler divergence, and optimizes the self-contained loss according to the total loss. The encoder, the deep learning model and the Gaussian mixture model include: calculating the product of the first reconstruction error and the Kulbeck-Leebler divergence to obtain the total loss; adjusting the self-encoding The total loss is minimized by the parameters of the engine, the deep learning model and the Gaussian mixture model.

在本發明的至少一個實施例中,調整所述自編碼器、所述深度學習模型及所述高斯混合模型的參數對所述總損失進行最小化處理的目的是優化所述自編碼器、所述深度學習模型及所述高斯混合模型,使得所述深度學習模 型與所述高斯混合模型根據所述自編碼器生成的重構圖像具有相同的概率分佈。 In at least one embodiment of the present invention, the purpose of adjusting the parameters of the autoencoder, the deep learning model and the Gaussian mixture model to minimize the total loss is to optimize the autoencoder, the the deep learning model and the Gaussian mixture model, so that the deep learning model has the same probability distribution as the reconstructed image generated by the Gaussian mixture model from the autoencoder.

所述總誤差計算模組308獲取測試樣本圖像,將所述測試樣本圖像輸入所述自編碼器,藉由所述自編碼器的編碼層計算得到所述測試樣本圖像的第二潛特徵,將所述第二潛特徵輸入所述自編碼器的解碼層並計算得到所述測試樣本圖像的第二重構圖像,並使用所述預設的誤差函數計算所述測試樣本圖像和所述第二重構圖像之間的第二重構誤差,將所述第二潛特徵輸入訓練完成的深度學習模型並計算得到所述第二潛特徵的第三概率分佈,根據所述第三概率分佈和所述第二重構誤差計算總誤差。 The total error calculation module 308 obtains a test sample image, inputs the test sample image into the auto-encoder, and calculates the second latent value of the test sample image through the coding layer of the auto-encoder. feature, input the second latent feature into the decoding layer of the self-encoder and calculate the second reconstructed image of the test sample image, and use the preset error function to calculate the test sample image The second reconstruction error between the image and the second reconstructed image, the second latent feature is input into the trained deep learning model and the third probability distribution of the second latent feature is obtained by calculation. A total error is calculated from the third probability distribution and the second reconstruction error.

在本發明的至少一個實施例中,所述總誤差計算模組308根據所述第三概率分佈和所述第二重構誤差計算總誤差包括:對所述第三概率分佈和所述第二重構誤差求和得到總誤差。 In at least one embodiment of the present invention, the total error calculation module 308 calculating the total error according to the third probability distribution and the second reconstruction error includes: calculating the third probability distribution and the second The reconstruction errors are summed to obtain the total error.

所述判斷模組309當所述總誤差大於或等於所述閾值時,確定所述測試樣本圖像為瑕疵圖像,當所述總誤差小於所述閾值時,確定所述測試樣本圖像為無瑕疵圖像。 The judging module 309 determines that the test sample image is a defective image when the total error is greater than or equal to the threshold, and determines that the test sample image is a defective image when the total error is less than the threshold. Flawless image.

本發明中,藉由同時訓練自編碼器、深度學習模型和高斯混合模型,使得深度學習模型和高斯混合模型可以輸出相同的概率分佈預測,從而可以使用深度學習模型替代高斯混合模型,在進行瑕疵檢測時實現更高的效率。 In the present invention, by training the autoencoder, the deep learning model and the Gaussian mixture model at the same time, the deep learning model and the Gaussian mixture model can output the same probability distribution prediction, so that the deep learning model can be used to replace the Gaussian mixture model. Achieve greater efficiency in detection.

實施例3 Example 3

圖3為本發明一實施方式中電子設備6的示意圖。 FIG. 3 is a schematic diagram of an electronic device 6 in an embodiment of the present invention.

所述電子設備6包括記憶體61、處理器62以及存儲在所述記憶體61中並可在所述處理器62上運行的電腦程式63。所述處理器62執行所述電腦程式63時實現上述圖像瑕疵檢測方法實施例中的步驟,例如圖1所示的步驟 S11~S19。或者,所述處理器62執行所述電腦程式63時實現上述圖像瑕疵檢測裝置實施例中各模組/單元的功能,例如圖2中的模組301~309。 The electronic device 6 includes a memory 61 , a processor 62 and a computer program 63 stored in the memory 61 and executable on the processor 62 . When the processor 62 executes the computer program 63, the steps in the above-mentioned embodiment of the image defect detection method are implemented, such as the steps shown in FIG. 1 . S11~S19. Alternatively, when the processor 62 executes the computer program 63, the functions of each module/unit in the above-mentioned embodiment of the image defect detection apparatus are realized, for example, the modules 301-309 in FIG. 2 .

示例性的,所述電腦程式63可以被分割成一個或多個模組/單元,所述一個或者多個模組/單元被存儲在所述記憶體61中,並由所述處理器62執行,以完成本發明。所述一個或多個模組/單元可以是能夠完成特定功能的一系列電腦程式指令段,所述指令段用於描述所述電腦程式63在所述電子設備6中的執行過程。例如,所述電腦程式63可以被分割成圖2中的訓練圖像獲取模組301,第一潛特徵獲取模組302,第一重構誤差獲取模組303,第一概率分佈計算模組304、第二概率分佈計算模組305、散度計算模組306、模型訓練模組307、總誤差計算模組308及判斷模組309,各模組具體功能參見實施例2。 Exemplarily, the computer program 63 can be divided into one or more modules/units, and the one or more modules/units are stored in the memory 61 and executed by the processor 62 , to complete the present invention. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program 63 in the electronic device 6 . For example, the computer program 63 can be divided into the training image acquisition module 301 in FIG. 2 , the first latent feature acquisition module 302 , the first reconstruction error acquisition module 303 , and the first probability distribution calculation module 304 , the second probability distribution calculation module 305, the divergence calculation module 306, the model training module 307, the total error calculation module 308 and the judgment module 309. For the specific functions of each module, refer to Embodiment 2.

本實施方式中,所述電子設備6可以是桌上型電腦、筆記本、掌上型電腦、伺服器及雲端終端裝置等計算設備。本領域技術人員可以理解,所述示意圖僅僅是電子設備6的示例,並不構成對電子設備6的限定,可以包括比圖示更多或更少的部件,或者組合某些部件,或者不同的部件,例如所述電子設備6還可以包括輸入輸出設備、網路接入設備、匯流排等。 In this embodiment, the electronic device 6 may be a computing device such as a desktop computer, a notebook, a palmtop computer, a server, and a cloud terminal device. Those skilled in the art can understand that the schematic diagram is only an example of the electronic device 6, and does not constitute a limitation to the electronic device 6, and may include more or less components than the one shown, or combine some components, or different Components such as the electronic device 6 may also include input and output devices, network access devices, bus bars, and the like.

所稱處理器62可以是中央處理模組(Central Processing Unit,CPU),還可以是其他通用處理器、數位訊號處理器(Digital Signal Processor,DSP)、專用積體電路(Application Specific Integrated Circuit,ASIC)、現場可程式設計閘陣列(Field-Programmable Gate Array,FPGA)或者其他可程式設計邏輯器件、分立門或者電晶體邏輯器件、分立硬體元件等。通用處理器可以是微處理器或者所述處理器62也可以是任何常規的處理器等,所述處理器62是所述電子設備6的控制中心,利用各種介面和線路連接整個電子設備6的各個部分。 The processor 62 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs) ), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor 62 can also be any conventional processor, etc. The processor 62 is the control center of the electronic device 6, and uses various interfaces and lines to connect the entire electronic device 6. various parts.

所述記憶體61可用於存儲所述電腦程式63和/或模組/單元,所述處理器62藉由運行或執行存儲在所述記憶體61內的電腦程式和/或模組/單元, 以及調用存儲在記憶體61內的資料,實現所述電子設備6的各種功能。所述記憶體61可主要包括存儲程式區和存儲資料區,其中,存儲程式區可存儲作業系統、至少一個功能所需的應用程式(比如聲音播放功能、圖像播放功能等)等;存儲資料區可存儲根據電子設備6的使用所創建的資料(比如音訊資料、電話本等)等。此外,記憶體61可以包括高速隨機存取記憶體,還可以包括非易失性記憶體,例如硬碟、記憶體、插接式硬碟,智慧存儲卡(Smart Media Card,SMC),安全數位(Secure Digital,SD)卡,快閃記憶體卡(Flash Card)、至少一個磁碟記憶體件、快閃記憶體器件、或其他易失性固態記憶體件。 The memory 61 can be used to store the computer programs 63 and/or modules/units, and the processor 62 runs or executes the computer programs and/or modules/units stored in the memory 61, And call the data stored in the memory 61 to realize various functions of the electronic device 6 . The memory 61 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; storage data The area may store data (such as audio data, phone book, etc.) created according to the use of the electronic device 6, and the like. In addition, the memory 61 may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, memory, plug-in hard disk, Smart Media Card (SMC), Secure Digital (Secure Digital, SD) card, flash memory card (Flash Card), at least one disk memory device, flash memory device, or other volatile solid state memory device.

所述電子設備6集成的模組/單元如果以軟體功能模組的形式實現並作為獨立的產品銷售或使用時,可以存儲在一個電腦可讀取存儲介質中。基於這樣的理解,本發明實現上述實施例方法中的全部或部分流程,也可以藉由電腦程式來指令相關的硬體來完成,所述的電腦程式可存儲於一電腦可讀存儲介質中,所述電腦程式在被處理器執行時,可實現上述各個方法實施例的步驟。其中,所述電腦程式包括電腦程式代碼,所述電腦程式代碼可以為原始程式碼形式、物件代碼形式、可執行檔或某些中間形式等。所述電腦可讀介質可以包括:能夠攜帶所述電腦程式代碼的任何實體或裝置、記錄介質、隨身碟、移動硬碟、磁碟、光碟、電腦記憶體、唯讀記憶體(ROM,Read-Only Memory)、隨機存取記憶體(RAM,Random Access Memory)、電載波信號、電信信號以及軟體分發介質等。 If the modules/units integrated in the electronic device 6 are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the present invention realizes all or part of the processes in the methods of the above embodiments, and can also be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, When the computer program is executed by the processor, the steps of the above method embodiments can be implemented. Wherein, the computer program includes computer program code, and the computer program code may be in the form of original code, object code, executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a flash drive, a removable hard disk, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM, Read-Only Memory); Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc.

在本發明所提供的幾個實施例中,應該理解到,所揭露的裝置和方法,可以藉由其它的方式實現。例如,以上所描述的裝置實施例僅僅是示意性的,例如,所述模組的劃分,僅僅為一種邏輯功能劃分,實際實現時可以有另外的劃分方式。 In the several embodiments provided by the present invention, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the device embodiments described above are only illustrative. For example, the division of the modules is only a logical function division, and other division methods may be used in actual implementation.

另外,在本發明各個實施例中的各功能模組可以集成在相同處理模組中,也可以是各個模組單獨物理存在,也可以兩個或兩個以上模組集成在相同模組中。上述集成的模組既可以採用硬體的形式實現,也可以採用硬體加軟體功能模組的形式實現。 In addition, each functional module in each embodiment of the present invention may be integrated in the same processing module, or each module may exist physically alone, or two or more modules may be integrated in the same module. The above-mentioned integrated modules can be implemented in the form of hardware, or can be implemented in the form of hardware plus software function modules.

對於本領域技術人員而言,顯然本發明不限於上述示範性實施例的細節,而且在不背離本發明的精神或基本特徵的情況下,能夠以其他的具體形式實現本發明。因此,無論從哪一點來看,均應將實施例看作是示範性的,而且是非限制性的,本發明的範圍由所附請求項而不是上述說明限定,因此旨在將落在請求項的等同要件的含義和範圍內的所有變化涵括在本發明內。不應將請求項中的任何附圖標記視為限制所涉及的請求項。此外,顯然“包括”一詞不排除其他模組或步驟,單數不排除複數。電子設備請求項中陳述的多個模組或電子設備也可以由同一個模組或電子設備藉由軟體或者硬件來實現。第一,第二等詞語用來表示名稱,而並不表示任何特定的順序。 It will be apparent to those skilled in the art that the present invention is not limited to the details of the above-described exemplary embodiments, but that the present invention may be embodied in other specific forms without departing from the spirit or essential characteristics of the invention. Therefore, the embodiments are to be regarded in all respects as illustrative and not restrictive, and the scope of the present invention is defined by the appended claims rather than the foregoing description, and is therefore intended to fall within the scope of the claims. All changes within the meaning and range of the equivalents of , are included in the present invention. Any reference sign in a claim should not be construed as limiting the claim to which it relates. Furthermore, it is clear that the word "comprising" does not exclude other modules or steps, and the singular does not exclude the plural. Multiple modules or electronic devices stated in the electronic device claim may also be implemented by the same module or electronic device through software or hardware. The terms first, second, etc. are used to denote names and do not denote any particular order.

綜上所述,本發明符合發明專利要件,爰依法提出專利申請。惟,以上所述僅為本發明之較佳實施方式,舉凡熟悉本案技藝之人士,在援依本案創作精神所作之等效修飾或變化,皆應包含於以下之申請專利範圍內。 To sum up, the present invention complies with the requirements of an invention patent, and a patent application can be filed in accordance with the law. However, the above descriptions are only the preferred embodiments of the present invention, and for those who are familiar with the techniques of this case, equivalent modifications or changes made in accordance with the creative spirit of this case shall be included in the scope of the following patent application.

S11~S19:步驟 S11~S19: Steps

Claims (10)

一種圖像瑕疵檢測方法,應用在電子設備中,其中,所述方法包括:獲取無瑕疵樣本訓練圖像;將所述無瑕疵樣本訓練圖像輸入自編碼器,藉由所述自編碼器的編碼層計算得到所述無瑕疵樣本訓練圖像的第一潛特徵;將所述第一潛特徵輸入所述自編碼器的解碼層並計算得到所述無瑕疵樣本訓練圖像的第一重構圖像,並使用預設的誤差函數計算所述無瑕疵樣本訓練圖像和所述第一重構圖像得到所述無瑕疵樣本訓練圖像和所述第一重構圖像之間的第一重構誤差;將所述第一潛特徵輸入深度學習模型並計算得到所述第一潛特徵的第一概率分佈;將所述第一潛特徵輸入高斯混合模型並計算得到所述第一潛特徵的第二概率分佈;計算所述第一概率分佈和所述第二概率分佈之間的庫爾貝克-萊布勒散度;根據所述第一重構誤差和所述庫爾貝克-萊布勒散度得到總損失,根據所述總損失優化所述自編碼器、所述深度學習模型及所述高斯混合模型,並根據所述總損失設定閾值;獲取測試樣本圖像,將所述測試樣本圖像輸入所述自編碼器,藉由所述自編碼器的編碼層計算得到所述測試樣本圖像的第二潛特徵,將所述第二潛特徵輸入所述自編碼器的解碼層並計算得到所述測試樣本圖像的第二重構圖像,並使用所述預設的誤差函數計算所述測試樣本圖像和所述第二重構圖像之間的第二重構誤差,將所述第二潛特徵輸入訓練完成的深度學習模型並計算得到所 述第二潛特徵的第三概率分佈,根據所述第三概率分佈和所述第二重構誤差計算總誤差;當所述總誤差大於或等於所述閾值時,確定所述測試樣本圖像為瑕疵圖像,當所述總誤差小於所述閾值時,確定所述測試樣本圖像為無瑕疵圖像。 An image flaw detection method, applied in electronic equipment, wherein the method comprises: acquiring a flawless sample training image; inputting the flawless sample training image into an autoencoder, The encoding layer calculates and obtains the first latent feature of the flawless sample training image; inputs the first latent feature into the decoding layer of the self-encoder and calculates to obtain the first reconstruction of the flawless sample training image image, and use the preset error function to calculate the flawless sample training image and the first reconstructed image to obtain the first error between the flawless sample training image and the first reconstructed image. a reconstruction error; input the first latent feature into a deep learning model and calculate the first probability distribution of the first latent feature; input the first latent feature into a Gaussian mixture model and calculate the first latent feature a second probability distribution of features; calculating the Kulbec-Leibler divergence between the first probability distribution and the second probability distribution; The total loss is obtained from the Buller divergence, the autoencoder, the deep learning model and the Gaussian mixture model are optimized according to the total loss, and a threshold is set according to the total loss; the test sample image is obtained, and the The test sample image is input into the self-encoder, the second latent feature of the test sample image is calculated by the coding layer of the self-encoder, and the second latent feature is input into the decoding of the self-encoder layer and calculate the second reconstructed image of the test sample image, and use the preset error function to calculate the second reconstruction between the test sample image and the second reconstructed image error, input the second latent feature into the trained deep learning model and calculate the obtained the third probability distribution of the second latent feature, and calculate the total error according to the third probability distribution and the second reconstruction error; when the total error is greater than or equal to the threshold, determine the test sample image For a flawed image, when the total error is less than the threshold, the test sample image is determined to be a flawless image. 如請求項1所述的圖像瑕疵檢測方法,其中,所述藉由所述自編碼器的編碼層計算得到所述無瑕疵樣本訓練圖像的第一潛特徵包括:將所述無瑕疵樣本訓練圖像進行向量化處理,得到所述無瑕疵樣本訓練圖像的特徵向量;利用所述自編碼器中的所述編碼層對所述無瑕疵樣本訓練圖像的所述特徵向量進行運算,得到所述第一潛特徵。 The image flaw detection method according to claim 1, wherein calculating the first latent feature of the flawless sample training image by the coding layer of the self-encoder comprises: converting the flawless sample The training image is vectorized to obtain the feature vector of the flawless sample training image; the coding layer in the self-encoder is used to operate on the feature vector of the flawless sample training image, The first latent feature is obtained. 如請求項1所述的圖像瑕疵檢測方法,其中,所述將所述第一潛特徵輸入所述自編碼器的解碼層並計算得到所述無瑕疵樣本訓練圖像的第一重構圖像包括:利用所述自編碼器中的所述解碼層對所述第一潛特徵進行運算;對運算後得到的向量進行還原處理,得到所述第一重建圖像。 The image flaw detection method according to claim 1, wherein the first latent feature is input into the decoding layer of the auto-encoder and the first reconstruction image of the flawless sample training image is obtained by calculation The image includes: using the decoding layer in the self-encoder to operate on the first latent feature; and performing restoration processing on the vector obtained after the operation to obtain the first reconstructed image. 如請求項1所述的圖像瑕疵檢測方法,其中,所述將所述第一潛特徵輸入深度學習模型並計算得到所述第一潛特徵的第一概率分佈包括:將所述第一潛特徵輸入所述深度學習模型;藉由所述深度學習模型中卷積層、池化層和至少一個隱藏層中的一個或多個對所述第一潛特徵進行運算,得到所述第一概率分佈。 The image flaw detection method according to claim 1, wherein the inputting the first latent feature into a deep learning model and calculating the first probability distribution of the first latent feature comprises: The feature is input into the deep learning model; the first latent feature is operated by one or more of the convolution layer, the pooling layer and at least one hidden layer in the deep learning model to obtain the first probability distribution . 如請求項1所述的圖像瑕疵檢測方法,其中,所述計算所述第一概率分佈和所述第二概率分佈之間的庫爾貝克-萊布勒散度包括: 根據公式
Figure 110105182-A0305-02-0022-15
計算所述第一概率分佈和所述第二概率分佈的庫爾貝克-萊布勒散度,其中,D KL (P||Q)為所述第一概率分佈和所述第二概率分佈的庫爾貝克-萊布勒散度,P(i)為所述第二概率分佈,Q(i)為所述第一概率分佈。
The image flaw detection method according to claim 1, wherein the calculating the Kulbec-Leebler divergence between the first probability distribution and the second probability distribution comprises: according to the formula
Figure 110105182-A0305-02-0022-15
Calculate the Kulbec-Leibler divergence of the first probability distribution and the second probability distribution, wherein D KL ( P || Q ) is the difference between the first probability distribution and the second probability distribution Kulbec-Leibler divergence, P ( i ) is the second probability distribution, and Q ( i ) is the first probability distribution.
如請求項1所述的圖像瑕疵檢測方法,其中,所述根據所述第一重構誤差和所述庫爾貝克-萊布勒散度得到總損失,根據所述總損失優化所述自編碼器、所述深度學習模型及所述高斯混合模型包括:計算所述第一重構誤差與所述庫爾貝克-萊布勒散度的乘積,得到所述總損失;調整所述自編碼器、所述深度學習模型及所述高斯混合模型的參數對所述總損失進行最小化處理。 The image defect detection method according to claim 1, wherein a total loss is obtained according to the first reconstruction error and the Kulbec-Leibler divergence, and the self-contained loss is optimized according to the total loss. The encoder, the deep learning model and the Gaussian mixture model include: calculating the product of the first reconstruction error and the Kulbeck-Leebler divergence to obtain the total loss; adjusting the self-encoding The total loss is minimized by the parameters of the engine, the deep learning model and the Gaussian mixture model. 如請求項1所述的圖像瑕疵檢測方法,其中,所述根據所述第三概率分佈和所述第二重構誤差計算總誤差包括:對所述第三概率分佈和所述第二重構誤差求和得到總誤差。 The image defect detection method according to claim 1, wherein the calculating the total error according to the third probability distribution and the second reconstruction error comprises: comparing the third probability distribution and the second reconstruction error Sum the construction errors to get the total error. 一種圖像瑕疵檢測裝置,其中,所述裝置包括:訓練圖像獲取模組,用於獲取無瑕疵樣本訓練圖像;第一潛特徵獲取模組,用於將所述無瑕疵樣本訓練圖像輸入自編碼器,藉由所述自編碼器的編碼層計算得到所述無瑕疵樣本訓練圖像的第一潛特徵;第一重構誤差獲取模組,用於將所述第一潛特徵輸入所述自編碼器的解碼層並計算得到所述無瑕疵樣本訓練圖像的第一重構圖像,並使用預設的誤差函數計算所述無瑕疵樣本訓練圖像和所述第一重構圖像得到所述無瑕疵樣本訓練圖像和所述第一重構圖像之間的第一重構誤差;第一概率分佈計算模組,用於將所述第一潛特徵輸入深度學習模型並計算得到所述第一潛特徵的第一概率分佈; 第二概率分佈計算模組,用於將所述第一潛特徵輸入高斯混合模型並計算得到所述第一潛特徵的第二概率分佈;散度計算模組,用於計算所述第一概率分佈和所述第二概率分佈之間的庫爾貝克-萊布勒散度;模型訓練模組,用於根據所述第一重構誤差和所述庫爾貝克-萊布勒散度得到總損失,根據所述總損失優化所述自編碼器、所述深度學習模型及所述高斯混合模型,並根據所述總損失設定閾值;總誤差計算模組,用於獲取測試樣本圖像,將所述測試樣本圖像輸入所述自編碼器,藉由所述自編碼器的編碼層計算得到所述測試樣本圖像的第二潛特徵,將所述第二潛特徵輸入所述自編碼器的解碼層並計算得到所述測試樣本圖像的第二重構圖像,並使用所述預設的誤差函數計算所述測試樣本圖像和所述第二重構圖像之間的第二重構誤差,將所述第二潛特徵輸入訓練完成的深度學習模型並計算得到所述第二潛特徵的第三概率分佈,根據所述第三概率分佈和所述第二重構誤差計算總誤差;判斷模組,用於當所述總誤差大於或等於所述閾值時,確定所述測試樣本圖像為瑕疵圖像,當所述總誤差小於所述閾值時,確定所述測試樣本圖像為無瑕疵圖像。 An image defect detection device, wherein the device comprises: a training image acquisition module for acquiring flawless sample training images; a first latent feature acquisition module for acquiring the flawless sample training images Input the self-encoder, and calculate the first latent feature of the flawless sample training image by the coding layer of the self-encoder; the first reconstruction error acquisition module is used to input the first latent feature The decoding layer of the auto-encoder obtains the first reconstructed image of the flawless sample training image, and uses a preset error function to calculate the flawless sample training image and the first reconstructed image. The image obtains the first reconstruction error between the flawless sample training image and the first reconstructed image; the first probability distribution calculation module is used to input the first latent feature into the deep learning model and calculating the first probability distribution of the first latent feature; The second probability distribution calculation module is used to input the first latent feature into a Gaussian mixture model and calculate the second probability distribution of the first latent feature; the divergence calculation module is used to calculate the first probability the Kulbeck-Leibler divergence between the distribution and the second probability distribution; a model training module for obtaining a total loss, optimize the self-encoder, the deep learning model and the Gaussian mixture model according to the total loss, and set a threshold according to the total loss; the total error calculation module is used to obtain the test sample image, and the The test sample image is input into the self-encoder, the second latent feature of the test sample image is calculated by the coding layer of the self-encoder, and the second latent feature is input into the self-encoder The decoding layer and the second reconstructed image of the test sample image are obtained by calculation, and the preset error function is used to calculate the second reconstructed image between the test sample image and the second reconstructed image. Reconstruction error, input the second latent feature into the trained deep learning model and calculate the third probability distribution of the second latent feature, and calculate the total probability according to the third probability distribution and the second reconstruction error. error; a judgment module for determining that the test sample image is a defective image when the total error is greater than or equal to the threshold, and determining the test sample image when the total error is less than the threshold Like a flawless image. 一種電子設備,其中,所述電子設備包括:記憶體,存儲至少一個指令;及處理器,執行所述記憶體中存儲的指令以實現如請求項1至7中任一項所述的圖像瑕疵檢測方法。 An electronic device, wherein the electronic device comprises: a memory that stores at least one instruction; and a processor that executes the instructions stored in the memory to realize the image according to any one of claim 1 to 7 Defect detection method. 一種存儲介質,其上存儲有電腦程式,其中:所述電腦程式被處理器執行時實現如請求項1至7中任一項所述的圖像瑕疵檢測方法。 A storage medium having a computer program stored thereon, wherein: the computer program implements the image defect detection method according to any one of claim 1 to claim 7 when the computer program is executed by a processor.
TW110105182A 2021-02-09 2021-02-09 Image defect detection method, image defect detection device, electronic device and storage media TWI762193B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
TW110105182A TWI762193B (en) 2021-02-09 2021-02-09 Image defect detection method, image defect detection device, electronic device and storage media

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
TW110105182A TWI762193B (en) 2021-02-09 2021-02-09 Image defect detection method, image defect detection device, electronic device and storage media

Publications (2)

Publication Number Publication Date
TWI762193B true TWI762193B (en) 2022-04-21
TW202232382A TW202232382A (en) 2022-08-16

Family

ID=82198945

Family Applications (1)

Application Number Title Priority Date Filing Date
TW110105182A TWI762193B (en) 2021-02-09 2021-02-09 Image defect detection method, image defect detection device, electronic device and storage media

Country Status (1)

Country Link
TW (1) TWI762193B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109583489A (en) * 2018-11-22 2019-04-05 中国科学院自动化研究所 Defect classifying identification method, device, computer equipment and storage medium
CN109829893A (en) * 2019-01-03 2019-05-31 武汉精测电子集团股份有限公司 A kind of defect object detection method based on attention mechanism
CN110599487A (en) * 2019-09-23 2019-12-20 北京海益同展信息科技有限公司 Article detection method, apparatus and storage medium
US20200005449A1 (en) * 2018-06-29 2020-01-02 Utechzone Co., Ltd. Defect inspection system and method using artificil intelligence
TW202006608A (en) * 2018-07-02 2020-02-01 由田新技股份有限公司 Recursive training method and detection system for deep learning system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200005449A1 (en) * 2018-06-29 2020-01-02 Utechzone Co., Ltd. Defect inspection system and method using artificil intelligence
TW202006608A (en) * 2018-07-02 2020-02-01 由田新技股份有限公司 Recursive training method and detection system for deep learning system
CN109583489A (en) * 2018-11-22 2019-04-05 中国科学院自动化研究所 Defect classifying identification method, device, computer equipment and storage medium
CN109829893A (en) * 2019-01-03 2019-05-31 武汉精测电子集团股份有限公司 A kind of defect object detection method based on attention mechanism
CN110599487A (en) * 2019-09-23 2019-12-20 北京海益同展信息科技有限公司 Article detection method, apparatus and storage medium

Also Published As

Publication number Publication date
TW202232382A (en) 2022-08-16

Similar Documents

Publication Publication Date Title
US20220207707A1 (en) Image defect detection method, electronic device using the same
US20220198228A1 (en) Method for detecting defects in multi-scale images and computing device utilizing method
CN114764768A (en) Defect detection and classification method and device, electronic equipment and storage medium
US20220189008A1 (en) Method for detecting data defects and computing device utilizing method
CN114943673A (en) Defect image generation method and device, electronic equipment and storage medium
US11983866B2 (en) Image defect detection method, electronic device using the same
TWI803243B (en) Method for expanding images, computer device and storage medium
CN108648135B (en) Hidden model training and using method, device and computer readable storage medium
TWI762193B (en) Image defect detection method, image defect detection device, electronic device and storage media
CN113704452B (en) Data recommendation method, device, equipment and medium based on Bert model
CN112071331B (en) Voice file restoration method and device, computer equipment and storage medium
CN114881913A (en) Image defect detection method and device, electronic equipment and storage medium
TWI778519B (en) Defective image generation method, defective image generation device, electronic device and storage media
TWI792134B (en) Image defect detection method, image defect detection device, electronic device, and storage media
CN114970670A (en) Model fairness assessment method and device
TWI755212B (en) Method and related equipment for determinting input dimensions of model
TWI764492B (en) Classification method, classification device for defect detection, electronic device and storage media
TWI795729B (en) Image defect detection method, image defect detection device, electronic device and storage media
TWI748867B (en) Image defect dection method, image defect dection device, electronic device and storage media
TWI755213B (en) Method and device for detecting defections, computer device and storage medium
TWI761109B (en) Cell density grouping method, cell density grouping device, electronic device and storage media
US20220198633A1 (en) Defect detection method, electronic device and storage medium
US20220198645A1 (en) Model input size determination method, electronic device and storage medium
CN115984302B (en) Multi-mode remote sensing image processing method based on sparse hybrid expert network pre-training
TWI755176B (en) Method and device for calculating cell distribution density, electronic device, and storage unit