A method for detecting adulterated mutton by an inverted residual network combined with an attention mechanism
Patent Information
- Application Number
- CN202210823768.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-14
- Publication Date
- 2026-09-18
- Estimated Expiration
- 2042-07-14
AI Technical Summary
[0003]本发明的目的是构建一种倒置残差网络结合注意力机制的卷积神经网络结构进而利用其建立分类检测模型并进行掺假羊肉检测的方法,包括构建掺假羊肉检测的卷积神经网络,然后建立掺假羊肉分类检测模型,再将模型移植到移动端对掺假羊肉进行检测,旨在解决经典的残差网络中参数过多、收敛速度较慢及针对成分复杂的掺假羊肉分类检测精度不高、操作复杂等问题
[0028] First, by using inverted residual networks, the computational cost in high-dimensional space is reduced, the model convergence speed is improved, the model parameters are reduced, and the model structure is made lightweight.
Smart Images

Figure CN117434054B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of rapid detection technology of meat using deep learning methods. It involves constructing a convolutional neural network structure that combines an inverted residual network with an attention mechanism, and then using it to establish a classification and detection model for detecting adulterated mutton. Background Technology
[0002] With the development of detection technology, the use of smartphones combined with machine learning and deep learning methods is increasingly being applied to meat detection. Deep learning methods have shown great advantages in image processing; however, in pursuit of stronger network performance, the increasing depth of convolutional neural network models has led to problems such as vanishing gradients and network degradation. The introduction of residual networks is a significant advancement in deep learning, effectively alleviating the problems caused by increasing the depth of convolutional neural networks. However, residual network models have too many parameters, resulting in slow convergence speeds and making them unsuitable for mobile devices. Furthermore, the performance of residual networks degrades when performing classification or recognition on large, complex images. Currently, there are no reports of using inverted residual networks combined with attention mechanisms in convolutional neural networks to achieve high-precision detection of adulterated mutton on mobile devices. Summary of the Invention
[0003] The purpose of this invention is to construct a convolutional neural network structure combining an inverted residual network and an attention mechanism, and then use it to establish a classification and detection model for detecting adulterated mutton. The method includes constructing a convolutional neural network for detecting adulterated mutton, then establishing a classification and detection model for adulterated mutton, and then porting the model to a mobile device to detect adulterated mutton. This invention aims to solve the problems of excessive parameters, slow convergence speed, low accuracy in classifying and detecting adulterated mutton with complex components, and complex operation in classic residual networks.
[0004] The technical solution adopted in this invention is as follows:
[0005] A method for detecting adulterated mutton using an inverted residual network combined with an attention mechanism is characterized by: first constructing a convolutional neural network for detecting adulterated mutton, then establishing a classification and detection model for adulterated mutton, and finally porting the model to a mobile device to detect adulterated mutton.
[0006] The specific construction of the convolutional neural network for detecting adulterated mutton is as follows:
[0007] A convolutional neural network combining an inverted residual network and an attention mechanism is constructed, comprising an input layer, Conv1, Conv2_x, Conv3_x, Conv4_x, Conv5_x, and an output layer. Conv1 consists of standard convolutional units. Conv2_x, Conv3_x, Conv4_x, and Conv5_x layers are composed of stacked inverted residual modules (two standard convolutional units and one depthwise convolutional unit) and an attention mechanism module. The output layer consists of a fully connected layer and a classification layer. Its workflow is as follows: First, the input data is subjected to standard convolution in the Conv1 layer. After max pooling, the order of dimensionality reduction and upscaling is swapped in the Conv2_x, Conv3_x, Conv4_x, and Conv5_x layers, and the attention mechanism module is introduced to obtain spatial and channel features. Finally, after average pooling, the classification result is output in the output layer.
[0008] The specific steps for establishing a classification and detection model for adulterated mutton are as follows:
[0009] Step 1: Prepare adulterated mutton samples with consistent quality, uniform density, and consistent particle size;
[0010] Step 2: Use an image acquisition system to acquire images of the adulterated mutton sample;
[0011] Step 3: Perform background segmentation preprocessing on the image of the adulterated mutton sample, and then perform data augmentation on this basis;
[0012] Step 4: Divide the enhanced image data into training and test sets; use the training and test sets to model the adulterated mutton classification and detection model in the constructed inverted residual network combined with the attention mechanism convolutional neural network structure, determine the model parameters, and establish the adulterated mutton classification and detection model.
[0013] Step 5: Port the preprocessing program for adulterated mutton sample images and the trained adulterated mutton classification and detection model to mobile devices, and develop a mobile adulterated mutton detection system.
[0014] The specific steps for detecting adulterated mutton samples on a mobile device are as follows:
[0015] Step A: Prepare mutton samples with consistent quality, uniform density, and consistent particle size to be tested;
[0016] Step B: Use a mobile image acquisition system to acquire images of the mutton sample to be tested;
[0017] Step C: Use the ported mobile system to preprocess the image of the mutton sample to be tested, and then use the mobile system's adulterated mutton classification and detection model to detect the mutton sample and output the detection results.
[0018] The inverted residual network combined with the attention mechanism described above can be used in different residual networks, such as ResNet50, ResNet101, and ResNet152.
[0019] In the above convolutional neural network structure combining the inverted residual network with the attention mechanism, the inverted residual structure takes the compressed low-dimensional features as input, first uses standard convolution to achieve dimensionality increase, then uses depthwise convolution to extract high-dimensional features, and finally uses standard convolution to achieve dimensionality reduction. The attention mechanism consists of two parts: channel attention and spatial attention, which recalibrate the feature maps in both the channel and spatial parts. The calculation formulas are as follows:
[0020]
[0021]
[0022] In steps one and A above, during sample preparation, adulterated mutton mince with consistent quality, uniform density, and consistent particle size is prepared.
[0023] In steps two and B above, images of the samples are acquired under constant temperature and humidity conditions in a laboratory. The image acquisition device includes: a dark box, a smartphone, a light source, a sample stage, and a displacement platform.
[0024] The image processing methods involved in steps three and C above include Hough circle transform and Hough line transform. Hough circle transform is preferred for segmenting the sample image.
[0025] In step four above, the optimizers involved include SGD and Adam, with corresponding learning efficiencies of 0.001 and 0.0001, respectively. SGD is preferred, and its learning efficiency is set to 0.001.
[0026] In step five above, the mobile detection system mainly includes two parts: a front-end interface and a back-end processing. The front-end interface displays the image to be detected and the detection results. The back-end processing includes image acquisition, image processing, and model detection functions. The mobile terminal acquires images of adulterated mutton samples by selecting images from the image library and taking images with the mobile terminal's camera.
[0027] The advantages of this invention compared to existing technologies are:
[0028] First, by using inverted residual networks, the computational cost in high-dimensional space is reduced, the model convergence speed is improved, the model parameters are reduced, and the model structure is made lightweight.
[0029] Second, an attention mechanism is introduced to redistribute feature weights by utilizing the channel and spatial features of the image, thereby enhancing the feature differences of the image and effectively improving the detection accuracy, thus achieving high-precision detection of adulterated mutton samples.
[0030] Third, the adulterated mutton classification and detection model established by using an inverted residual network combined with an attention mechanism convolutional neural network is ported to mobile devices, which has good portability and practicality. Attached Figure Description
[0031] Figure 1 Attention mechanism structure diagram
[0032] Figure 2 This example illustrates the image data acquisition of adulterated mutton samples.
[0033] Figure 3 This example demonstrates the system flowchart for detecting adulterated mutton samples on a mobile device.
[0034] Figure 4 This example shows the results of testing a sample of adulterated mutton on a mobile device. Detailed Implementation
[0035] To make the objectives and advantages of this invention clearer, the following detailed description of the invention is provided in conjunction with specific embodiments.
[0036] Example 1: A convolutional neural network combining an inverted residual network and an attention mechanism
[0037] The constructed inverted residual network combined with the attention mechanism of the convolutional neural network includes an input layer, Conv1, Conv2_x, Conv3_x, Conv4_x, Conv5_x and an output layer; wherein Conv1 is composed of standard convolutional units, Conv2_x, Conv3_x, Conv4_x and Conv5_x layers are composed of inverted residual modules consisting of two standard convolutional units and one depthwise convolutional unit stacked with attention mechanism modules, and the output layer is composed of a fully connected layer and a classification layer.
[0038] As shown in Table 1, in a typical network structure based on inverted residual networks combined with an attention mechanism, Conv(1×1) is a convolution with a kernel size of 1×1, Dwise(3×3) is a depthwise convolution with a kernel size of 3×3, k is the number of kernels, and S is the stride. In typical convolutional neural networks, such as ResNet50, ResNet101, and ResNet152, the selectable values for the number of kernels include 64, 256, 512, 1024, and 2048. The difference between different convolutional neural networks lies in the number of Conv2_x, Conv3_x, Conv4_x, and Conv5_x layers. In this example, taking CBAM-Invert-ResNet50 as an example, the number of Conv2_x, Conv3_x, Conv4_x, and Conv5_x layers are 3, 4, 6, and 3, respectively, and the kernel number k takes values of 256, 64, and 512, respectively. 128, 1024, 256, 2048, 512; the stride of Conv1 and Conv2_x layers is 2; Conv3_1, Conv4_1, and Conv5_1 are inverted residual structures with downsampling and convolution, with Dwise(3×3) having a stride of 2, and the rest are inverted residual structures with downsampling and no convolution, with a stride of 1.
[0039] Table 1. Typical network structures of inverted residual networks combined with attention mechanisms.
[0040]
[0041] In this example, the inverted residual structure takes the compressed low-dimensional features as input, first uses a 1×1 standard convolution to achieve dimensionality increase, then extracts features through a 3×3 depthwise convolution, and finally uses a 1×1 standard convolution to achieve dimensionality reduction.
[0042] like Figure 1 As shown, after the feature map is input, it first enters the channel attention module: first, global max pooling and global average pooling are performed, and the channel attention weights are obtained through a shared perceptron. Then, the normalized attention weights are obtained through the sigmoid activation function. Finally, the original input feature map is obtained through weighting, completing the relabeling of the original features by the channel attention. Next, the feature map output by the channel attention enters the spatial attention module: after obtaining the spatial attention features through global average pooling and global pooling, the feature dimension is transformed from H×W to 1×1, and then it is convolved with a 7×7 kernel and a sigmoid activation function to establish high-dimensional spatial correlation.
[0043] Example 2: Establishment of a classification and detection model for adulterated mutton based on inverted residual networks combined with attention mechanisms under the influence of additives.
[0044] Step 1: Prepare adulterated mutton samples with additives;
[0045] In this embodiment, the experimental materials are mutton and pork, with fat, fascia, and skin removed; the additives are mutton extract and red yeast rice dye; the specific preparation process is as follows: First, according to the food safety regulations for mutton extract and red yeast rice dye, mutton extract is dissolved in distilled water at a concentration of 0.05 g / ml to prepare a mutton extract solvent, and red yeast rice dye is dissolved in distilled water at a concentration of 0.5 g / kg to prepare a red yeast rice dye solvent at a concentration of 0.001 g / ml. The two solvents are mixed and shaken for ten minutes to ensure uniform color mixing; then, the mixed solvent is added to pork mince from different parts and soaked for 20 minutes. After the solvent has fully penetrated the pork mince, the residual liquid on the surface is removed; finally, the pork mince from different parts mixed with mutton extract and dye is mixed in different proportions (10%, 20%), and the mixture is further mixed with the red yeast rice dye. 30% and 40% of the mutton were mixed into the mutton mince to make adulterated mutton samples. The adulterated mutton samples were all round or nearly round patties with a net weight of about 30g and a diameter of 6cm. Eight samples of pork with different proportions of adulterated mutton were prepared under the action of additives (8×4×3=96 samples). Ten samples of pork with different parts of the body were prepared under the action of additives, for a total of 30 samples. Thirty mutton samples were prepared, for a total of 156 samples.
[0046] Step 2: Image acquisition of adulterated mutton samples under the influence of additives;
[0047] like Figure 2 As shown, the experiment was conducted at a temperature of (26±1)℃ and a relative humidity of (30±5)%. The image acquisition device included: a dark box, a smartphone, a light source, a sample stage, and a displacement platform.
[0048] The image acquisition was performed using a Huawei P40 mobile phone and a camera model ANA-AN00. When acquiring images, the camera's ISO sensitivity was 500, the aperture was f / 1.9, the exposure time was 1 / 100, the focal length was 7mm, the color temperature was 4500K, the image resolution was 6144*8192 pixels (dpi), and the image acquisition height was 18cm.
[0049] Step 3: Perform background segmentation preprocessing on the image of the adulterated mutton sample under the influence of additives, and then perform data augmentation on this basis;
[0050] The image dataset of adulterated samples under the influence of additives is preprocessed, specifically including the selection of Hough circular detection method to segment and remove sample background and remove a small number of abnormal samples; data augmentation methods such as rotation, offset, and mirroring are used to expand the data volume, and the expanded data is compressed to 224*224 pixels to reduce the computational load and computation time of the network model.
[0051] Step 4: Divide the enhanced image data into training and testing sets to establish a classification and detection model for adulterated mutton under the influence of additives;
[0052] In this example, the image dataset consists of data-augmented images of adulterated mutton, including 3900 images in the training set and 1300 images in the test set. The SGD optimizer is preferred when training the model, with a learning efficiency set to 0.001. The batch sample size is 16, and the maximum number of iterations is 100. The detection results of the samples include mutton samples, adulterated mutton samples, and pork samples.
[0053] The model's performance is evaluated by calculating its accuracy, using the following formula:
[0054] Accuracy=(TP+TN) / (TP+FP+TN+FN)
[0055] Among them, TP represents true positive (the number of adulterated samples that are correctly classified as adulterated samples), FN represents false negative (the number of adulterated samples that are mistakenly classified as unadulterated samples), TN represents true negative (the number of unadulterated samples that are correctly classified as unadulterated samples), and FP represents false positive (the number of unadulterated samples that are mistakenly classified as adulterated samples).
[0056] Step 5: Port the image preprocessing program and the trained adulterated mutton classification and detection model under the action of additives to the mobile terminal, and develop a mobile adulterated mutton detection system.
[0057] In this example, the TensorFlow Lite framework is used to deploy a pre-trained inverted residual network combined with an attention mechanism convolutional neural network to an Android device. The mobile system mainly consists of two parts: the front-end interface and the back-end processing. The front-end interface displays the image to be detected and the detection results by adding text and button components. The back-end processing includes image acquisition, image processing, and model detection functions.
[0058] Example 3: A mobile detection method for adulterated mutton under the influence of additives based on inverted residual networks combined with attention mechanisms.
[0059] Step a: Prepare adulterated mutton samples under the influence of the additives to be tested;
[0060] Following the same procedure as step 1 in Example 2, adulterated mutton samples were prepared under the influence of the additives to be tested, including: 96 samples of pork adulterated with mutton from different parts of the meat in different proportions under the influence of the additives, 30 samples of pork from different parts of the meat under the influence of the additives, and 30 mutton samples, for a total of 156 samples.
[0061] Step b: Acquire images of adulterated mutton samples under the influence of the additives to be tested;
[0062] like Figure 2 As shown, images of adulterated mutton samples under the influence of the additives to be tested were acquired in a laboratory environment with a temperature of (26±1)℃ and a relative humidity of (30±5)%.
[0063] Step c: Use the ported mobile system to preprocess the image of the adulterated mutton sample under the action of the additives to be detected, and then use the adulterated mutton classification and detection model of the mobile device to detect the mutton sample and output the detection results.
[0064] In this embodiment, the image library of the mobile system includes 2600 images to be detected after data augmentation; as shown in Figure 3, after the user logs into the mobile system, they select the input method for the images to be detected. After the images are input, they are automatically cropped to 224*224 pixels; after the mobile system acquires the images, it calls the adulterated mutton classification and detection model to classify and detect the images; as shown in Figure 3. Figure 4 As shown, when a sample image to be detected is input, the mobile system will detect whether it is falsified and output the category of the image to be detected, the corresponding confidence level, and the detection time; the detection time for each image is approximately 0.3 seconds.
[0065] For 2600 images to be detected, the detection results are shown in Table 2. The accuracy of the convolutional neural network model constructed in this invention, which combines an inverted residual network with an attention mechanism, in detecting adulterated mutton from different parts is 95.19%, 94.29%, and 95.81%, respectively, and the accuracy of detecting adulterated mutton from mixed parts is 92.96%. Meanwhile, the accuracy of the classic convolutional neural network model in detecting adulterated mutton from different parts is 89.58%, 91.72%, and 82.22%, respectively, and the accuracy of detecting adulterated mutton from mixed parts is 90.38%. Compared with the corresponding classic convolutional neural network, the proposed convolutional neural network model improves the classification accuracy of adulterated mutton from different parts and adulterated mutton from mixed parts by 5.61, 2.57, 13.59, and 2.58 percentage points, respectively.
[0066] Table 2 Comparison of Validation Set Accuracy of Two Convolutional Neural Networks at Different Locations
[0067]
[0068] Analysis of the test results shows that the classification and detection model for adulterated mutton established based on the inverted residual network and attention mechanism has good overall performance, can significantly improve classification accuracy and classification speed, and can be well applied to real-world scenarios.
[0069] This invention, through three embodiments, illustrates a method for constructing a convolutional neural network structure combining an inverted residual network and an attention mechanism, and then using it to build a classification and detection model for adulterated mutton. These methods are: constructing a convolutional neural network combining an inverted residual network and an attention mechanism; establishing a classification and detection model for adulterated mutton; and implementing adulterated mutton classification and detection on a mobile device. This invention replaces the residual structure in the classic residual network with an inverted residual structure, effectively improving the model's convergence speed and making the model structure lightweight. The introduction of an attention mechanism into the inverted residual structure enhances the feature differences in the image, thereby acquiring more comprehensive feature information and improving detection accuracy. Furthermore, the established adulterated mutton classification and detection model is ported to mobile devices, exhibiting good portability and practicality.
[0070] The above embodiments are only used to illustrate the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention and based on the technical essence of the present invention should be included within the scope of the present invention. The patent protection scope of the present invention is defined by the claims.
Claims
1. A method for detecting adulterated mutton using an inverted residual network combined with an attention mechanism, characterized in that: First, a convolutional neural network for detecting adulterated mutton is constructed. Then, a classification and detection model for adulterated mutton is established. Finally, the model is ported to a mobile device to detect adulterated mutton. The specific construction of the convolutional neural network for detecting adulterated mutton is as follows: A convolutional neural network combining an inverted residual network and an attention mechanism is constructed, comprising an input layer, Conv1, Conv2_x, Conv3_x, Conv4_x, Conv5_x, and an output layer, as shown in the table. Conv1 consists of standard convolutional units, while Conv2_x, Conv3_x, Conv4_x, and Conv5_x layers are composed of stacked inverted residual modules consisting of two standard convolutional units and one depthwise convolutional unit, along with an attention mechanism module. The output layer consists of a fully connected layer and a classification layer. Its workflow is as follows: First, the input data is subjected to standard convolution in the Conv1 layer. After max pooling, the data dimensionality reduction and dimensionality increase order is swapped in the Conv2_x, Conv3_x, Conv4_x, and Conv5_x layers, and an attention mechanism module is introduced to obtain spatial and channel features. Finally, after average pooling, the classification result is output in the Output layer. Network structure combining inverted residual networks with attention mechanisms The inverted residual structure takes the compressed low-dimensional features as input, first uses a 1×1 standard convolution to achieve dimensionality increase, then uses a 3×3 depthwise convolution to extract high-dimensional features, and finally uses a 1×1 standard convolution to achieve dimensionality reduction. The specific steps for establishing a classification and detection model for adulterated mutton are as follows: Step 1: Prepare adulterated mutton samples with consistent quality, uniform density, and consistent particle size; Step 2: Use an image acquisition system to acquire images of the adulterated mutton sample; Step 3: Perform background segmentation preprocessing on the image of the adulterated mutton sample, and then perform data augmentation on this basis; Step 4: Divide the enhanced image data into training and testing sets; In the constructed convolutional neural network structure combining inverted residual network and attention mechanism, the training set and test set are used to model the adulterated mutton classification and detection model, and the model parameters are determined to establish the adulterated mutton classification and detection model. Step 5: Port the preprocessing program for adulterated mutton sample images and the trained adulterated mutton classification and detection model to mobile devices, and develop a mobile adulterated mutton detection system. The specific steps for testing adulterated mutton samples on a mobile device are as follows: Step A: Prepare mutton samples with consistent quality, uniform density, and consistent particle size to be tested; Step B: Use a mobile image acquisition system to acquire images of the mutton sample to be tested; Step C: Use the ported mobile system to preprocess the image of the mutton sample to be tested, then use the mobile system's adulterated mutton classification and detection model to detect the mutton sample to be tested, and output the detection results.
2. The method for detecting adulterated mutton using an inverted residual network combined with an attention mechanism according to claim 1, characterized in that: The attention mechanism is divided into two parts: channel attention and spatial attention. The feature maps are recalibrated in both the channel and spatial parts. The calculation formulas are as follows:
3. The method for detecting adulterated mutton using an inverted residual network combined with an attention mechanism according to claim 1, characterized in that: In steps one and A, during sample preparation, adulterated mutton mince with consistent quality, uniform density, and consistent particle size is prepared.
4. The method for detecting adulterated mutton using an inverted residual network combined with an attention mechanism according to claim 1, characterized in that: In steps two and B, images of the sample are acquired in a laboratory environment with constant temperature and humidity. The image acquisition device includes a dark box, a smartphone, a light source, a sample stage, and a displacement platform.
5. The method for detecting adulterated mutton using an inverted residual network combined with an attention mechanism according to claim 1, characterized in that: The image processing methods involved in steps three and C include Hough circle transform and Hough line transform.
6. The method for detecting adulterated mutton using an inverted residual network combined with an attention mechanism according to claim 1, characterized in that: In step four, the optimizers involved include SGD and Adam, with corresponding learning efficiencies of 0.001 and 0.0001, respectively.
7. The method for detecting adulterated mutton using an inverted residual network combined with an attention mechanism according to claim 1, characterized in that: In step five, the mobile detection system includes two parts: a front-end interface and a back-end processing; the front-end interface displays the image to be detected and the detection results. Backend processing includes functions for image acquisition, image processing, and model detection; The mobile devices can acquire images of adulterated mutton samples by selecting images from the gallery and taking pictures with the mobile device's camera.