Yolov8 network-based vector drug package detection method and system
By using vector detection methods based on yolov8 network in drug packaging detection, through data enhancement and attention mechanisms, the problem of poor generalization ability of traditional detection methods is solved, and higher detection accuracy and automation are achieved.
Patent Information
- Application Number
- CN202411197206.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2024-12-06
AI Technical Summary
Traditional industrial camera detection methods have poor generalization ability when detecting drug packaging, making it difficult to quickly and accurately detect various drug packaging in complex application scenarios, resulting in the inability to achieve fully automated testing.
A vector drug packaging detection method based on the yolov8 network is adopted to build a network model with attention mechanism through data enhancement and addition of attention mechanisms to improve the detection accuracy of the model. The specific steps include HSV color enhancement, random rotation, random affine enhancement, and random mosaic enhancement on the sample image, building backbone, neck, and head structure modules, and adding channels and spatial attention layers to the C2F module, optimizing the model through loss function .
It improves the generalization of the detection algorithm and the readability of the image, and can more accurately detect objects at any angle, significantly improving the accuracy and automation of drug packaging detection.
Smart Images

Figure BDA0005016802300000041 
Figure BDA0005016802300000051 
Figure BDA0005016802300000052
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of target detection, and in particular relates to a method for accurately monitoring drug packaging based on deep learning. Background Art
[0002] Pharmaceutical packaging comes in various shapes, such as medicine bottles, medicine bags, and medicine boxes. Their geometric features and representation information vary greatly. Traditional industrial camera detection methods use image processing technology, including image binarization, threshold segmentation, and morphological segmentation, to obtain image detection results. These technologies rely on manual experience for design and can only be applied to specific situations. They have poor generalization capabilities and are difficult to quickly and accurately detect various pharmaceutical packaging in actual complex application scenarios, resulting in the need to spend additional manpower and material resources to handle undetectable packaging, and unable to meet the needs of fully automated detection. Summary of the invention
[0003] In view of the above-mentioned shortcomings of the current manual inspection of drug packaging, the present invention provides a method for accurate drug packaging inspection based on deep learning. By expanding the diversity of data samples and adding an attention mechanism, the model has a stronger learning generalization ability, thereby improving the detection accuracy of the model.
[0004] To achieve the above object, the embodiments of the present invention adopt the following technical solutions:
[0005] A vector drug packaging detection method based on yolov8 network, the vector drug packaging detection method based on yolov8 network, specifically comprising:
[0006] Performing data enhancement on the obtained sample image to obtain an enhanced image;
[0007] Build a network model with attention mechanism based on yolov8 network;
[0008] The network model is trained based on the enhanced image to obtain a detection model;
[0009] Input the target image into the detection model to obtain the detection result.
[0010] According to one aspect of the present invention, the data enhancement of the obtained sample image to obtain the enhanced image specifically includes: performing HSV color enhancement, random rotation enhancement, random affine enhancement, and random mosaic enhancement operations on the sample image to obtain a variety of enhanced images.
[0011] According to one aspect of the present invention, the network model with attention mechanism based on yolov8 network includes backbone structure module, neck structure module and head structure module, and each module is connected in sequence into a trainable network model.
[0012] According to one aspect of the present invention, the backbone structure includes a C2F module, the C2F module includes three output channels, and is connected to the neck structure; a channel attention layer and a spatial attention layer are added before the concate layer in the C2F module.
[0013] According to one aspect of the present invention, the neck structure includes three input channels, and the feature fusion between the channels adopts the Wconcate weighted feature concatenation method.
[0014] According to one aspect of the present invention, the Wconcate weighted feature concatenation method is implemented using the following formula:
[0015] f wc =W{C(f1,f2)}, where f1,f2 are feature maps from the upper layer entering the concatenation module, wc is the enhanced feature map, C is the equivalent function of the concate module, and is the weighted function generated by self-learning.
[0016] According to one aspect of the present invention, the head structure includes two output channels: a classification output channel and a detection output channel; the classification output channel outputs the category of the target object; the detection output channel outputs the bounding box of the target object, and the bounding box has directionality.
[0017] According to one aspect of the present invention, a network model is trained based on an enhanced image to obtain a detection model, specifically including using the enhanced image as the input of the network model, evaluating the prediction ability of the network model through a loss function, iterating multiple times until the loss function no longer decreases and the model reaches an optimal state, and saving the optimal detection model.
[0018] According to one aspect of the present invention, the target image is input into the detection model to obtain the detection result, specifically, after the target image is input into the optimal detection model obtained above, the detection task is executed to obtain the detection result of the target image, that is, the classification of the target drug and the detection frame of the target drug.
[0019] A vector medicine packaging detection system based on yolov8 network, the vector medicine packaging detection system based on yolov8 network comprises:
[0020] An image data processing module, used for enhancing the drug packaging image data to obtain an enhanced image;
[0021] Build a model module to build a network model with attention mechanism;
[0022] A training module, used to enhance the image pair network model training to obtain a detection model;
[0023] The testing module is used to input the test image into the detection model and output the detection result of the model.
[0024] The advantages of the implementation of the present invention are as follows: (1) a variety of image enhancement techniques are used to enhance the training data, thereby improving the generalization of the algorithm and the readability of the image; (2) by decoupling the detection head in the network model and independently optimizing the classification and regression convolutional layers, objects at any angle can be detected more accurately; (3) by adding an attention processing mechanism to the C2F unit of the model, the accuracy of detection is further improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below.
[0026] Figure 1 This is a flow chart of a detection method based on deep learning in Example 1;
[0027] Figure 2 This is a complete flowchart of the deep learning-based detection method in Example 2;
[0028] Figure 3 This is the structural diagram of the C2F-A module. DETAILED DESCRIPTION
[0029] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0030] Embodiment 1
[0031] The dataset used in this example is 16,848 images of drug packaging, which are divided into 7 packaging types to form a fully annotated CPPD dataset. The dataset for model performance evaluation is divided into a training set and a test set; the training set contains 16,848 images, and the test set is a zero-sample test data set containing 100,000 test images.
[0032] The experimental hardware is RTX3060 GPU, and TensorBoard is used to monitor the training process in the python3 environment.
[0033] like Figure 1As shown, a vector drug packaging visual precision detection method based on yolov8, the specific steps are as follows:
[0034] Step S01: performing data enhancement on the obtained sample image to obtain an enhanced image; the data enhancement on the obtained training data to obtain an enhanced image specifically includes: performing HSV color enhancement, random rotation enhancement, random affine enhancement, and random mosaic enhancement operations on the training data to obtain a variety of enhanced images.
[0035] The obtained training data set is CPPD data collected about the outer packaging of medicines, and multiple enhancement methods are used, including HSV color enhancement, random rotation enhancement, random affine enhancement, random mosaic enhancement and other image data enhancement methods to expand the diversity of data samples.
[0036] The principle of HSV color enhancement: by adding disturbances to the three channels of h, s, and v in the HSV color space, the hue is transformed to achieve the purpose of data enhancement. The specific color conversion relationship is:
[0037]
[0038] Randomly adjust the brightness by calling the RandomAdjustBrightness() function in the transforms package.
[0039] For example: Transforms.RandomAdjustBrightness() function: RandomAdjustBrightness(0.3).
[0040] Call the RandomRotation() function in the transforms package to perform random rotation. For example: Transforms.RandomRotation() function: RandomRotation(degrees, resample = False, expand = False, center = None).
[0041] Call the RandomAffine() function in the transforms package to perform random affine. For example: Transforms.RandomAffine() function:
[0042] RandomAffine(degrees,translate=None,scale=None,shear=None,interpolation=<InterpolationMode.NEAREST:’nearest’> , fill=0, fillcolor=None, resample=None, center=None).
[0043] Random mosaic enhancement is to randomly select several images and combine them into several new images. The number of combined images is greater than the original number.
[0044] Through multiple data enhancement methods, the brightness and shape of the image are adjusted to improve the generalization ability of the model.
[0045] Step S02: Building a network model with an attention mechanism based on the Yolov8 network; the network model with an attention mechanism based on the Yolov8 network includes a backbone structure module, a neck structure module, and a head structure module, and each module is sequentially connected to form a trainable network model. The backbone structure includes a C2F module, and the C2F module includes three output channels connected to the neck structure; a channel attention layer and a spatial attention layer are added before the concate layer in the C2F module.
[0046] First, an attention mechanism is added to the C2F module in the model to strengthen channel and spatial attention, that is, global average pooling and maximum pooling operations are introduced after the concate layer in the CSVF module.
[0047] For example, the input feature map is F∈R C×H×W , where C is the number of channels of the feature map, H is the height, and W is the width. As in Formula 1, normalize F to [-1, 1] to get F * Then use the Softmax function to transform F * Mapped into an exponential probability distribution F en , as shown in Formula 2. This step increases the probability distribution exponential of key eigenvalues and decreases the probability distribution exponential of non-key eigenvalues. Finally, as shown in Formula 3, F is increased by the enhancement index e. * With F en After linear weighted addition, we get F in Then global pooling is performed, where the enhancement parameter is set to 55. This method can effectively filter out useless features and enhance key features, effectively improving the performance of the subsequent attention mechanism.
[0048]
[0049] Fin =F * +eF en (3)
[0050] Then, the global average pooling and maximum pooling are used to generate two different feature descriptors, as shown in Formulas 4 and 5.
[0051] F in-avg =AvgPool(F in ) (4)
[0052] F in-max =MaxPool(F in ) (5)
[0053] The first full-chain layer uses the ReLu activation function to increase feature nonlinearity, which helps the model learn more complex channel correlations. The second full-chain layer restores the original enhanced feature values. W1 and W2 are the weights of the two full-chain layers, which are weighted and activated by the Sigmoid function to ensure the safe generation of the attention mechanism weight vector M(F). The channel and spatial attention weight vectors are shown in formulas 6 and 7, respectively, where f 7×7 is a 7×7 convolution operation, and σ is a Sigmoid activation function.
[0054]
[0055] The weights W1 and W2 of the two full-chain layers are updated by self-learning using the small-batch gradient descent method, and the initial weights are set manually.
[0056] The neck structure includes three input channels, and the feature fusion between the channels adopts the Wconcate weighted feature splicing method. The Wconcate weighted feature splicing method is implemented using the following formula:
[0057] f wc =W{C(f1,f2)}, where f1,f2 are feature maps from the upper layer entering the Concate module, wc is the enhanced feature map, C is the equivalent function of the Concate module, and is the weighted function generated by self-learning.
[0058] like Figure 3 The connection mode of WConcate in the C2F module shown in the figure. The WConcate module is an improved weighted concatenation fusion module. It can solve the information redundancy and interference between channels that may be caused by directly concatenating different path features during feature fusion.
[0059] Combined with the above-mentioned channel self-attention module, the spliced feature map is weighted at the channel level, so that the model can adaptively focus on the information from a specific channel among many channels, improving the network's perception of key features. In this process, we have made targeted improvements to the shortcomings of the direct splicing method, so that the model can more accurately capture the correlation between features of different scales and improve the target detection performance.
[0060] After the feature maps from the upper layer and the current layer are WConcate-ed, the channel self-attention module is embedded thereafter to effectively enhance the features. It is particularly noteworthy that the design choice of introducing channel self-attention after WConcate is to overcome the problem of inconsistent features learned by each channel after channel splicing. This can give channels containing important information a greater weight while ignoring those insignificant channels. Such an attention mechanism helps to increase the network's attention to the spliced feature maps, allowing the network to focus more on the sensitive features of the target, thereby improving detection performance. Its calculation principle is as shown in Formula 8:
[0061] f WC =W{C(f1,f2)} (8)
[0062] Where C is the equivalent function of the WConcate module, is the weighted function generated by self-learning, the method is the same as above, f1, f2 are the feature maps from the upper layer entering the WConcate module, f wc It is the enhanced feature map.
[0063] The head structure includes two output channels: a classification output channel and a detection output channel; the classification output channel outputs the category of the target object; the detection output channel outputs the bounding box of the target object.
[0064] The C2F module and other modules in the backbone, neck and head structures constitute a neural network with characterization and learning capabilities, which is called the ACDet network model structure in the present invention.
[0065] Step S03: training the network model based on the enhanced image to obtain the optimal detection model, specifically including using the enhanced image as the input of the network model, evaluating the prediction ability of the network model through the loss function, iterating multiple times until the loss function no longer decreases and the model reaches the optimal state, and saving the optimal detection model.
[0066] The loss functions are specifically: one is CIoU Loss and DFL loss for optimizing the bounding box regression problem, and the other is BCE loss for optimizing the classification task.
[0067] There are two types of tasks for this model: classification and bounding box regression. Two types of loss functions are designed: the loss function of the category output is the multi-label multi-classification BCE loss function, which is shown in Formula 9:
[0068]
[0069] Among them, σ(x) represents the sigmoid activation function:
[0070] The bounding box regression loss function uses the CIoU and DFL loss functions, which are shown in Formula 10 and Formula 11:
[0071]
[0072] DFL(S i , S i+1 )=-((y i+1 -y)log(S i )+(yy i )log(S i+1 )) (11)
[0073] The DFL loss function can effectively correct the distance between the generated bounding box and the target bounding box, making it more accurately close to the target bounding box.
[0074] The weight self-learning update is shown in formula 12:
[0075]
[0076] The learning rate is reduced by half every 10 epochs, and the initial learning rate is 0.6. The dynamic learning rate is shown in Formula 13, where n is the number of iterations.
[0077]
[0078] Finally, based on the above experimental settings, the designed loss function and enhanced images are used to train the network model to obtain the optimal detection model. The specific application of the present invention in model training and target detection on the CPPD dataset is shown in Table 1, which shows the target detection results on the CPPD dataset.
[0079] Model ImgSize mAP@0.5 mAP@0.5:0.95 YOLOv8n 640 69.79 59.69 Ours 640 77.01 56.22
[0080] As can be seen from Table 1, on the CPPD dataset, the input feature map size is 640*640 pixels, the mAP@0.5 index of the YOLOv8n model target detection is 69.79%, and the mAP@0.5:0.95 index is 59.69%; the mAP@0.5 index of the target detection of the model of the present invention is 77.01%, and the mAP@0.5:0.95 index is 56.22%.
[0081] The above experimental results show that the target detection model improved by the method of the present invention and the diversified training data can effectively improve the accuracy of target detection in medicine box images.
[0082] Embodiment 2
[0083] The dataset used in this example is 16,848 images of drug packaging, which are divided into 7 packaging types to form a fully annotated CPPD dataset. The dataset for model performance evaluation is divided into a training set and a test set; the training set contains 16,848 images, and the test set is a zero-sample test data set containing 100,000 test images.
[0084] The experimental hardware is RTX3060 GPU, and TensorBoard is used to monitor the training process in the python3 environment.
[0085] like Figure 1 As shown in the figure, a vector drug packaging visual precision detection method based on yolov8 is shown in the figure. The specific steps are as follows:
[0086] Step S01: performing data enhancement on the obtained sample image to obtain an enhanced image; the data enhancement on the obtained training data to obtain an enhanced image specifically includes: performing HSV color enhancement, random rotation enhancement, random affine enhancement, and random mosaic enhancement operations on the training data to obtain a variety of enhanced images.
[0087] The obtained training data set is CPPD data collected about the outer packaging of medicines, and multiple enhancement methods are used, including HSV color enhancement, random rotation enhancement, random affine enhancement, random mosaic enhancement and other image data enhancement methods to expand the diversity of data samples.
[0088] The principle of HSV color enhancement: by adding disturbances to the three channels of h, s, and v in the HSV color space, the hue is transformed to achieve the purpose of data enhancement. The specific color conversion relationship is:
[0089]
[0090] Randomly adjust the brightness by calling the RandomAdjustBrightness() function in the transforms package.
[0091] For example: Transforms.RandomAdjustBrightness() function: RandomAdjustBrightness(0.3).
[0092] Call the RandomRotation() function in the transforms package to perform random rotation. For example: Transforms.RandomRotation() function: RandomRotation(degrees, resample = False, expand = False, center = None).
[0093] Call the RandomAffine() function in the transforms package to perform random affine. For example: Transforms.RandomAffine() function:
[0094] RandomAffine(degrees,translate=None,scale=None,shear=None,interpolation=<InterpolationMode.NEAREST:’nearest’> , fill=0, fillcolor=None, resample=None, center=None).
[0095] Random mosaic enhancement is to randomly select several images and combine them into several new images. The number of combined images is greater than the original number.
[0096] Through multiple data enhancement methods, the brightness and shape of the image are adjusted to improve the generalization ability of the model.
[0097] Step S02: Building a network model with an attention mechanism based on the yolov8 network; the network model with an attention mechanism based on the yolov8 network includes a backbone structure module, a neck structure module, and a head structure module, and each module is sequentially connected to form a trainable network model. The backbone structure includes a C2F module, and the C2F module includes three output channels connected to the neck structure; a channel attention layer and a spatial attention layer are added before the concate layer in the C2F module.
[0098] First, an attention mechanism is added to the C2F module in the model to strengthen channel and spatial attention, that is, global average pooling and maximum pooling operations are introduced after the Concate layer in the CSVF module.
[0099] For example, the input feature map is F∈R C×H×W , where C is the number of channels of the feature map, H is the height, and W is the width. As in Formula 1, normalize F to [-1, 1] to get F * Then use the Softmax function to transform F * Mapped into an exponential probability distribution F en , as shown in Formula 2. This step increases the probability distribution exponential of key eigenvalues and decreases the probability distribution exponential of non-key eigenvalues. Finally, as shown in Formula 3, F is increased by the enhancement index e. * With F en After linear weighted addition, we get F in Then global pooling is performed, where the enhancement parameter is set to 55. This method can effectively filter out useless features and enhance key features, effectively improving the performance of the subsequent attention mechanism.
[0100]
[0101] F in =F * +eF en (3)
[0102] Then, the global average pooling and maximum pooling are used to generate two different feature descriptors, as shown in Formulas 4 and 5.
[0103] F in-avg =AvgPool(F in ) (4)
[0104] F in-max =MaxPool(F in ) (5)
[0105] The first full-chain layer uses the ReLu activation function to increase feature nonlinearity, which helps the model learn more complex channel correlations. The second full-chain layer restores the original enhanced feature values. W1 and W2 are the weights of the two full-chain layers, which are weighted and activated by the Sigmoid function to ensure the safe generation of the attention mechanism weight vector M(F). The channel and spatial attention weight vectors are shown in formulas 6 and 7, respectively, where f 7×7 is a 7×7 convolution operation, and σ is a Sigmoid activation function.
[0106]
[0107] The weights W1 and W2 of the two full-chain layers are updated by self-learning using the small-batch gradient descent method, and the initial weights are set manually.
[0108] The neck structure includes three input channels, and the feature fusion between the channels adopts the Wconcate weighted feature splicing method. The Wconcate weighted feature splicing method is implemented using the following formula:
[0109] f wc =W{C(f1,f2)}, where f1,f2 are feature maps from the upper layer entering the Concate module, wc is the enhanced feature map, C is the equivalent function of the Concate module, and is the weighted function generated by self-learning.
[0110] like Figure 3 The connection mode of WConcate in the C2F module shown in the figure. The WConcate module is an improved weighted concatenation fusion module. It can solve the information redundancy and interference between channels that may be caused by directly concatenating different path features during feature fusion.
[0111] Combined with the above-mentioned channel self-attention module, the spliced feature map is weighted at the channel level, so that the model can adaptively focus on the information from a specific channel among many channels, improving the network's perception of key features. In this process, we have made targeted improvements to the shortcomings of the direct splicing method, so that the model can more accurately capture the correlation between features of different scales and improve the target detection performance.
[0112] After the feature maps from the upper layer and the current layer are WConcate-ed, the channel self-attention module is embedded thereafter to effectively enhance the features. It is particularly noteworthy that the design choice of introducing channel self-attention after WConcate is to overcome the problem of inconsistent features learned by each channel after channel splicing. This can give channels containing important information a greater weight while ignoring those insignificant channels. Such an attention mechanism helps to increase the network's attention to the spliced feature maps, allowing the network to focus more on the sensitive features of the target, thereby improving detection performance. Its calculation principle is as shown in Formula 8:
[0113] f WC =W{C(f1,f2)} (8)
[0114] Where C is the equivalent function of the WConcate module, is the weighted function generated by self-learning, the method is the same as above, f1, f2 are the feature maps from the upper layer entering the WConcate module, f wc It is the enhanced feature map.
[0115] The head structure includes two output channels: a classification output channel and a detection output channel; the classification output channel outputs the category of the target object; the detection output channel outputs the bounding box of the target object.
[0116] The C2F-A module and other modules in the backbone, neck and head structures constitute a neural network with characterization and learning capabilities, which is called the ACDet network model structure in the present invention.
[0117] Step S03: training the network model based on the enhanced image to obtain the optimal detection model, specifically including using the enhanced image as the input of the network model, evaluating the prediction ability of the network model through the loss function, iterating multiple times until the loss function no longer decreases and the model reaches the optimal state, and saving the optimal detection model.
[0118] The loss functions are specifically: one is CIoU Loss and DFL loss for optimizing the bounding box regression problem, and the other is BCE loss for optimizing the classification task.
[0119] There are two types of tasks for this model: classification and bounding box regression. Two types of loss functions are designed: the loss function of the category output is the multi-label multi-classification BCE loss function, which is shown in Formula 9:
[0120]
[0121] Among them, σ(x) represents the sigmoid activation function:
[0122] The bounding box regression loss function uses the CIoU and DFL loss functions, which are shown in Formula 10 and Formula 11:
[0123]
[0124] DFL(S i , S i+1 )=-((y i+1 -y)log(S i )+(yy i )log(S i+1 )) (11)
[0125] The DFL loss function can effectively correct the distance between the generated bounding box and the target bounding box, making it more accurately close to the target bounding box.
[0126] The weight self-learning update is shown in formula 12:
[0127]
[0128] The learning rate is reduced by half every 10 epochs, and the initial learning rate is 0.6. The dynamic learning rate is shown in Formula 13, where n is the number of iterations.
[0129]
[0130] Finally, based on the above experimental settings, the designed loss function and enhanced images are used to train the network model to obtain the optimal detection model. The specific application of the present invention in model training and target detection on the CPPD dataset is shown in Table 1, which shows the target detection results on the CPPD dataset.
[0131] Model ImgSize mAP@0.5 mAP@0.5:0.95 YOLOv8n 640 69.79 59.69 Ours 640 77.01 56.22
[0132] As can be seen from Table 1, on the CPPD dataset, the input feature map size is 640*640 pixels, the mAP@0.5 index of the YOLOv8n model target detection is 69.79%, and the mAP@0.5:0.95 index is 59.69%; the mAP@0.5 index of the target detection of the model of the present invention is 77.01%, and the mAP@0.5:0.95 index is 56.22%.
[0133] The above experimental results show that the target detection model improved by the method of the present invention and the diversified training data can effectively improve the accuracy of target detection in medicine box images.
[0134] After obtaining the optimal model above, you can use the target image for testing:
[0135] Step S04: input the target image into the detection model to obtain the detection result; the inputting the target image into the detection model to obtain the detection result is specifically inputting the target image into the optimal model obtained above, executing the detection task, and obtaining the detection result of the target image, that is, the target drug and the detection frame of the target drug; the detection frame has vector properties, that is, it is generated according to the contour of the target image.
[0136] Embodiment 3
[0137] This embodiment is a vector pharmaceutical packaging visual precision detection system of yolov8 based on the attention mechanism, which includes the following modules: image data processing module, model building module, training module, and testing module.
[0138] The image data processing module is used to enhance the drug packaging image data to obtain an enhanced image; this module includes operations such as cropping, graying, rotating, and data enhancement of the image data.
[0139] Build a model module to build a network model with attention mechanism;
[0140] A training module, used to enhance the image pair network model training to obtain a detection model;
[0141] The testing module is used to input the test image into the detection model and output the detection result of the model.
[0142] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with the art within the technical scope disclosed in the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A vector drug packaging detection method based on yolov8 network, the vector drug packaging detection method based on yolov8 network, specifically comprising the following steps: Obtain sample images of drug packaging and perform data enhancement to obtain enhanced images; Build a network model with attention mechanism based on yolov8 network; The network model is trained based on the enhanced image to obtain a detection model; Input the target image into the detection model to obtain the detection result.
2. The vector drug packaging detection method based on yolov8 network according to claim 1 is characterized in that: The method of obtaining a sample image of a pharmaceutical package and performing data enhancement to obtain an enhanced image specifically includes: obtaining a sample image of a pharmaceutical package and performing HSV color enhancement, random rotation enhancement, random affine enhancement, and random mosaic enhancement operations on the image data to obtain a variety of enhanced images.
3. The vector drug packaging detection method based on yolov8 network according to claim 1 is characterized in that: The network model with attention mechanism based on yolov8 network includes backbone structure module, neck structure module and head structure module, and each module is connected in sequence into a trainable network model.
4. The vector drug packaging detection method based on yolov8 network according to claim 3 is characterized in that: The backbone structure includes a C2F module, which includes three output channels and is connected to the neck structure; a channel attention layer and a spatial attention layer are added before the concate layer in the C2F module.
5. The vector drug packaging detection method based on yolov8 network according to claim 3 is characterized in that: The neck structure includes three input channels, and the feature fusion between the three channels adopts the Wconcate weighted feature concatenation method.
6. The vector drug packaging detection method based on yolov8 network according to claim 5 is characterized in that: The Wconcate weighted feature concatenation method is implemented using the following formula: f wc =W{C(f1,f2)}, where f1,f2 are feature maps from the upper layer entering the Concate module, wc is the enhanced feature map, C is the equivalent function of the Concate module, and is the weighted function generated by self-learning.
7. According to the vector drug packaging detection method based on yolov8 network according to claim 3, it is characterized in that: The head structure includes two output channels: a classification output channel and a detection output channel; The classification output channel outputs the category of the target object; the detection output channel outputs the bounding box of the target object, and the bounding box has directionality.
8. The vector drug packaging detection method based on yolov8 network according to any one of claims 1 to 7, characterized in that: The network model is trained based on the enhanced image to obtain the detection model, which specifically includes using the enhanced image as the input of the network model, evaluating the prediction ability of the network model through the loss function, and iterating multiple times until the loss function no longer decreases and the model reaches the optimal state, and then saving the optimal detection model.
9. The vector drug packaging detection method based on yolov8 network according to claim 8 is characterized in that: The target image is input into the optimal detection model to obtain the detection result, specifically, after the target image is input into the optimal detection model obtained above, the detection task is performed to obtain the detection result of the target image, that is, the classification of the target drug and the detection frame of the target drug.
10. A vector medicine packaging detection system based on yolov8 network, the vector medicine packaging detection system based on yolov8 network comprising: An image data processing module, used for enhancing the drug packaging image data to obtain an enhanced image; Build a model module to build a network model with attention mechanism; A training module, used to enhance the image pair network model training to obtain a detection model; The testing module is used to input the test image into the detection model and output the detection result of the model.
