CN-115240195-B - Automatic detection method and device for defects of medicine bottles and storage medium
Abstract
The invention provides an automatic detection method, device and storage medium for defects of medicine bottles, which are characterized in that the defects of appearance contours of the medicine bottles are detected through a Res-Seg semantic segmentation network, foreground extraction and horizontal correction are carried out on the medicine bottles, the defect data of the medicine bottles are generated through CycleGAN, the defects of the surfaces of the medicine bottles and the defects of foreign matters in the medicine bottles are detected through a RETINANET target detection network, and the deformation defects of the bottle heads and the bottle tails of the medicine bottles are detected through a Resnet image classification network. The invention can detect the appearance defect of the medicine bottle and the foreign matters in the bottle, has strong adaptability to the environment, can effectively detect the tiny defect characteristics, does not need to perform a large amount of pre-training work, and is simple and reliable to operate.
Inventors
- LI XIN
- WANG SURONG
- LI BOZHI
- LI CONG
- TANG HONG
Assignees
- 成都泓睿科技有限责任公司
Dates
- Publication Date
- 20260505
- Application Date
- 20220804
Claims (11)
- 1. The automatic detection method for the defects of the medicine bottle is characterized by comprising the following steps of: Detecting appearance outline defects of a medicine bottle through a Res-Seg semantic segmentation network, and carrying out foreground extraction and horizontal correction on the medicine bottle, wherein the Res-Seg semantic segmentation network uses a single backbone network to extract space information and semantic information, a segmentation flow of the Res-Seg semantic segmentation network comprises three parts of feature extraction, feature fusion and prediction output, feature extraction is carried out through a CoTx module, and the CoTx module specifically comprises: Q=F k×k (X),K 1 =QW k ,V=QW v , SA(K 1 ,Q)=Softmax(Mean([K 1 ,Q]W θ W σ )), K 2 =SA·V, Y=K 1 +K 2 , Wherein Q represents an inquiry matrix, F k×k represents a kxk convolution operation, X represents an input feature, K 1 represents a key matrix, which is local static context information, V represents a value matrix, W k represents a 1X1 convolution weight used for calculation of K 1 , W v represents a 1X1 convolution weight used for calculation of V, W θ represents a 1X1 convolution weight, W σ represents a 1X1 convolution weight, K 2 represents dynamic context information, SA is a self-attention distribution weight, and Y represents an output feature; generating vial defect data via CycleGAN to an antagonism network; detecting surface defects of the medicine bottle and foreign body defects in the bottle through RETINANET target detection network; And detecting deformation defects of the bottle head and the bottle tail of the medicine bottle through Resnet image classification networks.
- 2. The automatic detection method for defects of medicine bottles according to claim 1, wherein feature fusion is performed through an FFM module, and the FFM module specifically comprises: res =[c 3 ,p 3 ]W r , A=Sigmoid(Avg(res)W θ W σ ), f 3 =res·A+res, Where res is a fusion feature of a spatial path and a context path, c 3 is a spatial path feature, p 3 is a context path feature, W r is a spatial path and context path feature fusion matrix, a is an attention vector, and f 3 is a refinement feature.
- 3. The automatic detection method for defects of medicine bottles according to claim 1, wherein the loss function of the Res-Seg semantic segmentation network is specifically: CELoss i =-y i log(p i ), losses=sort(CELoss i ), , Wherein CELoss i denotes a cross entropy loss function of the i-th pixel, y i denotes a class of the i-th pixel, p denotes a probability of a target, losses denotes a cross entropy loss value list, loss denotes a final loss value obtained by the cross entropy loss function, and H and W denote a height and a broadband size of the divided prediction image.
- 4. The automatic detection method for defects of medicine bottles according to claim 1, wherein detail information learning is jointly optimized through BCELoss and DICELoss modules, specifically: BCELoss=-(ylog(p)+(1-y)log(1-p)), , Wherein BCELoss denotes a binary cross entropy loss function, y denotes a pixel class, p denotes a probability of a target, DICELoss denotes a dic difference loss function, H and W denote a height and a broadband size of a detail predicted image, taking ε=1.
- 5. The automatic detection method for defects of medicine bottles according to claim 1, wherein the defect of deformation of the appearance outline of the medicine bottle is judged by a mask, specifically: , Wherein r w is the width error ratio, w is the width of the defect outline, w' is the standard value of the outline width, deltaw is the error range of the width, r s is the area error ratio, s is the area of the defect inner outline, deltas is the maximum value of the allowed area of the defect inner outline, and f (r w ,r s ) is the outline defect qualification judging function.
- 6. The automatic detection method for defects of a medicine bottle according to claim 5, wherein when the appearance outline of the medicine bottle is deformed beyond a set error, the subsequent station does not detect the appearance outline of the medicine bottle, marks the appearance outline as a defective product and rejects the defective product, and when the appearance outline of the medicine bottle is deformed within an allowable error, the appearance outline of the medicine bottle is subjected to foreground extraction through a mask and then is subjected to horizontal correction through affine transformation.
- 7. The automatic detection method for defects in medicine bottles according to claim 1, wherein said CycleGAN generation countermeasure network is used for data expansion of defect images, a generator is constructed by STDC module, downsampling layer and upsampling layer in the generator are removed, and information loss is reduced.
- 8. The automatic detection method of medicine bottle defects according to claim 1, wherein the RETINANET target detection network specifically comprises a deformable convolution DCN module, a spatial pyramid pooling SPP module and a PAN structure.
- 9. The automatic detection method for defects of medicine bottles according to claim 1, wherein said Resnet image classification network uses Res2net residual blocks to construct a feature extraction layer, and Res2net performs multi-scale processing in residual blocks to increase receptive fields of network layers.
- 10. An automatic medicine bottle defect detecting apparatus for operating the automatic medicine bottle defect detecting method according to any one of claims 1 to 9, comprising: The Res-Seg semantic segmentation network module is used for detecting appearance outline defects of the medicine bottle and carrying out prospect extraction and horizontal correction on the medicine bottle; CycleGAN generate an countermeasure network module for generating vial defect data; RETINANET a target detection network module for detecting surface defects of the medicine bottle and foreign body defects in the bottle; Resnet image classification network module for detecting deformation defect of bottle head and tail of medicine bottle.
- 11. A storage medium in which a program for automatically detecting defects of a medicine bottle is stored, the CPU realizing the automatic detecting method for defects of a medicine bottle according to claims 1 to 9 when executing the program.
Description
Automatic detection method and device for defects of medicine bottles and storage medium Technical Field The invention belongs to the technical field of machine vision detection, and particularly relates to a method and a device for automatically detecting defects of a medicine bottle and a storage medium. Background Before the medicine bottle leaves the factory, the blowing, filling and sealing of the medicine bottle can generate some defects in the sterile production process, including deformation defects of the outline of the bottle body, surface dirt scratch defects, foreign matter defects in the bottle and the like. When the blow molding treatment is carried out, the problems of poor process stability and consistency can cause some deformation defects and accumulation defects of products, when liquid filling is carried out, the situation that foreign matters enter the bottle, such as glass scraps, rubber plug scraps, metal scraps, color points, white lumps, fibers, hair and other tiny insoluble foreign matters, when tail sealing treatment is carried out, the situation that the tail of the bottle is deformed, when the cutting is carried out on the aligned plastic medicine bottle, the situation that the cutting deviation and few branches exist, and the defect that the foreign matters adhere to the surface of the bottle body, the bruise, the scratch and the like exist in the transportation process. In order to ensure the safety of medical supplies and the aesthetic appearance of medicine bottles, it is necessary to detect the appearance of medicine bottle packages and foreign matters in the bottles. At present, the application of the machine vision technology in the automatic detection field is wider and wider, the application is more and more mainly in the medicine and beverage industry, the quality detection of medicine bottles is mainly carried out by adopting manual light detection, the manual light detection is time-consuming and labor-consuming, subjective false detection and omission detection are carried out, the safety of products cannot be ensured, and the difference exists between different detection standards, the distribution of the quality of the products is different, the image of the products is not easy to maintain, so that a detection method capable of automatically detecting the appearance defects of medicine bottles and foreign matters in the bottles is urgently needed to replace human eye detection. The existing detection method for detecting the appearance defects of the medicine bottle vision equipment still has some problems, for example, the traditional detection method is greatly influenced by ambient light, a large number of parameters need to be regulated for recalibration once the imaging environment changes, the operation is extremely complicated, the defect detection method based on deep learning can only identify the types and positions of defects, the detection effect on fine defect features is poor, the network feature extraction capability is not strong, in addition, the existing detection algorithm needs to carry out a large number of pre-training operations, the flow is too complex, repeated manual training and parameter regulation are needed, the development cost is greatly increased, and the use experience of users is poor. Disclosure of Invention The invention aims to solve the problems, and provides a medicine bottle defect detection method which can detect appearance defects of medicine bottles and foreign matters in the bottles, has strong adaptability to environment, can effectively detect fine defect characteristics, does not need to perform a large amount of pre-training work, and is simple and reliable to operate. In order to achieve the above purpose, the invention adopts the following technical scheme: An automatic detection method for defects of a medicine bottle comprises the following steps: Detecting appearance outline defects of the medicine bottle through a Res-Seg semantic segmentation network, and carrying out prospect extraction and horizontal correction on the medicine bottle; generating vial defect data via CycleGAN to an antagonism network; detecting surface defects of the medicine bottle and foreign body defects in the bottle through RETINANET target detection network; And detecting deformation defects of the bottle head and the bottle tail of the medicine bottle through Resnet image classification networks. Further, the Res-Seg semantic segmentation network uses a single backbone network to extract space information and semantic information, and the segmentation flow of the Res-Seg semantic segmentation network comprises three parts of feature extraction, feature fusion and prediction output. Further, feature extraction is performed by CoTx modules, and the CoTx modules specifically are: Q=Fk×k(X)K1=QWk V=QWv SA(K1,Q)=Softmax(Mean([K1,Q]WθWσ)) K2=SA·V Y=K1+K2 wherein Q represents an inquiry matrix, F k×k represents a kxk convolution operation,