Hair defect detection method and device for syringe
Through the multi-directional feature aggregation module and codec model, combined with the pseudo-hair training set and reconstruction loss function, the problem of low hair defect detection accuracy in the existing technology is solved, high-precision hair defect detection is achieved, and medical equipment is improved. Reliability of production and quality inspection.
Patent Information
- Application Number
- CN202410940681.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-07-15
AI Technical Summary
The existing defect detection model based on the codec network structure cannot effectively prevent abnormal feature information from flowing into the decoder, resulting in the inability to accurately detect hair defects in medical syringes, affecting detection accuracy and quality reliability.
Using the multi-directional feature aggregation (MFA) module and codec model, the spline tool is used to simulate hair defects on the training set, generate a pseudo-hair training set, iteratively shift and aggregate the feature map, input the decoder, combine reconstruction and The comparison loss function adjusts the model parameters to achieve hair defect detection.
It improves the accuracy and robustness of medical syringe hair defect detection, enables high-precision defect classification and positioning without relying on manual annotation, and improves the reliability of medical device production and quality inspection.
Smart Images

Figure CN118470026B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of defect detection, and in particular to a method and device for detecting hair defects of a syringe. Background Art
[0002] In the manufacturing process of medical syringes, defects are inevitable, and hair defects are one of them. The presence of hair in medical syringes is a serious problem. This defect may cause grease and bacteria to exist in the syringe, which seriously endangers the health of the user. Therefore, detecting and preventing hair defects has become a vital task.
[0003] Manufacturers usually use machine vision defect detection methods to check product defects. Current machine vision defect detection methods usually use defect detection models based on encoder network structures. However, the existing defect detection models based on encoder-decoder network structures have the problem of being unable to prevent abnormal feature information from flowing into the decoder. That is, after the encoder encodes the input data, the abnormal feature information in the data will also be encoded and passed to the decoder. This problem will cause the output of the decoder to also contain abnormal feature information, making it difficult to distinguish the difference between normal data and abnormal data, and thus unable to effectively mark the abnormal area with hair in the image of the syringe to be detected.
[0004] Therefore, there is an urgent need for a syringe hair defect detection method with strong feature learning ability, strong anti-interference ability and strong robustness, which can improve the accuracy of medical syringe hair defect detection and thus improve the reliability of medical device production and quality inspection. Summary of the invention
[0005] The present application provides a method and device for detecting hair defects in syringes, which can effectively improve the accuracy of hair defect detection in medical syringes, thereby improving the reliability of medical device production and quality inspection.
[0006] In order to achieve the above objectives, in a first aspect, the present application provides a method for detecting hair defects in a syringe, comprising the following steps:
[0007] S1. Using the spline curve tool, simulate hair defects on the syringe sample images in the training set to generate a pseudo-hair training set;
[0008] S2. A multi-directional feature aggregation MFA module and a codec model are used to construct a syringe hair defect detection model. The MFA module is used to receive a feature map output by the encoder, iteratively perform shift operations, enhancement and aggregation on the feature map, and then input the feature map into a decoder.
[0009] S3, training the syringe hair defect detection model using the training set and the pseudo-hair training set;
[0010] S4. Input the real-time syringe image into the trained syringe hair defect detection model, fuse the feature map output by the encoder and the feature map output by the decoder to obtain an abnormal score map, and determine the abnormal area corresponding to the hair defect in the real-time syringe image according to the abnormal score map.
[0011] In a possible implementation manner, step S2 includes:
[0012] Using the output of the encoder as the input of the MFA module, and using the output of the MFA module as the input of the decoder;
[0013] The MFA module uses a different step size to perform a shift operation each time iteratively. The MFA module includes L convolution blocks stacked sequentially, each convolution block includes a two-dimensional convolution unit, an instance normalization unit and an activation function, and L is a positive integer.
[0014] In a possible implementation manner, the step S2 further includes:
[0015] Performing multiple shift operations on the first multi-scale feature map output by the encoder through the MFA module to obtain a shifted feature map, where the shifted feature map includes pixel information of the first multi-scale feature map at different positions;
[0016] The MFA module performs a convolution block operation on the shifted feature map to obtain an enhanced shifted feature map, and the enhanced shifted feature map is added to the first multi-scale feature map to obtain a second multi-scale feature map for inputting into a decoder.
[0017] In a possible implementation manner, step S3 includes:
[0018] S31, inputting a pair of syringe sample images and pseudo-hair sample images corresponding to the training set and the pseudo-hair training set into the encoder respectively, and obtaining a first multi-scale feature map of the syringe sample image and the pseudo-hair image at multiple scales output by the encoder;
[0019] S32, inputting the first multi-scale feature map into the MFA module to obtain a second multi-scale feature map output by the MFA module;
[0020] S33, inputting the second multi-scale feature map into the decoder to obtain a target multi-scale feature map output by the decoder for the multiple scales, and adjusting the parameters of the injector hair defect detection model according to a reconstruction loss function and / or a contrast loss function between the target multi-scale feature map and the first multi-scale feature map;
[0021] S34. Iteratively execute steps S31 to S33 based on the training set and the pseudo-hair training set until the training stop condition is reached, and select a model that meets the preset conditions on the given verification set and the pseudo-hair verification set as the trained syringe hair defect detection model.
[0022] In a possible implementation manner, step S4 includes:
[0023] S41, inputting the real-time syringe image into the trained syringe hair defect detection model;
[0024] S42: If there is a difference between the first multi-scale feature map output by the encoder and the target multi-scale feature map output by the decoder, fuse the first multi-scale feature map with the target multi-scale feature map to obtain an anomaly score map;
[0025] S43. Determine an abnormal region corresponding to the hair defect in the real-time injector image according to the abnormal score map.
[0026] In a possible implementation manner, the step S1 includes:
[0027] S11, using an industrial camera to collect the syringe sample image, and dividing it into a verification set and the training set according to a preset ratio;
[0028] S12, using the spline curve tool to simulate hair defects on the syringe sample images in the training set to generate a pseudo hair training set;
[0029] S13. Using the spline curve tool, simulate hair defects on the syringe sample images in the verification set to generate a pseudo-hair verification set.
[0030] In a possible implementation manner, the spline curve tool is a B-spline, and the step S12 or the step S13 includes:
[0031] A. Generate a target spline curve using B-spline according to the pseudo-hair generation parameters, and convert the target spline curve into a two-dimensional array with the same size as the image;
[0032] B. Adding the two-dimensional array and the syringe sample image to obtain a pseudo hair image corresponding to the syringe sample image.
[0033] In one possible implementation, step A includes:
[0034] Determining pseudo-hair generation parameters according to the image size of the syringe sample image, wherein the pseudo-hair generation parameters include: the number of pseudo-hairs, the length of pseudo-hairs, the width of pseudo-hairs, and the number of control points;
[0035] Generate hair control points equal to the number of control points according to the number of pseudo hairs, the length of pseudo hairs, and the width of pseudo hairs;
[0036] An array having a length equal to the number of control points is used as a node vector, and a third-order B-spline curve is used to fit the node vector based on the hair control points to generate a target spline curve;
[0037] Create a two-dimensional array with the same size as the image and all elements are 0, and add the target spline curve to the two-dimensional array.
[0038] In a possible implementation, in the codec model: the backbone networks of the encoder and the decoder are both Wide ResNet50.
[0039] In a second aspect, a device for detecting hair defects of a syringe is provided. The device includes a plurality of functional modules for executing corresponding steps in the method for detecting hair defects of a syringe provided in the first aspect.
[0040] In a third aspect, a computing device is provided, the computing device comprising a memory and a processor, the memory storing at least one program, the at least one program being executed by the processor to implement the injector hair defect detection method provided in the first aspect.
[0041] In a fourth aspect, a computer-readable storage medium is provided, wherein at least one program is stored in the storage medium, and the at least one program is executed by a processor to implement the injector hair defect detection method provided in the first aspect.
[0042] In a fifth aspect, a computer program product is provided, comprising a computer program / instruction, wherein when the computer program / instruction is executed by a processor, the injector hair defect detection method provided in the first aspect is implemented.
[0043] The technical solution provided by this application includes at least the following technical effects: an unsupervised medical syringe hair defect detection method is implemented based on multi-directional feature aggregation, a medical syringe hair defect detection model is trained, and newly collected images are detected in real time based on the model, so that high-precision defect classification and defect location of medical syringes can be performed in real time. Based on this, high-precision medical needle tube hair defect detection can be achieved without relying on manual data annotation and manual defect detection, which plays an important role in the field of medical device production and quality inspection, and provides a reliable intelligent detection method for improving the quality and production efficiency of medical devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 This is a hardware implementation scenario of a syringe hair defect detection method provided in an embodiment of the present application;
[0045] Figure 2 It is a partial enlarged view of a syringe image at a top-down angle provided in an embodiment of the present application;
[0046] Figure 3 is a flow chart of a syringe defect detection method provided in an embodiment of the present application;
[0047] Figure 4 is a schematic diagram of a pseudo hair provided in an embodiment of the present application;
[0048] Figure 5 is a functional schematic diagram of an MFA module provided in an embodiment of the present application;
[0049] Figure 6 is a schematic diagram of an abnormal score map provided in an embodiment of the present application;
[0050] Figure 7 is a schematic diagram of a syringe hair defect detection method provided in an embodiment of the present application;
[0051] Figure 8 is a schematic diagram of a syringe defect detection device provided in an embodiment of the present application;
[0052] Fig. 9 It is a schematic diagram of the hardware structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] To further illustrate each embodiment, the present application provides drawings. These drawings are part of the disclosure of the present application, which are mainly used to illustrate the embodiments and can be used in conjunction with the relevant descriptions in the specification to explain the operating principles of the embodiments. With reference to these contents, a person of ordinary skill in the art should be able to understand other possible implementations and the advantages of the present application. The components in the figures are not drawn to scale, and similar component symbols are generally used to represent similar components. The term "at least one" in the present application means one or more, and the term "multiple" in the present application means two or more.
[0054] The present application is now further described in conjunction with the accompanying drawings and specific implementation methods.
[0055] First, the implementation scenario of the technical solution of this application is introduced.
[0056] The embodiment of the present application provides a hardware implementation scenario of a syringe hair defect detection method. Figure 1 is a stereoscopic diagram of a syringe hair defect detection scene provided by an embodiment of the present application, such as Figure 1As shown, part (a) shows the three-dimensional structure of collecting syringe images on the conveyor belt mechanism of the assembly line from a side view; part (b) shows the three-dimensional structure of collecting syringe images on the conveyor belt mechanism of the assembly line from a top view. Figure 2 This is a partially enlarged view of a syringe image from a top-down angle provided in an embodiment of the present application.
[0057] An embodiment of the present application provides a method for detecting hair defects in a syringe, which can be executed by any computing device. Figure 3 is a flow chart of a syringe defect detection method provided in an embodiment of the present application, such as Figure 3 As shown, the method includes the following steps S1 to S4.
[0058] S1. Use the spline curve tool to simulate hair defects on the syringe sample images in the training set to generate a pseudo-hair training set.
[0059] In a possible implementation, step S1 includes: the following steps S11 to S13.
[0060] S11. Use an industrial camera to collect syringe sample images and divide them into training set and validation set according to the preset ratio.
[0061] Exemplarily, the industrial camera is set on the conveyor mechanism of the syringe manufacturing line, and the industrial camera can be used to collect real medical syringe sample images. Based on the collected syringe sample images, a training set and a validation set can be divided for model training.
[0062] Optionally, the preset ratio is expressed as, for example: a ratio of the number of samples in the training set to that in the validation set is 9:1, the training set contains N medical syringe images, the validation set contains M medical syringe images, N and M are both positive integers, and N is greater than M.
[0063] Optionally, the resolution of the image collected by the industrial camera is preset, and a high resolution can be selected according to requirements. The resolution is, for example, expressed as H×W, where H is the height and W is the width.
[0064] S12. Using a spline curve tool, simulate hair defects on the syringe sample images in the training set to generate a pseudo-hair training set.
[0065] S13. Use the spline curve tool to simulate hair defects on the syringe sample images in the validation set to generate a pseudo-hair validation set.
[0066] Among them, spline tools are a type of mathematical tools used to generate and edit smooth curves and surfaces, which define the shape of the curve through control points and corresponding mathematical formulas. For example, B-spline can be used. B-spline curves have local controllability and continuous adjustability. Local controllability means that modifying a control point will only affect the local area of the curve, and continuous adjustability means that the continuity of the curve can be adjusted by selecting basis functions of different orders. Of course, other types of spline tools can also be used, such as Bezier curves.
[0067] In the example where the spline curve tool is B-spline, the principle of the above step S12 or step S13 can refer to the following steps A to B.
[0068] A. Generate the target spline curve using B-spline according to the pseudo-hair generation parameters, and convert the target spline curve into a two-dimensional array with the same size as the image;
[0069] A1. Determine pseudo-hair generation parameters according to the image size of the syringe sample image. The pseudo-hair generation parameters include: pseudo-hair quantity, pseudo-hair length, pseudo-hair width, and control point quantity.
[0070] Exemplarily, the image size includes the image height and the image width. In this step A1, the initialization parameters are first obtained: the height and width (height, width) of the image in the training set are obtained, and the required number of pseudo hairs (num_hairs), pseudo hair length (hair_length), pseudo hair width (hair_width) and number of control points (num_points) are determined according to the image height and image width.
[0071] A2. Generate hair control points of the control point quantity according to the pseudo-hair quantity, pseudo-hair length, and pseudo-hair width.
[0072] In a possible implementation, firstly, the root coordinates (x_root, y_root) of the hair are generated according to the image height and image width (height, width); starting from the horizontal coordinate (x_root) of the root coordinate, the number of control points (num_points) of hair horizontal coordinates are generated according to the preset spacing; starting from the vertical coordinate (y_root) of the root coordinate according to the pseudo hair length (hair_length), the number of control points (num_points) of hair vertical coordinates are generated randomly within the pseudo hair width (hair_width). Each hair horizontal coordinate and the corresponding hair vertical coordinate constitute a hair coordinate point. The total length of multiple hair coordinate points is the pseudo hair length (hair_length).
[0073] Optionally, random noise can be added to the hair coordinate points of the control points. Specifically, a normal distribution random noise with a standard deviation is added to the generated hair ordinate y, thereby increasing the randomness of the y coordinate, making the hair lines more natural and the authenticity of the generated hair.
[0074] A3. Using an array with a length equal to the number of control points as a node vector, a third-order B-spline curve is used to fit the node vector based on the hair control points to generate a target spline curve.
[0075] For example, an array with a length equal to the number of control points (num_points) is created and used as the node vector in the B-spline curve. The node vector defines the position of the point on the curve in the parameter space. Based on this, according to the hair control points generated in A2 and the node vector, a third-order B-spline curve is used to fit the node vector to generate a B-spline curve.
[0076] A4. Create a two-dimensional array with the same size as the image and all elements are 0, and add the target spline curve to the two-dimensional array.
[0077] Specifically, a two-dimensional array with a height and a width of height and width respectively is created, and all elements are zero; then the B-spline curve generated in the correction A3 is added to the two-dimensional array to obtain a new two-dimensional array (denoted as noise_array).
[0078] B. Add the two-dimensional array and the syringe sample image to obtain a pseudo-hair image corresponding to the syringe sample image.
[0079] Specifically, the pseudo hair image can be obtained by adding the noise_array obtained in the above step A4 and the original syringe sample image in the training set.
[0080] Figure 4 is a schematic diagram of a pseudo hair provided in an embodiment of the present application, Figure 4 Part (a) is a schematic diagram of the syringe structure without added hair, and part (b) is a schematic diagram of the syringe structure with added pseudo hair.
[0081] S2. A multi-directional feature aggregation (MFA) module and encoder-decoder model are used to build a syringe hair defect detection model. The MFA module is used to receive the feature map output by the encoder, iteratively perform shift operations, enhancement and aggregation on the feature map, and then input it into the decoder.
[0082] In the embodiment of the present application, the MFA module can be used to extract features at multiple scales. For example, different Gaussian blur kernels or image pyramids can be used to generate multi-scale image representations.
[0083] Exemplarily, at each scale, features can be extracted using traditional image processing techniques (such as edge detection, texture analysis, etc.) or deep learning models (such as convolutional neural networks). Optionally, spatial location information (such as using sliding windows or region proposal networks) can be combined during feature extraction to locate the specific location of the defect. The MFA module aggregates features extracted from multiple scales to understand and identify defects at a higher level. This can be achieved through feature fusion techniques such as splicing, weighted summation, or attention mechanisms.
[0084] Through multi-scale feature extraction, defect information at different scales can be captured to improve the accuracy of detection. Since information at multiple scales is taken into account, the system is more robust to factors such as noise and lighting changes.
[0085] In one possible implementation, the codec model is composed of an encoder and a decoder. Optionally, the backbone networks of the encoder and the decoder are both Wide ResNet50.
[0086] In one possible implementation, step S2 includes: using the output of the encoder as the input of the MFA module, and using the output of the MFA module as the input of the decoder. In any iteration of the MFA module: the MFA module performs multiple shift operations on the first multi-scale feature map output by the encoder to obtain a shifted feature map, and the shifted feature map includes pixel information of the first multi-scale feature map at different positions; the MFA module performs a convolution block operation on the shifted feature map to obtain an enhanced shifted feature map, and after adding the enhanced shifted feature map to the first multi-scale feature map, a second multi-scale feature map for inputting the decoder is obtained.
[0087] Specifically, the MFA module is used to receive the output of the encoder. The MFA module includes multiple layers of several iterations, and each iteration performs a shift operation on the first multi-scale feature map output by the encoder in the order from bottom to top, from top to bottom, from right to left and then from left to right to obtain pixel information at different positions of the feature map, thereby obtaining a shifted feature map. Optionally, the MFA module uses different step sizes for each iteration of the shift operation, so that the shifted feature map can fully obtain pixel information at different positions.
[0088] Specifically, the shifted feature map is subjected to a convolution block operation to obtain an enhanced shifted feature map, and the enhanced shifted feature map is added to the first multi-scale feature map to obtain a second multi-scale feature map.
[0089] Optionally, the MFA module includes L convolution blocks stacked sequentially, each convolution block includes a two-dimensional convolution unit (Conv2D), an instance normalization unit (InstanceNorm) and an activation function (LeakyReLU), and L is a positive integer.
[0090] In the embodiment of the present application, the MFA module is used to implement iterative learning of multi-scale features to guide the codec model to learn how to extract and identify data features at different scales. Exemplarily, different scales refer to different image resolutions or image sizes (height × width).
[0091] In one possible implementation, several fixed scales are predefined, and multiple scales are randomly selected for training in each training cycle (epoch). In the defect detection task of the embodiment of the present application, the syringe hair defect detection model performs feature extraction and prediction on feature maps of multiple scales. Exemplarily, the extraction of multi-scale features can be achieved by using convolution kernels or pooling layers of different sizes.
[0092] This application uses the MFA module to train and optimize the model on data of different scales, which can improve the adaptability and generalization performance of the model. In practical applications, the appropriate scale can be selected for training according to the specific requirements of the task and the characteristics of the data, and this application does not limit this.
[0093] Figure 5 is a functional schematic diagram of an MFA module provided in an embodiment of the present application, such as Figure 5 As shown, during the first iteration of the input feature map, the MFA module performs shift operations from bottom to top, from top to bottom, from right to left, and from left to right with a step size of 1; during the second iteration, multiple shift operations are performed in a step size of 2; and so on. After k iterations are performed, the output feature map is obtained, where k is a positive integer greater than 1.
[0094] Optionally, the codec model used may use model parameters obtained by pre-training. Optionally, the pre-trained model parameters may be obtained by training based on image datasets such as ImageNet.
[0095] The embodiment of the present application uses MFA to implement repeated execution of the above-mentioned feature aggregation process several times, so that each pixel of the obtained feature map can obtain the global encoding information of the input data, thereby strengthening the normal feature information of the input data and weakening its abnormal feature information, thereby achieving the purpose of preventing the abnormal feature information from flowing into the decoder.
[0096] S3. Use the training set and the pseudo-hair training set to train the syringe hair defect detection model.
[0097] In a possible implementation manner, this step S3 includes the following steps S31 to S34.
[0098] S31. Input a pair of syringe sample images and pseudo-hair sample images corresponding to the training set and the pseudo-hair training set into the encoder respectively, and obtain a first multi-scale feature map of the syringe sample image and the pseudo-hair image at multiple scales output by the encoder.
[0099] Specifically, after pseudo hair is added to the syringe sample image in the training set, a corresponding pseudo hair sample image in the pseudo hair training set is obtained. The syringe sample image in the training set and its corresponding pseudo hair sample image in the pseudo hair training set are respectively input into the encoder, and the outputs of the two at multiple scales are respectively used as the first multi-scale feature map.
[0100] Taking three scales as an example, the multi-scale output of a pair of sample images input after being processed by the encoder is recorded as:
[0101] and ;in, is the feature map corresponding to the syringe sample image at scales 1-3 in the first multi-scale feature map, where 1-3 are used as marks to distinguish different scales; It is the feature map corresponding to the pseudo hair sample image at scales 1-3 in the first multi-scale feature map.
[0102] In an embodiment of the present application, the encoder gradually extracts and summarizes the features of the input image through multiple layers (such as the convolutional layers of a convolutional neural network) to convert the input image into a low-dimensional or abstract representation. Optionally, the encoder includes an attention mechanism to focus on specific areas or features in the input image during the encoding process.
[0103] The encoder can capture the key information in the input image and map it to a representation space of smaller dimensionality to achieve feature extraction.
[0104] S32: Input the first multi-scale feature map into the MFA module to obtain a second multi-scale feature map output by the MFA module.
[0105] Specifically, the first multi-scale feature map and They are respectively input into the MFA module, and after iterative processing of the MFA module, a second multi-scale output of the MFA module is obtained.
[0106] Exemplarily, taking three scales as an example, the second multi-scale feature map is recorded as:
[0107] ;
[0108] in, It is the feature map corresponding to the syringe sample image at scales 1-3 in the second multi-scale feature map, where 1-3 are used as marks to distinguish different scales. Indicates the MFA module; It is the feature map corresponding to the pseudo hair sample image at scales 1-3 in the second multi-scale feature map.
[0109] S33. Input the second multi-scale feature map into the decoder to obtain a target multi-scale feature map output by the decoder for multiple scales, and adjust the parameters of the injector hair defect detection model according to a reconstruction loss function and / or a contrast loss function between the target multi-scale feature map and the first multi-scale feature map.
[0110] Specifically, the second multi-scale feature map output by the MFA module is input into the decoder, and the target multi-scale feature map is recovered from the image encoding. Exemplarily, Represents the second multi-scale feature map input to the decoder for the decoder to learn the medical syringe hair features.
[0111] Taking three scales as an example, the target multi-scale feature maps output by the decoder for the three scales are recorded as: ; Numbers 1-3 indicate three different scales.
[0112] This application uses a decoder to recover data of the original or target domain (e.g., multi-scale feature maps processed by the MFA module) from the output of the encoder.
[0113] Optionally, the decoder is usually composed of multiple layers, which gradually generate higher-level representations based on the output of the encoder. The multiple layers include, for example, upsampling layers (such as transposed convolutional layers) for restoring the spatial resolution of the image; further, skip connections can be used to fuse features of different scales to obtain more refined segmentation results.
[0114] The decoder is used to map the semantic information of images of different scales to the image pixel space, and dense classification of the image is achieved pixel by pixel, thereby completing the division of different targets and the detection of defects.
[0115] In one possible implementation, the reconstruction loss function and the contrast loss function may be calculated based on the cosine similarity distance between the target multi-scale feature map and the first multi-scale feature map. The reconstruction loss function uses the second multi-scale feature map output by the MFA module of the training set and the pseudo-hair training set. and The contrast loss function is determined by the anomaly score between the first multi-scale feature map obtained by the training set input encoder and the target multi-scale feature map obtained by the training set input encoder, MAFA module and decoder. For details, please refer to the following formulas (1)-(2).
[0116] (1)
[0117] (2)
[0118] In formula (1)-(2), L Recon represents the reconstruction loss function, L Cons Represents the contrast loss function; cos represents the calculation of the cosine similarity distance between two feature maps, H and W represent the height and width of the feature map respectively; I Indicates the number of MFA module outputs. and It is the second multi-scale feature map at the i-th scale (refer to the introduction of the second multi-scale feature map in the previous article). Represents the difference between the first multi-scale feature map (encoder output) and the target multi-scale feature map (decoder output) at scale i. The larger the difference, the The smaller, 0<= M i (h,w) <=1. and Represents the first multi-scale feature map at the i-th scale (refer to the introduction of the first multi-scale feature map in the previous article).
[0119] S34. Iteratively execute steps S31 to S33 based on the training set and the pseudo-hair training set until the training stop condition is reached, and select the model that meets the preset conditions on the given verification set and the pseudo-hair verification set as the trained syringe hair defect detection model.
[0120] Exemplarily, the given verification set and pseudo-hair verification are obtained by the method introduced in step S13.
[0121] Optionally, the training stop condition is, for example, that the number of iterations reaches a preset number, or that the loss value has converged to a target value. The loss value is composed of a reconstruction loss function value and a comparison loss function value.
[0122] Optionally, the preset condition refers to the best performance, and the performance includes, for example, any one or a combination of the fastest calculation speed, the highest detection accuracy, and the most accurate marking of abnormal areas.
[0123] S4. Input the real-time syringe image into the trained syringe hair defect detection model, fuse the feature map output by the encoder and the feature map output by the decoder to obtain an abnormal score map, and determine the abnormal area corresponding to the hair defect in the real-time syringe image according to the abnormal score map.
[0124] In the embodiment of the present application, the anomaly score map is used to indicate the degree of difference between the encoder output feature map and the decoder output feature map. The similarity of the corresponding areas of the two feature maps is measured. The greater the difference, the higher the anomaly score.
[0125] In a possible implementation manner, this step S4 includes the following steps S41 to S43.
[0126] S41, inputting the real-time syringe image into the trained syringe hair defect detection model.
[0127] Specifically, the syringe image is input into the encoder of the trained syringe hair defect detection model.
[0128] S42: If there is a difference between the first multi-scale feature map output by the encoder and the target multi-scale feature map output by the decoder, the first multi-scale feature map and the target multi-scale feature map are fused to obtain an anomaly score map.
[0129] Exemplarily, the encoder outputs the first multi-scale feature map, and the decoder outputs the target multi-scale feature map. For scale i, the first multi-scale feature map and the target multi-scale feature map are divided into multiple regions, and the cosine value between the image feature vectors of the corresponding regions of the two is calculated. The smaller the cosine value, the larger the angle, the larger the gap, and therefore the higher the anomaly score.
[0130] Figure 6 is a schematic diagram of an abnormal score map provided in an embodiment of the present application, such as Figure 6 As shown, the feature map of a single scale extracted by the encoder is recorded as (x1, y1), and the feature map output by the decoder at the corresponding scale is recorded as (x2, y2); the angle between the corresponding areas (x1, y1) and (x2, y2) of the feature map is calculated The cosine value of , we can get the anomaly score map. The anomaly score of each region is recorded as M(x, y) = 1- .
[0131] Optionally, the following formula (3) is used to calculate the anomaly score map at scale i.
[0132] (3)
[0133] In formula (3) Represents the difference between the first multi-scale feature map (encoder output) and the target multi-scale feature map (decoder output) at scale i. The larger the difference, the The smaller, 0<= M i (h,w) <= 1. cos means calculating the cosine similarity distance between the corresponding feature vectors of two feature maps. and represents the first multi-scale feature map at the i-th scale (refer to the introduction of the first multi-scale feature map in the previous article); and Represents the target multi-scale feature map at the i-th scale (refer to the introduction of the target multi-scale feature map in the previous article).
[0134] S43. Determine the abnormal area corresponding to the hair defect in the real-time syringe image according to the abnormal score map.
[0135] Based on this, the area corresponding to the relatively larger value in the abnormal score map indicates the abnormal area blocked by hair. The larger value is, for example, a score that exceeds the average value / three times the standard deviation in the abnormal score map, or a score that is ranked in the top X positions in descending order.
[0136] Alternatively, real-time syringe images can be acquired in real time using a conveyor mechanism and an industrial camera.
[0137] In an embodiment of the present application, if the input data of the syringe hair defect detection model is defective, there will be differences in the multi-scale feature maps output by its encoder and its corresponding decoder. By fusing the paired multi-scale feature maps of these encoders and decoders, an abnormal score map can be obtained, and the abnormal area corresponding to the hair defect in the syringe can be effectively marked based on the map.
[0138] Figure 7 is a schematic diagram of a syringe hair defect detection method provided in an embodiment of the present application, such as Figure 7 As shown, the syringe hair defect detection method provided in the present application includes a model training process and an actual detection process.
[0139] like Figure 7As shown in FIG. 1 , the model training process includes: collecting medical syringe image data through a conveyor mechanism and an industrial camera to construct a training set and a validation set; using B-spline to add pseudo hair to construct a pseudo hair training set; the training set and the validation set are used to input the encoder for model training, and the pre-trained model parameters used by the encoder are obtained based on the ImageNet image data set training; the first multi-scale feature map output by the encoder is input into the MFA module for iteration, and the second multi-scale feature map is output; after the second multi-scale feature map is input into the decoder, the decoder outputs the target multi-scale feature map; during the training process, the second multi-scale feature map ( and ) to determine the reconstruction loss; the contrast loss is determined based on the anomaly score between the first multi-scale feature map obtained by the training set input encoder and the target multi-scale feature map obtained by the training set input encoder, MAFA module and decoder. Finally, the model parameters corresponding to the trained model are saved, output as a pth file and deployed as a syringe hair defect detection model for actual use.
[0140] like Figure 7 As shown, the actual detection process includes: inputting the syringe image data collected in real time by the conveyor belt mechanism and the industrial camera into the encoder, inputting the first multi-scale feature map output by the encoder into the MFA module, and inputting the second multi-scale feature map output by the MFA module into the decoder to obtain the target multi-scale feature map; by fusing the first multi-scale feature map and the target multi-scale feature map, an abnormal score map can be obtained, and the abnormal area with hair defects can be marked according to the abnormal feature map.
[0141] This application implements an unsupervised medical syringe hair defect detection method based on multi-directional feature aggregation, trains a medical syringe hair defect detection model, and uses the model as a basis to detect newly acquired images in real time, which can perform high-precision defect classification and defect location on medical syringes in real time. Based on this, high-precision medical needle hair defect detection can be achieved without relying on manual data annotation and manual defect detection, which plays an important role in the field of medical device production and quality inspection, and provides a reliable intelligent detection method for improving the quality and production efficiency of medical devices.
[0142] The present application also provides a schematic diagram of a syringe hair defect detection device, referring to Figure 8 , the device comprises:
[0143] A model training module is used to use a spline curve tool to simulate hair defects on a syringe sample image in a training set to generate a pseudo-hair training set; a multi-directional feature aggregation MFA module and a codec model are used to construct a syringe hair defect detection model, wherein the MFA module is used to receive a feature map output by an encoder, iteratively perform shift operations, enhancement and aggregation on the feature map, and then input the feature map into a decoder; the syringe hair defect detection model is trained using the training set and the pseudo-hair training set;
[0144] The defect detection module is used to input the real-time syringe image into the trained syringe hair defect detection model, fuse the feature map output by the encoder and the feature map output by the decoder to obtain an abnormal score map, and determine the abnormal area corresponding to the hair defect in the real-time syringe image according to the abnormal score map.
[0145] It should be noted that, when implementing the corresponding steps, the syringe hair defect detection device provided in the above embodiment is only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the syringe hair defect detection device provided in the above embodiment and the above syringe hair defect detection method belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0146] The present application provides a computing device for executing the above-mentioned syringe hair defect detection method. Fig. 9 is a schematic diagram of the hardware structure of a computing device provided in an embodiment of the present application, such as Fig. 9 As shown, the computing device includes a processor 901, a memory 902, a bus 903, and a computer program stored in the memory 902 and executable on the processor 901. The processor 901 includes one or more processing cores. The memory 902 is connected to the processor 901 via the bus 903. The memory 902 is used to store program instructions. When the processor executes the computer program, all or part of the steps in the above method embodiments provided in the present application are implemented.
[0147] Further, as an executable solution, the computing device may be a computer unit, which may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer unit may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the composition structure of the computer unit is merely an example of a computer unit and does not constitute a limitation on the computer unit, and may include more or fewer components than the above, or a combination of certain components, or different components. For example, the computer unit may also include input and output devices, network access devices, buses, etc., which are not limited in the embodiments of the present application.
[0148] Further, as an executable solution, the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the computer unit, and various interfaces and lines are used to connect various parts of the entire computer unit.
[0149] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the computer unit by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system and at least one application required for a function; the data storage area can store data created according to the use of the mobile phone, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0150] The present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, all or part of the steps of the above method in the embodiment of the present application are implemented.
[0151] The present application also provides a computer program product, including a computer program / instruction, which implements all or part of the steps of the above-mentioned method in the embodiment of the present application when the computer program / instruction is executed by a processor.
[0152] If the module / unit integrated in the above-mentioned computing unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. 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-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory) and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction.
[0153] Although the present application has been specifically shown and described in conjunction with the preferred embodiments, those skilled in the art should understand that various changes may be made to the present application in form and details without departing from the spirit and scope of the present application as defined by the appended claims, all of which are within the scope of protection of the present application.
Claims
1. A method for detecting hair defects in a syringe, characterized in that: The following steps are involved: S1. Using a spline curve tool, simulate hair defects on the syringe sample images in the training set to generate a pseudo-hair training set, and simulate hair defects on the syringe sample images in the verification set to generate a pseudo-hair verification set; S2, using the output of the encoder in the codec model as the input of the multi-directional feature aggregation MFA module, and using the output of the MFA module as the input of the decoder in the codec model to construct a syringe hair defect detection model; The codec model is composed of the decoder and the encoder, the MFA module is used to receive the feature map output by the encoder, iteratively perform shift operations, enhancement and aggregation on the feature map, and then input it into the decoder; the MFA module uses different step sizes for each iteration of the shift operation, and the MFA module includes L convolution blocks stacked in sequence, each convolution block includes a two-dimensional convolution unit, an instance normalization unit and an activation function, and L is a positive integer; S31, inputting a pair of syringe sample images and pseudo-hair sample images corresponding to the training set and the pseudo-hair training set into the encoder respectively, and obtaining a first multi-scale feature map of the syringe sample image and the pseudo-hair image at multiple scales output by the encoder; S32, inputting the first multi-scale feature map into the MFA module to obtain a second multi-scale feature map output by the MFA module; S33, inputting the second multi-scale feature map into the decoder to obtain a target multi-scale feature map output by the decoder for the multiple scales, and adjusting the parameters of the injector hair defect detection model according to a reconstruction loss function and / or a contrast loss function between the target multi-scale feature map and the first multi-scale feature map; S34, iteratively executing steps S31 to S33 based on the training set and the pseudo-hair training set until a training stop condition is reached, and selecting a model that meets the preset conditions on a given verification set and the pseudo-hair verification set as a trained syringe hair defect detection model; S41, inputting the real-time syringe image into the syringe hair defect detection model obtained by training; S42: If there is a difference between the first multi-scale feature map output by the encoder and the target multi-scale feature map output by the decoder, fuse the first multi-scale feature map with the target multi-scale feature map to obtain an anomaly score map; S43. Determine an abnormal region corresponding to the hair defect in the real-time injector image according to the abnormal score map.
2. The syringe hair defect detection method according to claim 1, characterized in that: Step S2 also includes: Performing multiple shift operations on the first multi-scale feature map output by the encoder through the MFA module to obtain a shifted feature map, where the shifted feature map includes pixel information of the first multi-scale feature map at different positions; The MFA module performs a convolution block operation on the shifted feature map to obtain an enhanced shifted feature map, and the enhanced shifted feature map is added to the first multi-scale feature map to obtain a second multi-scale feature map for inputting into a decoder.
3. The syringe hair defect detection method according to claim 1, characterized in that: Step S1 includes: S11, using an industrial camera to collect the syringe sample image, and dividing it into a verification set and the training set according to a preset ratio; S12, using the spline curve tool to simulate hair defects on the syringe sample images in the training set to generate a pseudo hair training set; S13. Using the spline curve tool, simulate hair defects on the syringe sample images in the verification set to generate a pseudo-hair verification set.
4. The method for detecting hair defects in a syringe according to claim 3, characterized in that: The spline curve tool is B-spline, and step S12 or step S13 includes: A. generating a target spline curve using B-spline according to the pseudo-hair generation parameters, and converting the target spline curve into a two-dimensional array having the same image size as the syringe sample image; B. Adding the two-dimensional array and the syringe sample image to obtain a pseudo hair image corresponding to the syringe sample image.
5. The syringe hair defect detection method according to claim 4, characterized in that: Step A includes: Determining pseudo-hair generation parameters according to the image size of the syringe sample image, wherein the pseudo-hair generation parameters include: the number of pseudo-hairs, the length of pseudo-hairs, the width of pseudo-hairs, and the number of control points; Generate hair control points equal to the number of control points according to the number of pseudo hairs, the length of pseudo hairs, and the width of pseudo hairs; An array having a length equal to the number of control points is used as a node vector, and a third-order B-spline curve is used to fit the node vector based on the hair control points to generate a target spline curve; Create a two-dimensional array with the same size as the image and all elements are 0, and add the target spline curve to the two-dimensional array.
6. The method for detecting hair defects in a syringe according to claim 1, characterized in that: In the codec model: the backbone networks of the encoder and the decoder are both Wide ResNet50.
7. A syringe hair defect detection device, characterized in that: include: A model training module, used to use a spline curve tool to simulate hair defects on syringe sample images in a training set to generate a pseudo-hair training set, and simulate hair defects on syringe sample images in a verification set to generate a pseudo-hair verification set; using the output of the encoder in the codec model as the input of the multi-directional feature aggregation MFA module, and using the output of the MFA module as the input of the decoder in the codec model to construct a syringe hair defect detection model; The codec model is composed of the decoder and the encoder, the MFA module is used to receive the feature map output by the encoder, iteratively perform shift operation, enhancement and aggregation on the feature map, and then input it into the decoder; the syringe hair defect detection model is trained using the training set and the pseudo-hair training set; the MFA module performs the shift operation with different step sizes each time, and the MFA module includes L convolution blocks stacked in sequence, each convolution block includes a two-dimensional convolution unit, an instance normalization unit and an activation function, and L is a positive integer; A defect detection module, used to input a pair of syringe sample images and pseudo-hair sample images corresponding to the training set and the pseudo-hair training set into the encoder, respectively, to obtain a first multi-scale feature map of the syringe sample image and the pseudo-hair image output by the encoder at multiple scales; input the first multi-scale feature map into the MFA module to obtain a second multi-scale feature map output by the MFA module; input the second multi-scale feature map into the decoder to obtain a target multi-scale feature map output by the decoder for the multiple scales, and adjust the parameters of the syringe hair defect detection model according to a reconstruction loss function and / or a contrast loss function between the target multi-scale feature map and the first multi-scale feature map; iteratively execute steps S31 to S33 based on the training set and the pseudo-hair training set until a training stop condition is reached, and select a model that meets the preset conditions on a given verification set and the pseudo-hair verification set as the trained syringe hair defect detection model; The defect detection module is further used to input the real-time syringe image into the trained syringe hair defect detection model; if there is a difference between the first multi-scale feature map output by the encoder and the target multi-scale feature map output by the decoder, the first multi-scale feature map and the target multi-scale feature map are fused to obtain an abnormal score map; according to the abnormal score map, the abnormal area corresponding to the hair defect in the real-time syringe image is determined.
Citation Information
Patent Citations
Workpiece defect detection method and device fusing multi-attention mechanism
CN113822885A
Injector defect detection method based on improved Faster-RCNN
CN116739959A
Image recognition method, apparatus, device, and computer storage medium
US20210209343A1
Defect detecting apparatus and method
US20230394651A1
