Lightweight pork freshness grading method and system based on improved MobileNetV4
By improving the MobileNetV4 network, introducing the ASPP module and ELA attention mechanism, a lightweight pork freshness grading model was constructed, which solved the problems of pork image recognition accuracy and computational complexity, and achieved efficient and accurate pork freshness grading.
Patent Information
- Application Number
- CN202510721015.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-30
- Publication Date
- 2025-09-12
AI Technical Summary
Existing technologies find it difficult to accurately identify freshness features in pork images in open scenarios, and deep learning models require large amounts of computation and parameters, resulting in low detection efficiency and insufficient accuracy.
Abstract: In order to improve the freshness of pork, an improved MobileNetV4 network was used. The Atrous Spatial Convolutional Pooling Pyramid (ASPP) module and structured pruning technology were introduced. Combined with the ELA attention mechanism, a lightweight pork freshness grading model was constructed. The model's generalization ability was enhanced through image enhancement processing, and the amount of computation and parameters was reduced.
Maintaining high recognition accuracy in complex environments improves the model's operating efficiency and recognition accuracy, making it suitable for deployment on resource-constrained devices and enhancing the ability to capture detailed features and express key features in pork images.
Smart Images

Figure CN120635552A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image recognition and classification, and specifically relates to a lightweight pork freshness grading method and system based on an improved MobileNetV4. Background Art
[0002] Currently, conventional methods for testing pork freshness include sensory testing, physical and chemical testing, and microbiological testing. However, these methods all suffer from low efficiency, long testing times, and significant product damage. Pork images can reveal its external characteristics, which are diverse and complex, including color changes, texture changes, and fat content. However, traditional methods struggle to fully and accurately extract these subtle and complex features, resulting in inaccurate assessments of pork freshness. Furthermore, complex deep learning models, with their large number of parameters, are difficult to deploy due to hardware limitations.
[0003] Prior Art 1: CN118587742A (Gesture Recognition Model Construction Method, Apparatus, Electronic Device, and Medium). This technology collects gesture images of people inside a vehicle and feeds the preprocessed gesture images into a MobileNetV4 small network for feature extraction. After feature extraction, an FPN feature pyramid network is used to fuse feature maps of different scales. This network performs a feature pyramid operation by fusing feature maps from top to bottom and bottom to top, ultimately generating a fused feature map. The fused feature map is then fed into a fully connected layer of a MobileNetV4 small network, which outputs a classification feature vector. The loss values for different samples are determined based on the classification feature vectors and a cross-entropy loss function with label smoothing. The target loss for difficult samples is then adjusted based on the loss values for each sample and an adaptive adjustment matrix. The adaptive adjustment matrix is used to generate computational weights corresponding to K loss vectors. A softmax layer is used to normalize the computational weights. Finally, a weighted calculation is performed on the K loss vectors. The loss values for the remaining samples and a regularization penalty are combined to form the target loss for difficult samples. A regularization penalty is also added to mitigate overfitting. The limitation of existing technology 1 is that in a complex background environment, the model may be disturbed, resulting in a decrease in recognition accuracy. The model may not be accurate enough in capturing subtle features and may not be able to perform timely and accurate recognition, which may result in the model's detection effect still being unsatisfactory.
[0004] Prior art 2: CN119169514A (a method for detecting plant leaf diseases based on an improved MobileNetV3). This technology collects plant leaf disease images and performs preprocessing, and uses the improved MobileNetV3 as the feature extraction network of the model. SkipBlock is inserted into the feature extraction network of MobileNetV3. The specific structure of SkipBlock includes convolution blocks, BN normalization, and adaptive pooling. The low-level features extracted by the underlying network are passed to the high-level network through jump connections, and the improved whale optimization algorithm is used to automatically adjust the size of the hidden layer in SkipBlock and automatically determine the most suitable number of neurons. The improved whale optimization algorithm uses the Lévy flight strategy to update the position of the individual again after each position update. At the same time, the loss function is modified, and the traditional cross-entropy loss function is replaced by a weighted bias loss function. Finally, the model is fine-tuned and parameterized to obtain a plant leaf disease detection model. The limitations of the existing technology 2 are that the model may have limitations in covering the types of plant leaf diseases. When plant varieties vary greatly in different regions, it may not be able to adapt well and accurately identify diseases, thereby reducing the accuracy of detection.
[0005] How to build a lightweight model that can reduce the amount of computation and parameters while more accurately identifying feature information closely related to freshness in pork images in open scenarios, thereby achieving rapid and high-precision grading of pork freshness, is an urgent problem that needs to be solved. Summary of the Invention
[0006] In order to solve the problems existing in the prior art, the present invention provides a lightweight pork freshness grading method and system based on an improved MobileNetV4, aiming to accurately identify and detect the quality of pork and perform meat quality grading while reducing the amount of calculation and parameters, and to more accurately identify the feature information closely related to freshness in pork images in open scenarios, thereby achieving rapid and high-precision grading of pork freshness.
[0007] To achieve the above objectives, the present invention provides the following solution: a lightweight pork freshness grading method based on an improved MobileNetV4, comprising:
[0008] S1. Collect pork images, construct a data set based on the pork images, and preprocess the data set;
[0009] S2. Build a pork freshness grading model based on the MobileNetV4 network;
[0010] S3. Training the pork freshness grading model based on the preprocessed data set;
[0011] S4. Based on the trained pork freshness grading model, pork freshness is graded on the pork images to be graded.
[0012] Preferably, the pre-processing of the data set in S1 includes: performing four-fold image enhancement on the data set by reducing brightness, increasing brightness, increasing sharpness, and blurring.
[0013] Preferably, the S2 constructs a pork freshness grading model based on the MobileNetV4 network, including: introducing an ASPP module into the convolutional layer of the MobileNetV4 network, and the ASPP module includes four branches:
[0014] Branch 1 is a normal convolution with a dilation rate of r = 1, which is used to extract local detail features:
[0015] P1=Conv 1×1,r=1 (P in )
[0016] Among them, P1 represents the feature map extracted by branch 1, Conv 1×1,r=1 Indicates a normal 1×1 convolution operation with a dilation rate of r=1, P in Represents the input feature map;
[0017] Branch 2 is a dilated convolution with a dilation rate of r = 2, which is used to expand the receptive field to a medium scale:
[0018] P2=Conv 3×3,r=2 (P in )
[0019] Among them, P2 represents the feature map extracted by branch 2, Conv 3×3,r=2 Indicates a normal 3×3 convolution operation with a dilation rate of r=2;
[0020] Branch 3 is a dilated convolution with a dilation rate of r = 4, which is used to further expand the receptive field:
[0021] P3=Conv 3×3,r=4 (P in )
[0022] Among them, P3 represents the feature map extracted by branch 3, Conv 3×3,r=4 Indicates a normal 3×3 convolution operation with a dilation rate of r=4;
[0023] Branch 4 is global average pooling, which is used to capture global context features:
[0024] P4=Upsample(Conv 1×1 (GAP(P in )),H,W)
[0025] Among them, P4 represents the feature map extracted by branch 4, GAP represents the global average pooling of each channel, Conv 1×1 Represents a 1×1 convolution operation, Upsample represents the use of bilinear interpolation to restore the feature map, H and W are the height and width of the input feature map respectively;
[0026] The outputs of the four branches are stacked in the channel dimension for feature fusion to obtain the final feature map:
[0027] P f =Concat(P1,P2,P3,P4)
[0028] P out =Conv 1×1 (P f )
[0029] Among them, P f Represents the fused features, Concat represents the feature stacking operation, P out represents the final feature map.
[0030] Preferably, the S2 constructs a pork freshness grading model based on the MobileNetV4 network, including performing a structured pruning operation on the depthwise separable convolutional layer:
[0031]
[0032] Among them, ||W||1 represents the L1 norm of the weight tensor, that is, the sum of the absolute values of all elements, W i,j,k is the weight tensor in the convolution kernel, i and j are the spatial dimensions height and width of the convolution kernel, and k is the index of the input channel.
[0033] Preferably, the S2 constructs a pork freshness grading model based on the MobileNetV4 network, including: introducing an ELA attention mechanism module into the MobileNetV4 network:
[0034] Y=x c ×y h ×y w
[0035] Among them, Y represents the output feature of the ELA attention mechanism module, x c Represents the original input feature on the cth channel, y h Represents the horizontal position attention, y w Represents position attention in the vertical direction.
[0036] The present invention also provides a lightweight pork freshness grading system based on an improved MobileNetV4, the system is used to implement the aforementioned lightweight pork freshness grading method based on an improved MobileNetV4, the system comprising: an acquisition module, a model building module, a training module, and a grading module;
[0037] The acquisition module is used to acquire pork images, construct a data set based on the pork images, and preprocess the data set;
[0038] The model building module is used to build a pork freshness grading model based on the MobileNetV4 network;
[0039] The training module is used to train the pork freshness grading model based on the preprocessed data set;
[0040] The grading module is used to grade the pork freshness of the pork image based on the trained pork freshness grading model.
[0041] Preferably, the acquisition module pre-processes the data set, including: performing four-fold image enhancement on the data set by reducing brightness, increasing brightness, increasing sharpness, and blurring.
[0042] Preferably, the model construction module is used to construct a pork freshness grading model based on the MobileNetV4 network, including: introducing an ASPP module into the convolutional layer of the MobileNetV4 network, and the ASPP module includes four branches:
[0043] Branch 1 is a normal convolution with a dilation rate of r = 1, which is used to extract local detail features:
[0044] P1=Conv 1×1,r=1 (P in )
[0045] Among them, P1 represents the feature map extracted by branch 1, Conv 1×1,r=1 Indicates a normal 1×1 convolution operation with a dilation rate of r=1, P in Represents the input feature map;
[0046] Branch 2 is a dilated convolution with a dilation rate of r = 2, which is used to expand the receptive field to a medium scale:
[0047] P2=Conv 3×3,r=2 (P in )
[0048] Among them, P2 represents the feature map extracted by branch 2, Conv 3×3,r=2 Indicates a normal 3×3 convolution operation with a dilation rate of r=2;
[0049] Branch 3 is a dilated convolution with a dilation rate of r = 4, which is used to further expand the receptive field:
[0050] P3=Conv 3×3,r=4 (P in )
[0051] Among them, P3 represents the feature map extracted by branch 3, Conv 3×3,r=4 Indicates a normal 3×3 convolution operation with a dilation rate of r=4;
[0052] Branch 4 is global average pooling, which is used to capture global context features:
[0053] P4=Upsample(Conv 1×1 (GAP(P in )),H,W)
[0054] Among them, P4 represents the feature map extracted by branch 4, GAP represents the global average pooling of each channel, Conv 1×1 Represents a 1×1 convolution operation, Upsample represents the use of bilinear interpolation to restore the feature map, H and W are the height and width of the input feature map respectively;
[0055] The outputs of the four branches are stacked in the channel dimension for feature fusion to obtain the final feature map:
[0056] P f =Concat(P1,P2,P3,P4)
[0057] P out =Conv 1×1 (P f )
[0058] Among them, P f Represents the fused features, Concat represents the feature stacking operation, P out represents the final feature map.
[0059] Preferably, the model building module is used to build a pork freshness grading model based on the MobileNetV4 network, including performing a structured pruning operation on the depthwise separable convolutional layer:
[0060]
[0061] Among them, ||W||1 represents the L1 norm of the weight tensor, that is, the sum of the absolute values of all elements, W i,j,k is the weight tensor in the convolution kernel, i and j are the spatial dimensions height and width of the convolution kernel, and k is the index of the input channel.
[0062] Preferably, the model construction module is used to construct a pork freshness grading model based on the MobileNetV4 network, including: introducing an ELA attention mechanism module into the MobileNetV4 network:
[0063] Y=x c ×y h ×y w
[0064] Among them, Y represents the output feature of the ELA attention mechanism module, x c Represents the original input feature on the cth channel, y h Represents the horizontal position attention, y w Represents position attention in the vertical direction.
[0065] Compared with the prior art, the present invention has the following beneficial effects:
[0066] 1. By performing image enhancement on the pork image dataset, the model's generalization ability was enhanced, enabling it to maintain high recognition accuracy in complex environments such as those with varying lighting and color balance.
[0067] 2. By introducing the Atrous Spatial Convolutional Pooling Pyramid (ASPP) module and structured pruning technology, the model's computational complexity and parameter count are reduced, improving its operational efficiency and making it more suitable for deployment on resource-constrained devices. The ASPP module, through multi-branch atrous convolution and global average pooling, enhances the model's ability to capture multi-scale features in pork images. In particular, high-level feature extraction allows for better adaptation to detailed features in pork images, improving the accuracy of pork freshness recognition.
[0068] 3. By introducing the ELA attention mechanism module, the location information of the region of interest can be accurately obtained, which enhances the model's ability to express key features and further improves the model's classification accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] In order to more clearly illustrate the technical solution of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0070] Figure 1 This is a flow chart of a lightweight pork freshness grading method based on improved MobileNetV4 in Example 1 of the present invention;
[0071] Figure 2This is a schematic diagram of the structure of a pork freshness grading model according to Example 1 of the present invention;
[0072] Figure 3 This is a schematic diagram of the ELA attention mechanism module structure in Example 1 of the present invention;
[0073] Figure 4 This is a module diagram of a lightweight pork freshness grading system based on improved MobileNetV4 in Example 2 of the present invention. DETAILED DESCRIPTION
[0074] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. 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 making creative efforts are within the scope of protection of the present invention.
[0075] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0076] Example 1
[0077] like Figure 1 As shown, the present invention provides a lightweight pork freshness grading method based on an improved MobileNetV4, comprising:
[0078] S1. Collect pork images, build a dataset based on the pork images, and preprocess the dataset;
[0079] S2. Build a pork freshness grading model based on the MobileNetV4 network;
[0080] S3, training the pork freshness grading model based on the preprocessed data set;
[0081] S4. Based on the trained pork freshness grading model, pork freshness is graded on the pork images to be graded.
[0082] For example, pork samples were selected from pigs raised in the same environment and fed the same feed. These pork samples were then placed in the same environment to allow them to spoil naturally. At regular intervals, portions of the pork were removed from the samples for physical and chemical testing. The total microbial count, coliform count, and pH value of the pork were measured at different storage times. Based on comparisons with national standards, the freshness of this batch of pork was biologically classified into seven grades: fresh, less-than-fresh meat grade 1, less-than-fresh meat grade 2, less-than-fresh meat grade 3, spoiled meat grade 1, spoiled meat grade 2, and spoiled meat grade 3. The specific grading standards are shown in Table 1:
[0083] Table 1 Pork freshness classification
[0084]
[0085] After biological and physical chemical tests, biologically graded pork images were taken as a dataset.
[0086] Under different shooting environments, pork meat quality images may be affected by factors such as lighting uniformity, color balance and saturation, image clarity, exposure, equipment performance, and shooting environment. In order to enhance the generalization of the model, better distinguish the characteristics of different grades of meat, and improve recognition accuracy, the pork image dataset was preprocessed and four times image enhancement was performed on the pork image dataset using methods such as reducing brightness, increasing brightness, increasing sharpness, and blurring.
[0087] The preprocessed dataset is divided into training set, validation set and test set in a ratio of 7:2:1.
[0088] The Small version of MobileNetV4 is used to improve the network and build a pork freshness grading model. The structure of the pork freshness grading model is as follows: Figure 2 The details are as follows:
[0089] The MobileNetV4 pipeline begins with the input, which first undergoes a 3×3 convolutional layer (stride 2) for preliminary feature extraction and downsampling, followed by convolutional normalization to stabilize training. This process is repeated to further compress the feature map size and enhance spatial information aggregation. Next, the network enters the core feature extraction phase, employing a unified inverted bottleneck structure with a 5×5 depthwise separable convolutional block embedded in the ELA attention mechanism. This is followed by a stacking of five 3×3 depthwise separable convolutional blocks with a stride of 1, followed by another ELA attention mechanism. This adaptive weight distribution strengthens the representation of information about key feature channels or spatial locations. This pattern is continued in the subsequent stages. A 3×3 depthwise separable convolution block is used, the ELA attention mechanism is embedded, and five 5×5 depthwise separable convolution blocks with a stride of 1 are stacked in sequence. The ELA attention mechanism is embedded again to improve the discriminability of deep semantic features. A two-layer atrous spatial convolutional pooling pyramid (ASPP) module is used. Finally, the feature map is compressed into a global vector through global average pooling, and the classification result is output through a fully connected layer.
[0090] The ASPP module is introduced into the convolutional layer of the MobileNetV4 network to improve the network's receptive field, especially in the feature extraction part of higher layers. This allows the model to better capture a wide range of contextual information and adapt to the detailed features in pork images.
[0091] The working principle of dilated convolution is to insert gaps between elements in the standard convolution kernel to expand the convolution receptive field. Dilated convolution can obtain a larger receptive field while maintaining the same computational and memory consumption, thereby capturing larger-scale contextual information. By introducing multi-branch dilated convolution and global average pooling, the receptive field is expanded and the ability to express multi-scale information is enhanced. The ASPP module is added to the last two Bottleneck Blocks of MobileNetV4.
[0092] Each ASPP module consists of four branches and inputs feature maps:
[0093]
[0094] Among them, H and W are the height and width of the input feature map, C in is the number of input channels.
[0095] Branch 1 is a normal convolution with a dilation rate of r = 1, which is used to extract local detail features, namely:
[0096] P1=Conv 1×1,r=1 (P in )
[0097] Among them, P1 represents the feature map extracted by the ordinary 1×1 convolution of branch 1, Conv 1×1,r=1 Indicates a normal 1×1 convolution operation with a dilation rate of r=1, P in Represents the input feature map;
[0098] Branch 2 is a dilated convolution with a dilation rate of r = 2, which is used to expand the receptive field to a medium scale, namely:
[0099] P2=Conv 3×3,r=2 (P in )
[0100] Among them, P2 represents the local detail feature map extracted by the ordinary 3×3 convolution of branch 2, Conv 3×3,r=2 Indicates a normal 3×3 convolution operation with a dilation rate of r=2, P in Represents the input feature map;
[0101] Branch 3 is a dilated convolution with a dilation rate of r = 4, which is used to further expand the receptive field:
[0102] P3=Conv 3×3,r=4 (P in )
[0103] Among them, P3 represents the feature map extracted by branch 3 ordinary 3×3 convolution, Conv 3×3,r=4Indicates a normal 3×3 convolution operation with a dilation rate of r=4, P in Represents the input feature map;
[0104] Branch 4 is global average pooling, which is used to capture global context features, namely:
[0105] P4=Upsample(Conv 1×1 (GAP(P in )),H,W)
[0106] Among them, P4 represents the feature map extracted by branch 4, GAP represents the global average pooling of each channel to generate 1×1×C in Feature map, Conv 1×1 Represents 1×1 convolution, and Upsample means using bilinear interpolation to restore the 1×1 feature map to H×W.
[0107] The outputs of all branches are then stacked in the channel dimension for feature fusion:
[0108] P f =Concat(P1,P2,P3,P4)
[0109] Among them, P f Represents the fused features, Concat represents the feature stacking operation; use 1×1 convolution to adjust the number of channels and output the final feature map:
[0110] P out =Conv 1×1 (P f )
[0111] Among them, P out represents the final feature map.
[0112] We perform structured pruning on the third-layer, unified inverted bottleneck depthwise separable convolutional layer in the MobileNetV4 architecture. We evaluate the importance of convolution kernels or channels by measuring the L1 norm of the convolution layer, and then prune unimportant kernels or channels to reduce the number of model parameters and computational complexity. The L1 norm is the sum of the absolute values of all weights in the convolution layer and can be used to measure the impact of the convolution kernel or channel on the network output.
[0113]
[0114] Among them, ||W||1 represents the L1 norm of the weight tensor, that is, the sum of the absolute values of all elements, W i,j,k is the weight tensor in the convolution kernel, i and j are the spatial dimensions height and width of the convolution kernel, and k is the index of the input channel.
[0115] For the six depthwise separable convolutional layers in the third unified inverted bottleneck structure, after calculating the L1 norm, the depthwise separable convolutional layer with the smallest L1 norm is deleted, that is, the third depthwise separable convolutional layer: the number of channels is 96, the stride is 1, and the dilation rate is 2.
[0116] ELA (Efficient Local Attention) is an efficient local attention module that accurately captures the location of regions of interest, maintains the dimensionality of the input feature map channels, and preserves its lightweight nature. ELA uses strip pooling in the spatial dimension to obtain horizontal and vertical feature vectors. The strip kernel shape captures long-range dependencies, preventing irrelevant regions from affecting label predictions, thereby generating rich target location features in each direction.
[0117] ELA independently processes the feature vectors in each direction to predict attention, and then combines them using a product operation to ensure the accuracy of the position information of the region of interest. The specific steps are: using one-dimensional convolution to locally interact with the two feature vectors respectively, and the kernel size can be adjusted as needed to control the interaction range. The resulting feature vectors are then grouped and normalized, and processed through a nonlinear activation function to obtain the position attention prediction of the two directions. Finally, the position attention of the two directions is multiplied to obtain the final position attention.
[0118] The ELA attention mechanism module is introduced into a specific layer of the MobileNetV4 model, including: horizontal and vertical strip pooling to obtain long-distance dependencies; one-dimensional convolution and group normalization processing to enhance the expression ability of position information; and the horizontal and vertical position attention are combined through multiplication operation to generate the final position attention feature.
[0119] The ELA attention mechanism module structure diagram is as follows Figure 3 The specific implementation is as follows: the output of a convolution block is expressed as Where C represents the channel dimension. Strip pooling is applied to each channel in both horizontal and vertical spatial ranges, represented as (H, 1) in the horizontal direction and (1, W) in the vertical direction. That is:
[0120]
[0121]
[0122] in, Represents the output feature of the cth channel at height h after the pooling operation in the horizontal direction. Represents the output feature of the cth channel at the width w position after the pooling operation in the vertical direction. c(h,q) represents the element value of the c-th channel at a height of h and a width of q in the original convolution block output feature map. c (p,w) represents the element value of the c-th channel at a height of p and a width of w in the output feature map of the original convolution block.
[0123] A one-dimensional convolution is applied to the position information in both horizontal and vertical directions to enhance its information. Subsequently, group normalization G is used n To process the enhanced position information, we can get the representation of position attention in the horizontal and vertical directions:
[0124]
[0125]
[0126] Among them, y h Represents the horizontal position attention, y w represents the vertical position attention, γ represents the nonlinear activation function, P h and P w Represents a one-dimensional convolution, and the convolution kernel size is set to 5.
[0127] The feature Y is output through the ELA module, namely:
[0128] Y=x c ×y h ×y w
[0129] Among them, x c Represents the original input features on the c-th channel.
[0130] In the MobileNetV4 model, the first and fifth depthwise separable convolutional layers in the third unified inverted bottleneck structure, the first and sixth depthwise separable convolutional layers in the fourth unified inverted bottleneck structure, and the ELA attention mechanism modules are added after the two ASPP modules in the fifth layer to enhance the model's ability to express key features in pork images.
[0131] The pork freshness grading model was trained using the training set, and then the cross-validation method was used. The validation set was used to evaluate the performance of the pork freshness grading model after each training cycle. The parameters of the pork freshness grading model were adjusted according to the evaluation results, and the pork freshness grading model was tested using the test set to achieve the best performance of the pork freshness grading model.
[0132] In order to make the pork freshness grading model more convenient and efficient to be applied in actual scenarios, a set of interactive interfaces was developed, including image uploading, format conversion, model prediction and result display functional modules, which support users to conveniently select and upload pork image files. The front end receives the transmitted pork image data, and after verification and format conversion, it inputs it into the trained pork freshness grading model for prediction, and returns the obtained freshness grade result to the front end. After receiving the result, the front end presents it to the user in a special result display area with clear text and intuitive visual icons, thus realizing a complete, smooth and friendly interactive process from image uploading to grading result output, greatly improving the convenience and operability of pork image grading, and providing powerful tool support for pork quality assessment.
[0133] In summary, the present invention enhances the generalization ability of the model by performing image enhancement on the pork image dataset, such as brightness adjustment, sharpening, and blurring, so that it can still maintain a high recognition accuracy in complex environments such as different lighting and color balance. By introducing the Atrous Spatial Convolution Pooling Pyramid (ASPP) module and structured pruning technology, the computational complexity and parameter amount of the model are reduced, the operating efficiency of the model is improved, and it is more suitable for deployment on resource-constrained devices. The ASPP module enhances the model's ability to capture multi-scale features in pork images through multi-branch atrous convolution and global average pooling, especially in the high-level feature extraction part, which can better adapt to the detailed features in pork images and improve the recognition accuracy of pork freshness. By introducing the ELA attention mechanism module, the location information of the region of interest can be accurately obtained, the model's ability to express key features is enhanced, and the classification accuracy of the model is further improved. In addition, the present invention also develops a set of interactive interfaces that support users to conveniently upload pork images and perform freshness grading, greatly improving the convenience and operability of pork image grading, and providing a powerful tool support for pork quality assessment.
[0134] Example 2
[0135] like Figure 4 As shown, the present invention also provides a lightweight pork freshness grading system based on an improved MobileNetV4, which is used to implement the method described in Example 1. The system includes: an acquisition module, a model building module, a training module, and a grading module;
[0136] The acquisition module is used to collect pork images, build a data set based on the pork images, and preprocess the data set;
[0137] The model building module is used to build a pork freshness grading model based on the MobileNetV4 network;
[0138] The training module is used to train the pork freshness grading model based on the preprocessed data set;
[0139] The grading module is used to grade the pork freshness of the pork images based on the trained pork freshness grading model.
[0140] The data set is preprocessed in the acquisition module, including: four-fold image enhancement of the data set using brightness reduction, brightness increase, sharpening, and blurring.
[0141] The model building module is used to build a pork freshness grading model based on the MobileNetV4 network. It includes: introducing the ASPP module into the convolutional layer of the MobileNetV4 network. The ASPP module consists of four branches:
[0142] Branch 1 is a normal convolution with a dilation rate of r = 1, which is used to extract local detail features:
[0143] P1=Conv 1×1,r=1 (P in )
[0144] Among them, P1 represents the feature map extracted by branch 1, Conv 1×1,r=1 Indicates a normal 1×1 convolution operation with a dilation rate of r=1, P in Represents the input feature map;
[0145] Branch 2 is a dilated convolution with a dilation rate of r = 2, which is used to expand the receptive field to a medium scale:
[0146] P2=Conv 3×3,r=2 (P in )
[0147] Among them, P2 represents the feature map extracted by branch 2, Conv 3×3,r=2 Indicates a normal 3×3 convolution operation with a dilation rate of r=2;
[0148] Branch 3 is a dilated convolution with a dilation rate of r = 4, which is used to further expand the receptive field:
[0149] P3=Conv 3×3,r=4 (P in )
[0150] Among them, P3 represents the feature map extracted by branch 3, Conv 3×3,r=4 Indicates a normal 3×3 convolution operation with a dilation rate of r=4;
[0151] Branch 4 is global average pooling, which is used to capture global context features:
[0152] P4=Upsample(Conv1×1 (GAP(P in )),H,W)
[0153] Among them, P4 represents the feature map extracted by branch 4, GAP represents the global average pooling of each channel, Conv 1×1 Represents a 1×1 convolution operation, Upsample represents the use of bilinear interpolation to restore the feature map, H and W are the height and width of the input feature map respectively;
[0154] The outputs of the four branches are stacked in the channel dimension for feature fusion to obtain the final feature map:
[0155] P f =Concat(P1,P2,P3,P4)
[0156] P out =Conv 1×1 (P f )
[0157] Among them, P f Represents the fused features, Concat represents the feature stacking operation, P out represents the final feature map.
[0158] The model building module is used to build a pork freshness grading model based on the MobileNetV4 network, including structured pruning:
[0159]
[0160] Among them, ||W||1 represents the L1 norm of the weight tensor, that is, the sum of the absolute values of all elements, W i,j,k is the weight tensor in the convolution kernel, i and j are the spatial dimensions height and width of the convolution kernel, and k is the index of the input channel.
[0161] The model building module is used to build a pork freshness grading model based on the MobileNetV4 network, including: introducing the ELA attention mechanism module in the MobileNetV4 network:
[0162] Y=x c ×y h ×y w
[0163] Among them, Y represents the output feature of the ELA attention mechanism module, x c Represents the original input feature on the cth channel, y h Represents the horizontal position attention, y w Represents position attention in the vertical direction.
[0164] The embodiments described above are merely descriptions of preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Without departing from the spirit of the present invention, various modifications and improvements made to the technical solutions of the present invention by persons skilled in the art should fall within the scope of protection defined by the claims of the present invention.
Claims
1. A lightweight pork freshness grading method based on improved MobileNetV4, characterized in that: include: S1. Collect pork images, construct a data set based on the pork images, and preprocess the data set; S2. Build a pork freshness grading model based on the MobileNetV4 network; S3. Training the pork freshness grading model based on the preprocessed data set; S4. Based on the trained pork freshness grading model, pork freshness is graded on the pork images to be graded.
2. The lightweight pork freshness grading method based on improved MobileNetV4 according to claim 1 is characterized in that: The data set is preprocessed in S1, including: performing four-fold image enhancement on the data set by using brightness reduction, brightness increase, sharpening, and blurring.
3. The lightweight pork freshness grading method based on improved MobileNetV4 according to claim 1 is characterized in that: The S2 constructs a pork freshness grading model based on the MobileNetV4 network, including: introducing an ASPP module into the convolutional layer of the MobileNetV4 network, and the ASPP module includes four branches: Branch 1 is a normal convolution with a dilation rate of r = 1, which is used to extract local detail features: P1=Conv 1×1,r=1 (P in ) Among them, P1 represents the feature map extracted by branch 1, Conv 1×1,r=1 Indicates a normal 1×1 convolution operation with a dilation rate of r=1, P in Represents the input feature map; Branch 2 is a dilated convolution with a dilation rate of r = 2, which is used to expand the receptive field to a medium scale: P2=Conv 3×3,r=2 (P in ) Among them, P2 represents the feature map extracted by branch 2, Conv 3×3,r=2 Indicates a normal 3×3 convolution operation with a dilation rate of r=2; Branch 3 is a dilated convolution with a dilation rate of r = 4, which is used to further expand the receptive field: P3=Conv 3×3,r=4 (P in ) Among them, P3 represents the feature map extracted by branch 3, Conv 3×3,r=4 Indicates a normal 3×3 convolution operation with a dilation rate of r=4; Branch 4 is global average pooling, which is used to capture global context features: P4=Upsample(Conv 1×1 (GAP(P in )),H,W) Among them, P4 represents the feature map extracted by branch 4, GAP represents the global average pooling of each channel, Conv 1×1 Represents a 1×1 convolution operation, Upsample represents the use of bilinear interpolation to restore the feature map, H and W are the height and width of the input feature map respectively; The outputs of the four branches are stacked in the channel dimension for feature fusion to obtain the final feature map: P f =Concat(P1,P2,P3,P4) P out =Conv 1×1 (P f ) Among them, P f Represents the fused features, Concat represents the feature stacking operation, P out represents the final feature map.
4. The lightweight pork freshness grading method based on improved MobileNetV4 according to claim 1 is characterized in that: The S2 constructs a pork freshness grading model based on the MobileNetV4 network, including structured pruning of the depthwise separable convolutional layer: Among them, ||W||1 represents the L1 norm of the weight tensor, that is, the sum of the absolute values of all elements, W i,j,k is the weight tensor in the convolution kernel, i and j are the spatial dimensions height and width of the convolution kernel, and k is the index of the input channel.
5. The lightweight pork freshness grading method based on improved MobileNetV4 according to claim 1 is characterized in that: The S2 constructs a pork freshness grading model based on the MobileNetV4 network, including: introducing an ELA attention mechanism module into the MobileNetV4 network: Y=x c ×y h ×y w Among them, Y represents the output feature of the ELA attention mechanism module, x c Represents the original input feature on the cth channel, y h Represents the horizontal position attention, y w Represents position attention in the vertical direction.
6. A lightweight pork freshness grading system based on an improved MobileNetV4, the system being used to implement the lightweight pork freshness grading method based on an improved MobileNetV4 according to any one of claims 1 to 5, characterized in that: The system includes: an acquisition module, a model building module, a training module and a classification module; The acquisition module is used to acquire pork images, construct a data set based on the pork images, and preprocess the data set; The model building module is used to build a pork freshness grading model based on the MobileNetV4 network; The training module is used to train the pork freshness grading model based on the preprocessed data set; The grading module is used to grade the pork freshness of the pork image based on the trained pork freshness grading model.
7. The lightweight pork freshness grading system based on improved MobileNetV4 according to claim 6 is characterized in that: The acquisition module pre-processes the data set, including: performing four-fold image enhancement on the data set by using brightness reduction, brightness increase, sharpening, and blurring.
8. The lightweight pork freshness grading system based on improved MobileNetV4 according to claim 6 is characterized in that: The model construction module is used to construct a pork freshness grading model based on the MobileNetV4 network, including: introducing an ASPP module into the convolutional layer of the MobileNetV4 network, and the ASPP module includes four branches: Branch 1 is a normal convolution with a dilation rate of r = 1, which is used to extract local detail features: P1=Conv 1×1,r=1 (P in ) Among them, P1 represents the feature map extracted by branch 1, Conv 1×1,r=1 Indicates a normal 1×1 convolution operation with a dilation rate of r=1, P in Represents the input feature map; Branch 2 is a dilated convolution with a dilation rate of r = 2, which is used to expand the receptive field to a medium scale: P2=Conv 3×3,r=2 (P in ) Among them, P2 represents the feature map extracted by branch 2, Conv 3×3,r=2 Indicates a normal 3×3 convolution operation with a dilation rate of r=2; Branch 3 is a dilated convolution with a dilation rate of r = 4, which is used to further expand the receptive field: P3=Conv 3×3,r=4 (P in ) Among them, P3 represents the feature map extracted by branch 3, Conv 3×3,r=4 Indicates a normal 3×3 convolution operation with a dilation rate of r=4; Branch 4 is global average pooling, which is used to capture global context features: P4=Upsample(Conv 1×1 (GAP(P in )),H,W) Among them, P4 represents the feature map extracted by branch 4, GAP represents the global average pooling of each channel, Conv 1×1 Represents a 1×1 convolution operation, Upsample represents the use of bilinear interpolation to restore the feature map, H and W are the height and width of the input feature map respectively; The outputs of the four branches are stacked in the channel dimension for feature fusion to obtain the final feature map: P f =Concat(P1,P2,P3,P4) P out =Conv 1×1 (P f ) Among them, P f Represents the fused features, Concat represents the feature stacking operation, P out represents the final feature map.
9. The lightweight pork freshness grading system based on improved MobileNetV4 according to claim 6 is characterized in that: The model building module is used to build a pork freshness grading model based on the MobileNetV4 network, including structured pruning operations on the depthwise separable convolutional layers: Among them, ||W||1 represents the L1 norm of the weight tensor, that is, the sum of the absolute values of all elements, W i,j,k is the weight tensor in the convolution kernel, i and j are the spatial dimensions height and width of the convolution kernel, and k is the index of the input channel.
10. The lightweight pork freshness grading system based on improved MobileNetV4 according to claim 6 is characterized in that: The model construction module is used to build a pork freshness grading model based on the MobileNetV4 network, including: introducing an ELA attention mechanism module into the MobileNetV4 network: Y=x c ×y h ×y w Among them, Y represents the output feature of the ELA attention mechanism module, x c Represents the original input feature on the cth channel, y h Represents the horizontal position attention, y w Represents position attention in the vertical direction.
Citation Information
Patent Citations
Gesture recognition model construction method and device, electronic equipment and medium
CN118587742A
Plant leaf disease detection method based on improved MobileNetV3
CN119169514A
Lightweight remote sensing image semantic segmentation method based on improved Deeplabv3 +
CN115984850A
Meat freshness anti-light interference detection method, device and program product
CN119395009A
Dense cut tobacco segmentation method and device based on improved DeepLabv3 + network model
CN119888219A