Ton bag counting method based on port large model variable attention mechanism

By applying the variable attention mechanism based on the large port model in the port environment, the spatial structure and texture features of the ton bags are extracted and enhanced, and combined with the backbone network and feature fusion module, the problem of identifying and counting ton bags in complex environments is solved. , achieving high-accuracy detection and counting effects.

CN118840319APending Publication Date: 2024-10-25山东港口科技集团有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410811684.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-21
Publication Date
2024-10-25

AI Technical Summary

Technical Problem

In the port loading and unloading scene, manual counting is inefficient. The goods are densely arranged and similar in appearance. They are affected by viewing angle, light, and occlusion factors, resulting in the loss of edge information. The background is complex, which easily causes misdetection, and the goods are deformed during the lifting process. , the arrangement is irregular, and it is difficult to accurately identify and count ton bags with the existing technology.

Method used

Using a variable attention mechanism based on a large port model, by acquiring image data, the spatial structure and texture features of the ton bag are extracted, and the gray level co-occurrence matrix and contrast enhancement are used, combined with the backbone network and feature fusion module, to perform deformable attention processing And contextual and spatial feature enhancement, grid prediction and loss function optimization are performed to achieve accurate detection and counting of ton bags.

Benefits of technology

It improves the accuracy and precision of ton bag detection, reduces background noise interference, ensures accurate identification and counting in complex port environments, and improves the model's recognition capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118840319A_ABST
    Figure CN118840319A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image processing, in particular to a ton bag counting method based on a port large model variable attention mechanism, which comprises the following steps: S1, acquiring image data corresponding to ton bag operation in a port environment, and constructing a sample set by using an image containing ton bags in the image data; s2, converting images in the sample set into gray images, extracting spatial structures and textural features corresponding to the ton bags by using a gray co-occurrence matrix, and enhancing the textural features by using contrast enhancement to obtain a textural feature map; s3, inputting the processed texture feature map into a backbone network, obtaining feature maps of different levels, and outputting a feature map P1, a feature map P2, a feature map P3, a feature map P4, a feature map P5 and a feature map SPPF; s4, inputting the feature maps of different levels into a feature fusion module; the ton bag can be accurately identified and positioned in a complex port environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of image processing, and in particular to a ton bag counting method based on a variable attention mechanism of a large port model. Background Art

[0002] Port logistics mainly refers to the effective implementation of port functions by relying on the geographical advantages and the resources of the port itself, with the economic hinterland city as the center. The comprehensive logistics work implemented by the port with its geographical advantages can expand its logistics functions and show the advantages of port logistics in storage and concentration of goods. Port logistics can rely on management innovation, technology optimization, and equipment transformation to more reasonably and effectively use and allocate resources in the port, more effectively promote the service function of the port in the industrial supply chain, and realize the value of the port in the entire supply chain. It is an indispensable key link in the supply chain.

[0003] In the loading and unloading scenario, the loading / unloading of goods is realized by lifting the goods by the gantry crane. During each operation process, it is impossible to know the loading or unloading quantity of the whole vehicle and the quantity of each hook. Currently, it can only be supervised by manual counting, which is inefficient. Now based on artificial intelligence algorithm analysis, the number of goods lifted by the gantry crane each time is automatically analyzed through the camera deployed on the crane. During the operation, the goods are often densely arranged, the appearance of the goods is similar, and there are factors such as viewing angle, light, and occlusion, resulting in different degrees of loss of edge information between the goods. In addition, the background of the key identification area is relatively complex, and there are piles of goods in the cabin, on the trailer, and on the ground in the background, which can easily cause false detection; during the lifting process, the surface of the goods will be squeezed and deformed, and the arrangement of the goods will also bend and deform, making the arrangement of the goods irregular. Summary of the invention

[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is:

[0005] As a preferred technical solution of the present invention, a method for counting ton bags based on a variable attention mechanism of a large port model includes:

[0006] Step S1, obtaining image data corresponding to ton bag operations in a port environment, and constructing a sample set using images containing ton bags in the image data.

[0007] Step S2, converting the images in the sample set into grayscale images, using the grayscale co-occurrence matrix to extract the spatial structure and texture features corresponding to the ton bag, and using contrast enhancement to enhance the texture features to obtain a texture feature map.

[0008] Step S3, input the processed texture feature map into the backbone network, obtain feature maps of different levels, and output feature map P1, feature map P2, feature map P3, feature map P4, feature map P5, and feature map SPPF.

[0009] In step S4, feature maps of different levels are input into a feature fusion module, and the feature maps are processed according to a deformable attention mechanism module to obtain feature maps A4 and A5 of deformable adaptive target features.

[0010] Step S5, according to the feature map output by the deformable attention, the feature map is contextually enhanced to obtain feature maps B5, B4 and A6 based on attention enhancement.

[0011] Step S6, based on the attention-enhanced feature map, perform spatial feature enhancement on the feature map to obtain feature maps C1, C2, and C3 based on spatial feature enhancement.

[0012] Step S7, stacking the feature maps according to the feature maps after spatial feature enhancement to obtain a detection feature map of the target object.

[0013] Step S8, performing grid prediction on the detection feature map, and obtaining the loss function of the target object in the grid unit after the grid prediction.

[0014] The beneficial effects of the present invention are as follows: First, the spatial structure and texture features of the ton bag are extracted by graying and gray level co-occurrence matrix, and then these features are enhanced by contrast enhancement technology. This step helps to accurately identify and locate the ton bag in a complex port environment.

[0015] Second, the backbone network is used to obtain feature maps at different levels, and these feature maps are processed through the feature fusion module and the deformable attention mechanism module. This method can adaptively focus on the key areas in the image and improve the accuracy of ton bag detection.

[0016] Third, by performing contextual attention enhancement and spatial feature enhancement on the feature map, the features related to the target ton bag are further strengthened, while the background noise is suppressed, thereby improving the detection accuracy.

[0017] Fourth, the model training process is optimized through gridded prediction and carefully designed loss functions (including category loss function and generalized IOU loss function) to ensure that the model can more accurately identify and count ton bags. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The present invention is further described below in conjunction with the accompanying drawings and embodiments.

[0019] Figure 1It is a flow chart of a method for counting ton bags based on a variable attention mechanism of a large port model;

[0020] Figure 2 It is a structural diagram of grayscale processing of the backbone network of a ton bag counting method based on a variable attention mechanism of a large port model;

[0021] Figure 3 It is a structural diagram of the attention processing of the backbone network of the ton bag counting method based on the variable attention mechanism of the port large model;

[0022] Figure 4 It is a schematic diagram of the upsampling and downsampling structure of the backbone network of the ton bag counting method based on the variable attention mechanism of the port large model;

[0023] Figure 5 This is a schematic diagram of the effect of a ton bag counting method based on a variable attention mechanism of a large port model. DETAILED DESCRIPTION

[0024] The embodiments of the present invention are described in detail below. The embodiments described below are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention. If no specific techniques or conditions are specified in the embodiments, the techniques or conditions described in the literature in the art or the product specifications are used.

[0025] See also Figure 1-Figure 5 , a method for counting ton bags based on a variable attention mechanism of a large port model, including:

[0026] Step S1, obtaining image data corresponding to ton bag operations in a port environment, and constructing a sample set using images containing ton bags in the image data.

[0027] Step S2, converting the images in the sample set into grayscale images, using the grayscale co-occurrence matrix to extract the spatial structure and texture features corresponding to the ton bag, and using contrast enhancement to enhance the texture features to obtain a texture feature map.

[0028] First, the image is grayscaled, and then the grayscale co-occurrence matrix is ​​used to extract the spatial structure and texture features. The different contrasts can highlight the hook patterns of the target object. The more prominent the pattern, the clearer the effect, which is conducive to enhancing the distinction between the sling cargo and the complex background.

[0029] The gray-level co-occurrence matrix describes texture by studying the spatial correlation characteristics of grayscale. This method was proposed by R. Haralick et al. in the 1970s to describe the spatial relationship between gray levels in an image.

[0030] The gray-level co-occurrence matrix counts the joint probability distribution of the simultaneous occurrence of gray levels of two pixels at a certain distance in the image. By calculating the correlation between the gray levels of two points at a certain distance and direction in the image, it reflects the comprehensive information of the image in terms of direction, interval, change amplitude and speed.

[0031] Take any point in the image and another point at a certain distance and direction to form a point pair, count the frequency of the gray value combination of this point pair in the entire image, and arrange all the gray value combination frequency statistics results into a matrix, namely the gray level co-occurrence matrix.

[0032] A variety of texture features can be extracted from the gray-level co-occurrence matrix, such as contrast, energy (also known as angular second moment), entropy, etc. These features can quantitatively describe the texture properties of the image, such as coarseness, complexity, directionality, and regularity.

[0033] Step S3, input the processed texture feature map into the backbone network, obtain feature maps of different levels, and output feature map P1, feature map P2, feature map P3, feature map P4, feature map P5, and feature map SPPF.

[0034] The backbone network includes six feature layers, namely P1, P2, P3, P4, P5, and SPPF; P1 consists of a conv convolution module, which consists of 3×3 convolution, normalization, and activation function SiLU, with a scale of 320×320; P2 consists of a conv convolution module and a CSP_1 module, with a scale of 160×160; P3 consists of a CSP_2 module and a conv convolution module, with a scale of 80×80; the CSP_1 module consists of three conv convolution modules and a B The P4 consists of a conv convolution module and 3 CSP_1 modules with a scale of 40×40; the P5 consists of 1 conv convolution module and 1 CSP_1 module with a scale of 20×20; the SPPF consists of three Maxpool modules and 2 conv modules with a scale of 20×20.

[0035] The processed texture feature map is input in the form of a resolution of 640*640. After being processed by P1, P2, P3, P4, P5, and SPPF, the corresponding image data at different scales are identified, and the differences and similarities in the image data are determined.

[0036] The feature maps output by the six feature layers of the above backbone network are feature map P1, feature map P2, feature map P3, feature map P4, feature map P5, and feature map SPPF.

[0037] In step S4, feature maps of different levels are input into a feature fusion module, and the feature maps are processed according to a deformable attention mechanism module to obtain feature maps A4 and A5 of deformable adaptive target features.

[0038] Step S5, according to the feature map output by the deformable attention, the feature map is contextually enhanced to obtain feature maps B5, B4 and A6 based on attention enhancement.

[0039] Step S6, based on the attention-enhanced feature map, perform spatial feature enhancement on the feature map to obtain feature maps C1, C2, and C3 based on spatial feature enhancement.

[0040] Step S7, stacking the feature maps according to the feature maps after spatial feature enhancement to obtain a detection feature map of the target object.

[0041] Step S8, performing grid prediction on the detection feature map, and obtaining the loss function of the target object in the grid unit after the grid prediction.

[0042] The processing method of the texture feature map in step S2 includes:

[0043] After the image is grayed, for the pixels in the grayscale image, the grayscale level co-occurrence frequency of each pixel about the preset horizontal direction and the preset pixel distance is counted according to the preset horizontal direction and the preset pixel distance; according to the grayscale level co-occurrence frequency, a grayscale co-occurrence matrix is ​​constructed; the grayscale co-occurrence matrix is ​​normalized to obtain a grayscale co-occurrence probability matrix; according to the grayscale co-occurrence probability matrix, a texture feature map is calculated; the features calculated in the texture feature map include calculating ASM energy, contrast, inverse moment, entropy, and autocorrelation.

[0044] ASM energy is the sum of the squares of each matrix element; contrast directly reflects the contrast in brightness between a certain pixel value and the pixel values ​​in its area; inverse moment reflects the homogeneity of image texture and measures the amount of local changes in image texture; entropy is a measure of the amount of information possessed by an image. Texture information also belongs to image information and is a measure of randomness. When all elements in the co-occurrence matrix have the greatest randomness and all values ​​in the spatial co-occurrence matrix are almost equal, the elements in the co-occurrence matrix are dispersed, and the entropy is larger, which indicates the degree of non-uniformity or complexity of the texture in the image; autocorrelation reflects the consistency of image texture.

[0045] Preferably, when processing the texture feature map in step S3, it also includes sending the texture feature map to a texture fusion module, adding features of the texture feature map and the feature map P1, and using the image after the feature addition as the feature map processed by the backbone network; the texture fusion module includes a spatial attention module and a 1×1 convolution.

[0046] The spatial attention module is represented as the CA attention mechanism. The core of the CA attention mechanism is to introduce coordinate information. It first aggregates the input features through two parallel spatial pooling operations (along the vertical and horizontal directions, respectively), thereby generating two feature maps containing direction-specific information. Doing so can capture the long-range dependencies of the input feature maps along different spatial directions; the two feature maps are encoded into two attention maps respectively. The encoding process may include steps such as convolution operations, normalization processing, and activation functions to effectively integrate the spatial coordinate information into the generated feature maps.

[0047] In one embodiment of the present invention, the method for performing feature fusion on feature maps of different levels in step S4 includes:

[0048] The feature maps P3, P4, and SPPF are obtained, and the feature maps P4 and SPPF are processed by the deformable attention mechanism module respectively to obtain the feature maps A4 and A5 of the deformable adaptive target features.

[0049] In step S4, the deformable attention mechanism module includes an offset module and an attention module; the offset module is used to determine the offset feature corresponding to the input feature map after convolution, and the attention module is used to obtain the attention feature corresponding to the input feature map, and the attention weight of the corresponding feature map is obtained by generating an attention map identical to the input feature map and multiplying the attention map with the input feature map to obtain the attention feature map.

[0050] For feature map P4 and feature map SPPF, the offset module learns the offset features of each position and adjusts the feature map according to the attention weights obtained by the attention module to adapt to the shape and size of the target.

[0051] According to the offset features corresponding to the feature maps P3 and P4 and the attention weights corresponding to the feature maps P4 and SPPF, the deformable adaptive target features are determined. The offset features corresponding to the deformable adaptive target features are determined to be the sum of the offset features of the feature maps P3 and P4. The attention weight of the deformable adaptive target features corresponding to the feature map A4 is the attention weight value of the feature map P4. The attention weight of the deformable adaptive target features corresponding to the feature map A5 is the attention weight value of the feature map SPPF.

[0052] Based on the offset features corresponding to feature maps P3 and P4 and the attention weight corresponding to feature map P4, feature map A4 is generated. Based on the offset features corresponding to feature maps P3 and P4 and the attention weight corresponding to feature map SPPF, feature map A5 is generated.

[0053] The processing means for performing attention enhancement on the feature map of the deformable attention output in step S5 includes:

[0054] Based on the acquired feature map A5, feature map A5 is convolved through a conv convolution module to obtain feature map A6, which is then upsampled. The scale of feature map A6 is 40×40.

[0055] The feature map A6 is concatenated with the obtained feature map A4 to obtain a concatenated feature map B3.

[0056] The feature map B3 is calculated through 1 CSP_1 module and 1 conv convolution module to obtain the feature map B4, which is then upsampled and the scale of the feature map B4 becomes 80×80.

[0057] The feature map B4 is stacked with the feature map P3 to obtain the feature map B5, that is, the top-down features are fused to obtain the feature maps B5, B4, and A6.

[0058] The processing method based on spatial feature enhancement in step S6 includes:

[0059] Feature map B5, feature map B4, and feature map A6 are respectively subjected to the spatial feature enhancement module to obtain feature map C1, feature map C2, and feature map C3.

[0060] The spatial feature enhancement module includes identifying the spatial feature enhancement branch, obtaining the features in the channel direction, stacking the feature maps in the three directions of C, H, and W together, and obtaining the feature maps C1, C2, and C3 enhanced by the spatial feature enhancement module.

[0061] As for the implementation method of the spatial feature enhancement module, the feature maps B5, B4, and A6 are sequentially sent into multiple branches, and the feature maps in the width and height directions are obtained through operations such as global average pooling. These feature maps encode the importance of the spatial position; the attention weights in the width and height directions are calculated through convolution and activation functions, and the attention weights are assigned to the channels through the attention mechanism. The feature maps of the channel features, height features, and width features corresponding to the feature map B5 are combined to obtain the feature map C1, the feature maps of the channel features, height features, and width features corresponding to the feature map B4 are combined to obtain the feature map C2, and the feature maps of the channel features, height features, and width features corresponding to the feature map A6 are combined to obtain the feature map C3.

[0062] The processing method for the detection feature map obtained in step S7 includes:

[0063] The feature map C1 is calculated by a CSP_1 module to obtain the feature map D1, the feature map D1 is calculated by a conv convolution module and then stacked with the feature map C2, the stacked feature map D1 is calculated with a CSP_1 module to obtain the feature map D2, the feature map D2 is stacked with the feature map C3 by a conv convolution module, the stacked feature map D2 is calculated with a CSP_1 module to obtain the feature map D3; the calculated feature maps D1, D2, and D3 are output as the processed detection feature maps.

[0064] In step S8, the processing method of the detection feature map includes:

[0065] Grid prediction is performed on feature maps D1, D2, and D3, where the grid layout of feature map D1 is NC×20×20, the grid layout of feature map D2 is NC×40×40, and the grid layout of feature map D3 is NC×80×80, where NC is the number of categories. According to the obtained grid layout, the loss function corresponding to the target object is obtained.

[0066] The loss function corresponding to the target object includes: determining the corresponding category information in each grid unit according to the obtained grid layout, and determining the category loss function based on the category;

[0067] Get the real box, predicted box and the minimum circumscribed matrix containing the real box and predicted box of the corresponding target in the grid layout, determine the minimum non-overlapping area between the real box and predicted box of the target, and obtain the generalized IOU loss function of the target based on the minimum non-overlapping area.

[0068] The prediction frame is obtained by determining the reference frame set in each grid unit, setting a set of offsets and target categories for each reference frame, adjusting the center point, width, and height of the reference frame according to the offset, and using the adjusted reference frame as the prediction frame.

[0069] The expression of the category loss function is:

[0070]

[0071] Among them, L is the category loss function, n is the number of samples, y i is the true label of the i-th sample, which takes the value of 0 or 1, p i is the probability of predicting the i-th sample as the positive class.

[0072] If the target object is detected in an image or a region, the label of the sample is usually set to 1 (or positive class); if the target object is not detected, the label of the sample is set to 0 (or negative class).

[0073] In order to make the category loss function able to identify the problem of imbalanced multi-classification samples, the factor α is introduced to learn the ratio of positive and negative samples; the adjusted category loss function is expressed as:

[0074]

[0075] Among them, L is the category loss function, n is the number of samples, y i is the true label of the i-th sample, which takes the value of 0 or 1, p i is the probability of predicting that the i-th sample is positive, and α is the adjustment factor used to adjust the weights of positive and negative class losses.

[0076] The generalized IOU loss function is expressed as:

[0077]

[0078] Among them, IOU is the intersection-over-union ratio, A is the real box, and B is the predicted box.

[0079]

[0080] Among them, L GIOU It is a generalized IOU loss function, IOU is the intersection-over-union ratio, A is the true box, B is the predicted box, and C is the minimum circumscribed matrix corresponding to the true box and the predicted box.

[0081] When using the generalized IOU loss function to solve the problem of dense target detection and classification, the smaller the non-overlapping area, the more accurate the coordinates, indicating that the currently detected object is consistent with the actual predicted position.

[0082] The generalized IOU loss function and the category loss function are weighted averaged to determine the corresponding processing content under the current grid layout to determine whether the number and location of the identified ton bags are accurate.

[0083] The present invention can effectively distinguish boundary information and the change of spatial information after the target is occluded through the enhancement of spatial feature information and the self-attention mechanism; the deformable attention mechanism can effectively extract the features of key areas through a dynamic selection mechanism (multi-head attention), reducing the interference of features under complex backgrounds; the enhancement of spatial information can effectively alleviate the situation of insufficient feature extraction under different occlusion degrees.

[0084] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations on the present invention. A person skilled in the art may make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention and they are still covered by the protection scope of the present invention.

Claims

1. A method for counting ton bags based on a variable attention mechanism for a large port model, characterized in that: include: Step S1, obtaining image data corresponding to ton bag operations in a port environment, and constructing a sample set using images containing ton bags in the image data; Step S2, converting the images in the sample set into grayscale images, using the grayscale co-occurrence matrix to extract the spatial structure and texture features corresponding to the ton bag, and using contrast enhancement to enhance the texture features to obtain a texture feature map; Step S3, input the processed texture feature map into the backbone network, obtain feature maps of different levels, and output feature map P1, feature map P2, feature map P3, feature map P4, feature map P5, and feature map SPPF; Step S4, inputting the feature maps of different levels into the feature fusion module, processing the feature maps according to the deformable attention mechanism module, and obtaining the feature maps A4 and A5 of the deformable adaptive target features; Step S5, according to the feature map output by the deformable attention, the feature map is subjected to contextual attention enhancement to obtain feature maps B5, B4 and A6 based on attention enhancement; Step S6, according to the attention-enhanced feature map, performing spatial feature enhancement on the feature map to obtain feature maps C1, C2, and C3 based on spatial feature enhancement; Step S7, stacking the feature maps according to the feature maps after spatial feature enhancement to obtain a detection feature map of the target object; Step S8, performing grid prediction on the detection feature map, and obtaining the loss function of the target object in the grid unit after the grid prediction.

2. According to claim 1, a method for counting ton bags based on a variable attention mechanism of a large port model is characterized in that: The processing method of the texture feature map in step S2 includes: after the image is grayed, for the pixels in the grayscale image, according to the preset horizontal direction and the preset pixel distance, the grayscale level co-occurrence frequency of each pixel about the preset horizontal direction and the preset pixel distance is counted; according to the grayscale level co-occurrence frequency, a grayscale co-occurrence matrix is ​​constructed; the grayscale co-occurrence matrix is ​​normalized to obtain a grayscale co-occurrence probability matrix; according to the grayscale co-occurrence probability matrix, a texture feature map is calculated.

3. According to claim 1, a method for counting ton bags based on a variable attention mechanism for a large port model is characterized in that: Step S3 also includes, when processing the texture feature map, sending the texture feature map to a texture fusion module, adding features of the texture feature map and the feature map P1, and using the image after the feature addition as the feature map processed by the backbone network; the texture fusion module includes a spatial attention module and a 1×1 convolution.

4. According to claim 1, a method for counting ton bags based on a variable attention mechanism of a large port model is characterized in that: The method of fusing features of feature maps at different levels in step S4 includes: Obtain feature maps P3, P4, and SPPF, process feature maps P4 and SPPF through deformable attention mechanism modules respectively, and obtain feature maps A4 and A5 of deformable adaptive target features; The deformable attention mechanism module consists of an offset module and an attention module; the offset module is used to determine the offset feature corresponding to the input feature map after convolution, and the attention module is used to obtain the attention feature corresponding to the input feature map; Based on the offset features corresponding to feature maps P3 and P4 and the attention weight corresponding to feature map P4, feature map A4 is generated. Based on the offset features corresponding to feature maps P3 and P4 and the attention weight corresponding to feature map SPPF, feature map A5 is generated.

5. According to claim 1, a method for counting ton bags based on a variable attention mechanism of a large port model is characterized in that: The processing means for performing attention enhancement on the feature map of the deformable attention output in step S5 includes: Based on the acquired feature map A5, the feature map A5 is convolved through a conv convolution module to obtain the feature map A6, and then upsampled. The scale of the feature map A6 is 40×40; Perform feature concatenation on the feature map A6 and the acquired feature map A4 to obtain a feature map B3 after feature concatenation; The feature map B3 is calculated through a CSP_1 module and a conv convolution module to obtain the feature map B4, and then upsampled. The scale of the feature map B4 becomes 80×80; The feature map B4 is stacked with the feature map P3 to obtain the feature map B5.

6. A method for counting ton bags based on a port large model variable attention mechanism according to claim 1, characterized in that: The processing method based on spatial feature enhancement in step S6 includes: The feature maps B5, B4, and A6 are respectively subjected to the spatial feature enhancement module to obtain the feature maps C1, C2, and C3; The spatial feature enhancement module includes identifying the spatial feature enhancement branch, obtaining the features in the channel direction, stacking the feature maps in the three directions of C, H, and W together, and obtaining the feature maps C1, C2, and C3 enhanced by the spatial feature enhancement module.

7. A method for counting ton bags based on a port large model variable attention mechanism according to claim 1, characterized in that: The processing method of the detection feature map obtained in step S7 includes: The feature map C1 is calculated by a CSP_1 module to obtain the feature map D1, the feature map D1 is calculated by a conv convolution module and then stacked with the feature map C2, the stacked feature map D1 is calculated with a CSP_1 module to obtain the feature map D2, the feature map D2 is stacked with the feature map C3 by a conv convolution module, the stacked feature map D2 is calculated with a CSP_1 module to obtain the feature map D3; the calculated feature maps D1, D2, and D3 are output as the processed detection feature maps.

8. A method for counting ton bags based on a port large model variable attention mechanism according to claim 7, characterized in that: The processing method of the detection feature map in step S8 includes: Grid prediction is performed on feature maps D1, D2, and D3, where the grid layout of feature map D1 is NC×20×20, the grid layout of feature map D2 is NC×40×40, and the grid layout of feature map D3 is NC×80×80, where NC is the number of categories. According to the obtained grid layout, the loss function corresponding to the target object is obtained.

9. A method for counting ton bags based on a port large model variable attention mechanism according to claim 8, characterized in that: The loss function corresponding to the target object includes: determining the corresponding category information in each grid unit according to the obtained grid layout, and determining the category loss function based on the category; Get the real box, predicted box and the minimum circumscribed matrix containing the real box and predicted box of the corresponding target in the grid layout, determine the minimum non-overlapping area between the real box and predicted box of the target, and obtain the generalized IOU loss function of the target based on the minimum non-overlapping area.

10. A method for counting ton bags based on a port large model variable attention mechanism according to claim 9, characterized in that: The category loss function is expressed as: Among them, L is the category loss function, n is the number of samples, y i is the true label of the i-th sample, p i is the probability of predicting that the i-th sample is a positive class; The generalized IOU loss function is expressed as: Among them, IOU is the intersection-over-union ratio, A is the real box, and B is the predicted box; Among them, L GIOU It is a generalized IOU loss function, IOU is the intersection-over-union ratio, A is the true box, B is the predicted box, and C is the minimum circumscribed matrix corresponding to the true box and the predicted box.