Pig posture recognition method, device and equipment, storage medium and program product
By using multi-layer feature extraction and fusion technology in the pig pose recognition model, the problem of high cost of pig pose recognition in the prior art is solved, and efficient and accurate pig pose recognition is achieved.
Patent Information
- Application Number
- CN202411392562.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2025-02-07
AI Technical Summary
In the prior art, pig posture recognition costs are relatively high, mainly because it requires a lot of manpower to make image judgments.
A pig pose recognition method is adopted to extract and fuse feature maps of different scales and levels by inputting pig images into multiple feature extraction layers and feature fusion layers in the pose recognition model, thereby generating high-resolution fusion feature maps , used to identify pig poses.
Low-cost pig posture recognition is achieved, improving the accuracy and efficiency of recognition, and reducing the need for manual judgment.
Smart Images

Figure CN119399832A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and in particular to a pig posture recognition method, device, equipment, storage medium and program product. Background Art
[0002] With the rapid development of science and technology, the pig farming industry is becoming more and more intelligent and modern. Among them, the results of pig posture recognition provide important references in pig behavior analysis, health monitoring, disease detection and large-scale farming management, which to a certain extent affects the farming efficiency and economic benefits. Therefore, pig posture recognition is a technical demand that needs to be urgently solved.
[0003] Currently, pig images are collected by cameras, and then the pig posture is manually judged based on the pig images. However, manual judgment requires a lot of manpower, resulting in a high cost for pig posture recognition. Summary of the invention
[0004] The present invention provides a pig posture recognition method, device, equipment, storage medium and program product, which are used to solve the defect of high cost of pig posture recognition in the prior art and realize low-cost pig posture recognition.
[0005] The present invention provides a pig posture recognition method, comprising: Inputting the pig image into the first feature extraction layer in the posture recognition model to obtain an initial feature map output by the first feature extraction layer; the first feature extraction layer is used to extract a feature map of a preset initial scale; Inputting the initial feature map into the second feature extraction layer in the gesture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer; the scale of the at least one hierarchical feature map is smaller than the preset initial scale, and the scales of the at least one hierarchical feature map are different; The initial feature map and the at least one hierarchical feature map are input into a feature fusion layer in the posture recognition model to obtain a fused feature map output by the feature fusion layer; the feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and perform feature fusion on each of the upsampled feature maps to obtain the fused feature map; Inputting the fused feature map into the posture recognition layer in the posture recognition model to obtain the pig posture recognition result output by the posture recognition layer; The posture recognition model is obtained by training based on sample pig images and pig posture labels corresponding to the sample pig images.
[0006] According to a pig posture recognition method provided by the present invention, any of the hierarchical feature graphs is extracted based on the hierarchical feature extraction layer in the second feature extraction layer, and the hierarchical feature graph is extracted based on the following method: Inputting the input feature map input to the hierarchical feature extraction layer into the downsampling layer in the hierarchical feature extraction layer to obtain the downsampling feature map output by the downsampling layer; the downsampling layer is used to segment the input feature map and splice the segmented feature maps in the channel dimension, so as to reduce the scale of the input feature map and increase the number of channels of the input feature map; The downsampled feature map is input to a third feature extraction layer in the hierarchical feature extraction layer to obtain the hierarchical feature map output by the third feature extraction layer; the scale of the hierarchical feature map is the same as the scale of the downsampled feature map.
[0007] According to a pig posture recognition method provided by the present invention, the number of channels of the initial feature map is a preset initial channel number; the initial feature map and the at least one hierarchical feature map are input into the feature fusion layer in the posture recognition model to obtain the fused feature map output by the feature fusion layer, including: Inputting the initial feature map and the at least one hierarchical feature map into the channel number unification layer in the feature fusion layer, obtaining the initial feature map with unified channel numbers and the at least one hierarchical feature map with unified channel numbers output by the channel number unification layer; the channel number unification layer is used to convert the input feature maps with different channel numbers into feature maps with the preset initial channel number; Inputting the initial feature map with a unified number of channels and at least one hierarchical feature map with a unified number of channels into the upsampling layer in the feature fusion layer to obtain a plurality of upsampling feature maps output by the upsampling layer; Each of the upsampled feature maps is input into the feature concatenation layer in the feature fusion layer to obtain a fused feature map output by the feature concatenation layer.
[0008] According to a pig posture recognition method provided by the present invention, the down-sampled feature map is input into a third feature extraction layer in the hierarchical feature extraction layer to obtain the hierarchical feature map output by the third feature extraction layer, including: Inputting the downsampled feature map into the first self-attention layer in the third feature extraction layer to obtain a first feature map output by the first self-attention layer; the first self-attention layer is used to divide the downsampled feature map into multiple windows for self-attention processing respectively; The first feature map is input into the second self-attention layer in the third feature extraction layer to obtain the hierarchical feature map output by the second self-attention layer; the second self-attention layer is used to divide the first feature map into multiple windows for self-attention processing, and to transfer information between the multiple windows after the first feature map is divided.
[0009] According to a pig posture recognition method provided by the present invention, the pig image is input into a first feature extraction layer in a posture recognition model to obtain an initial feature map output by the first feature extraction layer, including: Segment the pig image into multiple image blocks; Superimposing the multiple image blocks in the channel dimension to obtain an original feature map; the scale of the original feature map is the preset initial scale; The original feature map is input into the first feature extraction layer to obtain an initial feature map output by the first feature extraction layer.
[0010] According to a pig posture recognition method provided by the present invention, the posture recognition model is obtained by training based on a sample pig image, at least one target detection frame corresponding to the sample pig image, and a pig posture label corresponding to each target detection frame, and any target detection frame is used to mark the position of a pig in the sample pig image; The pig posture recognition result includes a position detection result of at least one pig and a posture detection result of the at least one pig.
[0011] The present invention also provides a pig posture recognition device, comprising: A first extraction module is used to input the pig image into the first feature extraction layer in the posture recognition model to obtain an initial feature map output by the first feature extraction layer; the first feature extraction layer is used to extract a feature map of a preset initial scale; A second extraction module is used to input the initial feature map into a second feature extraction layer in the gesture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer; the scale of the at least one hierarchical feature map is smaller than the preset initial scale, and the scales of the at least one hierarchical feature map are different; A feature fusion module, used to input the initial feature map and the at least one hierarchical feature map into a feature fusion layer in the posture recognition model to obtain a fused feature map output by the feature fusion layer; the feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and perform feature fusion on each of the upsampled feature maps to obtain the fused feature map; A posture recognition module, used for inputting the fused feature map into the posture recognition layer in the posture recognition model to obtain the pig posture recognition result output by the posture recognition layer; The posture recognition model is obtained by training based on sample pig images and pig posture labels corresponding to the sample pig images.
[0012] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, any of the above-mentioned pig posture recognition methods is implemented.
[0013] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the method for identifying pig posture as described above is implemented.
[0014] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned pig posture recognition methods.
[0015] The pig posture recognition method, device, equipment, storage medium and program product provided by the present invention input the pig image into the first feature extraction layer in the posture recognition model to obtain the initial feature map output by the first feature extraction layer, and the first feature extraction layer is used to extract the feature map of the preset initial scale, and the initial feature map is input into the second feature extraction layer in the posture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer, and the scale of at least one hierarchical feature map is smaller than the preset initial scale, and the scale of at least one hierarchical feature map is different, so that feature maps of different scales and different levels can be extracted, thereby further improving the feature extraction capability and ultimately improving the accuracy of pig posture recognition; the initial feature map and at least one hierarchical feature map are input into the feature fusion layer in the posture recognition model to obtain the fused feature map output by the feature fusion layer, and the feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and upsample each upsampled feature map. The sample feature maps are subjected to feature fusion to obtain a fused feature map. Based on this, the feature maps of different hierarchical scales extracted by the first feature extraction layer and the second feature extraction layer are fused to generate a fused feature map with deep semantic information and shallow feature information while reducing the loss of detail features, thereby improving its expression ability, and thus improving the recognition accuracy of the pig posture. Moreover, since the input feature maps of different scales are upsampled to upsampled feature maps with a scale of a preset initial scale, the scale of the fused feature map is the preset initial scale, that is, a high-resolution fused feature map is generated, thereby improving its expression ability, and thus improving the recognition accuracy of the pig posture. Finally, the high-resolution fused feature map with deep semantic information and shallow feature information is input into the posture recognition layer in the posture recognition model, and an accurate pig posture recognition result output by the posture recognition layer is obtained, so that there is no need to manually judge the pig posture, thereby reducing the recognition cost of the pig posture while ensuring the accuracy of the pig posture recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 It is a schematic flow chart of the pig posture recognition method provided by the present invention.
[0018] Figure 2 It is one of the structural schematic diagrams of the posture recognition model provided by the present invention.
[0019] Figure 3This is the second structural schematic diagram of the posture recognition model provided by the present invention.
[0020] Figure 4 It is a structural schematic diagram of the pig posture recognition device provided by the present invention.
[0021] Figure 5 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0022] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0023] Traditionally, the posture of pigs is mainly judged by on-site observation of pigs by pig farm staff or breeders. This method is extremely inconvenient and has high labor costs, especially for large-scale farms, and has the defects of low efficiency and poor real-time performance.
[0024] At present, pig images are collected by cameras, and then the pig posture is manually judged based on the pig images. Although the real-time performance has been improved to a certain extent, it has not significantly liberated manual labor. Manual judgment still requires a lot of manpower, resulting in a high cost for pig posture recognition. Even if the integrated and miniaturized smart wearable sensor device is worn under the pig's neck or ear, the pig information is collected without interfering with the normal activities of the pig as much as possible, so that the breeder can view the pig's current posture and related pig physiological information in real time through the monitoring results returned by the sensor device; however, compared with the traditional method, although this method has liberated manpower to a certain extent, in the actual pig farm scenario, the individual and group activities of pigs are prone to sensor damage and shedding, and the service life of the sensor equipment cannot be guaranteed, that is, the cost of pig posture recognition is still high.
[0025] In view of the above problems, the present invention proposes the following embodiments. Figure 1-Figure 3 The pig posture recognition method of the present invention is described.
[0026] Figure 1 : is a schematic diagram of the flow chart of the pig posture recognition method provided by the present invention, such as Figure 1 As shown, the pig posture recognition method includes the following steps 110, 120, 130 and 140.
[0027] Step 110: input the pig image into the first feature extraction layer in the posture recognition model to obtain an initial feature map output by the first feature extraction layer.
[0028] Here, the pig image is an image obtained by capturing images of pigs, such as using an image capture device to capture pig images, and the image capture device can be a camera, a video camera, or other equipment. The pig image can be an image of a sow, a piglet, or a group of pigs, so that a pig image can include one pig or multiple pigs. Further, the pig image is obtained by capturing images of a pig farm. Further, a pig video is first captured, and then a frame is extracted to obtain a pig image. In one embodiment, the pig image is an RGB image.
[0029] In one embodiment, a rail-type inspection robot equipped with a camera is used to capture images or collect videos of pigs in different pens and of different types. The collected videos need to be subsequently framed and saved as pig images.
[0030] Furthermore, the collected pig images are tested, and if it is detected that they do not meet the preset requirements, they are re-collected, thereby ensuring that the pig images with clear shooting and good angles are input into the posture recognition model, thereby improving the accuracy of pig posture recognition.
[0031] Furthermore, the pig image is preprocessed and then input into the posture recognition model. The preprocessing may include but is not limited to at least one of the following: scale adjustment, normalization processing, etc.
[0032] The posture recognition model is trained based on sample pig images and pig posture labels corresponding to the sample pig images. The posture recognition model is used to perform posture recognition on pig images to obtain pig posture recognition results.
[0033] Here, the sample pig images are also images obtained by collecting images of pigs. Further, the collected sample pig images are cleaned to retain the sample pig images with clear shooting and good angles, thereby improving the model training effect and further improving the accuracy of pig posture recognition; illustratively, RGB images containing pigs are collected, the data are cleaned, invalid data are eliminated, and sample pig images with clear normal images and complete pigs are screened out. Further, training sets and test sets are constructed respectively to train the posture recognition model.
[0034] Here, the pig posture label is obtained by annotating the sample pig image. For example, the pig posture label can be standing, lying on the side, lying prone, sitting, etc. Further, the posture recognition model is trained based on the sample pig image, at least one target detection frame corresponding to the sample pig image, and the pig posture label corresponding to each target detection frame; that is, the pigs in the sample pig image are first annotated with the target detection frame, and the pig posture label corresponding to the target detection frame is annotated, and the target detection frame can be a rectangular frame; that is, the sample pig image is annotated with the position and the pig posture label.
[0035] Furthermore, the pig image is divided into multiple image blocks, and the multiple image blocks are superimposed in the channel dimension to obtain an original feature map, the scale of which is a preset initial scale, so that the original feature map is input into the first feature extraction layer, thereby extracting feature information at different positions in the pig image, further improving the feature extraction capability, and then further improving the representation capability of image features, and ultimately improving the accuracy of pig posture recognition.
[0036] The first feature extraction layer is used to extract a feature map of a preset initial scale. That is, the first feature extraction layer is used to extract features from the pig image to obtain an initial feature map of a preset initial scale. The preset initial scale can be set according to actual needs.
[0037] In one embodiment, the first feature extraction layer includes a linear embedding layer, and the pig image is feature mapped to obtain an initial feature map. Further, the first feature extraction layer includes a linear embedding layer, a first self-attention layer, and a second self-attention layer connected in sequence; specifically, the pig image is input into the linear embedding layer, and the feature map output by the linear embedding layer is input into the first self-attention layer to obtain the second feature map output by the first self-attention layer; the first self-attention layer is used to divide the input feature map into multiple windows for self-attention processing respectively; the second feature map is input into the second self-attention layer to obtain the initial feature map output by the second self-attention layer; the second self-attention layer is used to divide the second feature map into multiple windows for self-attention processing, and to enable information transfer between the multiple windows after the second feature map is divided.
[0038] Step 120: input the initial feature map to the second feature extraction layer in the gesture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer.
[0039] The scale of at least one hierarchical feature map is smaller than the preset initial scale, and the scales of at least one hierarchical feature map are different. That is, the second feature extraction layer can continuously extract features of the initial feature map, and can extract hierarchical feature maps of different scales and levels, thereby further improving the feature extraction capability and ultimately improving the accuracy of pig posture recognition.
[0040] Here, the second feature extraction layer includes at least one downsampling layer to obtain a hierarchical feature map with a scale smaller than a preset initial scale, and ensure that the scale of at least one hierarchical feature map is different. Further, the downsampling layer is used to segment the input feature map and splice the segmented feature maps in the channel dimension to reduce the scale of the input feature map and increase the number of channels of the input feature map.
[0041] Step 130: input the initial feature map and the at least one hierarchical feature map into a feature fusion layer in the gesture recognition model to obtain a fused feature map output by the feature fusion layer.
[0042] The feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps of the preset initial scale, and perform feature fusion on each of the upsampled feature maps to obtain the fused feature map, that is, to fuse the feature maps of different hierarchical scales extracted by the first feature extraction layer and the second feature extraction layer.
[0043] In one embodiment, the initial feature map and at least one hierarchical feature map are input into an upsampling layer in a feature fusion layer to obtain a plurality of upsampling feature maps output by the upsampling layer; each upsampling feature map is input into a feature splicing layer in a feature fusion layer to obtain a fused feature map output by the feature splicing layer.
[0044] Considering that in the feature extraction process of the second feature extraction layer, the resolution of the hierarchical feature map is continuously reduced, which will cause the loss of some detail features; based on this, the input feature maps of different scales are upsampled to upsampled feature maps with a scale of a preset initial scale, and the upsampled feature maps are feature fused to obtain a fused feature map, that is, the feature maps of different scales are fused, and while reducing the loss of detail features, a fused feature map with deep semantic information and shallow feature information is generated, thereby improving its expression ability, and then improving the recognition accuracy of pig posture; and because the input feature maps of different scales are upsampled to upsampled feature maps with a scale of a preset initial scale, the scale of the fused feature map is the preset initial scale, that is, a high-resolution fused feature map is generated, thereby improving its expression ability, and then improving the recognition accuracy of pig posture. That is, the feature fusion operation can reduce the loss of some features and improve the expression ability of the model.
[0045] Step 140: input the fused feature map into the posture recognition layer in the posture recognition model to obtain the pig posture recognition result output by the posture recognition layer.
[0046] Here, the posture recognition layer is used to obtain the pig posture recognition result based on the fusion feature map recognition. For example, the posture recognition layer is a detection head to detect and obtain the pig posture recognition result. Furthermore, the detection head is an Anchor-Free (no anchor point detection) detection head, so as to obtain a more accurate pig posture recognition result.
[0047] Furthermore, the pig posture recognition result includes the pig position detection result and the pig posture detection result, so that not only the identified pig can be located, but also the pig's posture can be identified, so that the user can better view the pig posture recognition result and improve the user experience.
[0048] The pig posture recognition method provided by the embodiment of the present invention inputs the pig image into the first feature extraction layer in the posture recognition model to obtain the initial feature map output by the first feature extraction layer, and the first feature extraction layer is used to extract the feature map of the preset initial scale, and the initial feature map is input into the second feature extraction layer in the posture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer, and the scale of at least one hierarchical feature map is smaller than the preset initial scale, and the scale of at least one hierarchical feature map is different, so that feature maps of different scales and different levels can be extracted, thereby further improving the feature extraction capability and ultimately improving the accuracy of pig posture recognition; the initial feature map and at least one hierarchical feature map are input into the feature fusion layer in the posture recognition model to obtain the fused feature map output by the feature fusion layer, and the feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and perform feature fusion on each upsampled feature map The features are fused to obtain a fused feature map, based on which the feature maps of different hierarchical scales extracted by the first feature extraction layer and the second feature extraction layer are fused, and a fused feature map with deep semantic information and shallow feature information is generated while reducing the loss of detail features, thereby improving its expression ability, and thus improving the recognition accuracy of pig posture. Moreover, since the input feature maps of different scales are upsampled to upsampled feature maps with a scale of a preset initial scale, the scale of the fused feature map is the preset initial scale, that is, a high-resolution fused feature map is generated, thereby improving its expression ability, and thus improving the recognition accuracy of pig posture. Finally, the high-resolution fused feature map with deep semantic information and shallow feature information is input into the posture recognition layer in the posture recognition model, and an accurate pig posture recognition result output by the posture recognition layer is obtained, so that there is no need to manually judge the pig posture, thereby reducing the recognition cost of the pig posture while ensuring the accuracy of the pig posture recognition.
[0049] Based on any of the above embodiments, any of the hierarchical feature maps is extracted based on the hierarchical feature extraction layer in the second feature extraction layer, and the hierarchical feature map is extracted based on the following method: Inputting the input feature map input to the hierarchical feature extraction layer into the downsampling layer in the hierarchical feature extraction layer to obtain the downsampling feature map output by the downsampling layer; the downsampling layer is used to segment the input feature map and splice the segmented feature maps in the channel dimension, so as to reduce the scale of the input feature map and increase the number of channels of the input feature map; The downsampled feature map is input to a third feature extraction layer in the hierarchical feature extraction layer to obtain the hierarchical feature map output by the third feature extraction layer; the scale of the hierarchical feature map is the same as the scale of the downsampled feature map.
[0050] It should be noted that the second feature extraction layer includes at least one hierarchical feature extraction layer connected in sequence to extract at least one hierarchical feature map.
[0051] Here, the downsampling layer is used to perform downsampling processing to produce a hierarchical representation. In one embodiment, the downsampling layer is used to segment the input feature map, and splice the segmented feature map in the channel dimension, so that the scale of the input feature map is reduced to half of the original scale, and the number of channels of the input feature map is increased to twice the original scale; that is, the scale of the downsampled feature map is half of the scale of the input feature map, and the number of channels of the downsampled feature map is twice the number of channels of the input feature map. Exemplarily, the downsampling layer is used to extract four small matrices from a matrix of the input feature map at intervals, and then splice (concat) the four matrices in the channel dimension, and then after layer normalization (LayerNorm) processing, map them into 2 channels through a linear layer. Based on this, the scale of the input feature map is reduced to half of the original scale, and the number of channels of the input feature map is increased to twice the original scale.
[0052] Here, the third feature extraction layer is used to extract features from the downsampled feature map to obtain a hierarchical feature map without changing the scale of the downsampled feature map. If the third feature extraction layer is followed by a hierarchical feature extraction layer, the hierarchical feature map is used as the input feature map of the next hierarchical feature extraction layer.
[0053] For ease of understanding, a specific embodiment is used for illustration. Figure 2As shown, the second feature extraction layer includes three hierarchical feature extraction layers connected in sequence, namely, a first-level feature extraction layer, a second-level feature extraction layer and a third-level feature extraction layer. Any hierarchical feature extraction layer includes a downsampling layer and a third feature extraction layer. Specifically, the initial feature map is input into the first-level feature extraction layer to obtain a first-level feature map output by the first-level feature extraction layer. The first-level feature map is input into the second-level feature extraction layer to obtain a second-level feature map output by the second-level feature extraction layer. The second-level feature map is input into the third-level feature extraction layer to obtain a third-level feature map output by the third-level feature extraction layer. Then, the initial feature map, the first-level feature map, the second-level feature map and the third-level feature map of different scales are input into the feature fusion layer to obtain a fused feature map output by the feature fusion layer.
[0054] The pig posture recognition method provided by the embodiment of the present invention inputs the input feature map input to the hierarchical feature extraction layer into the downsampling layer in the hierarchical feature extraction layer to obtain the downsampling feature map output by the downsampling layer, and the downsampling layer is used to segment the input feature map, and splice the segmented feature map in the channel dimension to reduce the scale of the input feature map and increase the number of channels of the input feature map, so that the downsampling feature map is input to the third feature extraction layer in the hierarchical feature extraction layer to obtain the hierarchical feature map with stronger representation ability output by the third feature extraction layer, that is, improve its expression ability, thereby improving the recognition accuracy of the pig posture.
[0055] Based on any of the above embodiments, considering that the downsampling layer is used to segment the input feature map, and the segmented feature map is spliced in the channel dimension to increase the number of channels of the input feature map; based on this, the number of channels of the initial feature map is the preset initial channel number, the above step 130 includes: Inputting the initial feature map and the at least one hierarchical feature map into a channel number unification layer in the feature fusion layer, and obtaining an initial feature map with unified channel numbers and at least one hierarchical feature map with unified channel numbers output by the channel number unification layer; Inputting the initial feature map with a unified number of channels and at least one hierarchical feature map with a unified number of channels into the upsampling layer in the feature fusion layer to obtain a plurality of upsampling feature maps output by the upsampling layer; Each of the upsampled feature maps is input into the feature concatenation layer in the feature fusion layer to obtain a fused feature map output by the feature concatenation layer.
[0056] Among them, the channel number unification layer is used to convert the input feature maps with different channel numbers into feature maps with the preset initial channel number. That is, the channel numbers of feature maps with different channel numbers are unified to the preset initial channel number. Based on this, it is convenient to fuse the feature maps with different channel numbers extracted by the first feature extraction layer and the second feature extraction layer. That is, the channel numbers of the initial feature map after the channel number is unified and the channel number of at least one level feature map after the channel number is unified are both the preset initial channel number.
[0057] In one embodiment, the layer with the same number of channels can be constructed by MLP (Multilayer Perceptron).
[0058] It should be noted that since the downsampling layer is used to segment the input feature map and concatenate the segmented feature map in the channel dimension to increase the number of channels of the input feature map, before feature fusion, it is necessary to unify the number of channels of the initial feature map and at least one level feature map to facilitate the subsequent fusion of feature maps of different scales.
[0059] Here, the upsampling layer is used to upsample the initial feature map after the number of channels is unified and the at least one level feature map after the number of channels is unified into an upsampled feature map with a scale of a preset initial scale.
[0060] Here, the feature concatenation layer is used to concatenate the upsampled feature maps of the same scale and the same number of channels to obtain a fused feature map.
[0061] For ease of understanding, a specific embodiment is used for illustration. Figure 3 As shown, assuming that the initial feature map and the three-level feature maps are F1, F2, F3 and F4 respectively, the feature fusion layer includes a channel number unification layer, an upsampling layer and a feature concatenation layer in the dotted box, wherein the scale of the feature map after processing by the upsampling layer is increased. Specifically, the initial feature map F1 and the three-level feature maps F2, F3, F4 are input into the feature fusion layer to obtain a fused feature map F output by the feature fusion layer.
[0062] In one embodiment, the preset initial scale may be one quarter of the input pig image, so that the scale of the upsampled feature map obtained by upsampling may be one quarter of the pig image.
[0063] The pig posture recognition method provided by the embodiment of the present invention inputs the initial feature map and at least one hierarchical feature map into the channel number unification layer in the feature fusion layer, obtains the initial feature map with unified channel number output by the channel number unification layer and at least one hierarchical feature map with unified channel number, and inputs the initial feature map with unified channel number and at least one hierarchical feature map with unified channel number into the upsampling layer in the feature fusion layer, so that before feature fusion, the initial feature map and at least one hierarchical feature map are first unified in channel number, so as to facilitate better fusion of feature maps of different scales, and finally obtain a fused feature map with stronger representation ability, that is, improve its expression ability, thereby improving the recognition accuracy of pig posture.
[0064] Based on any of the foregoing embodiments, the step of inputting the downsampled feature map to a third feature extraction layer in the hierarchical feature extraction layer to obtain the hierarchical feature map output by the third feature extraction layer includes: Inputting the downsampled feature map into a first self-attention layer in the third feature extraction layer to obtain a first feature map output by the first self-attention layer; The first feature map is input into the second self-attention layer in the third feature extraction layer to obtain the hierarchical feature map output by the second self-attention layer.
[0065] Among them, the first self-attention layer is used to divide the downsampled feature map into multiple windows for self-attention processing respectively, so as to better extract local features, that is, improve its expression ability, and then improve the recognition accuracy of pig posture.
[0066] In one embodiment, the first self-attention layer includes a W-MSA (Window Multi-head Self-Attention) module, so that while the downsampled feature map is divided into multiple windows for self-attention processing, the computational complexity can be further reduced, thereby reducing the amount of calculation and improving the recognition efficiency of the pig posture. Multiple windows of different sizes are processed with self-attention respectively.
[0067] Furthermore, the first self-attention layer includes a first normalization layer (Layer Norm), a W-MSA module, a first feature fusion module, a second normalization layer, a multi-layer perceptron (MLP) layer, and a second feature fusion module connected in sequence. Specifically, the downsampled feature map is input into the first normalization layer, and then the feature map output by the first normalization layer is input into the W-MSA module, and then the feature map output by the W-MSA module and the downsampled feature map are input into the first feature fusion module, the feature map output by the first feature fusion module is input into the second normalization layer, the feature map output by the second normalization layer is input into the multi-layer perceptron layer, the feature map output by the multi-layer perceptron layer and the feature map output by the first feature fusion module are input into the second feature fusion module, and the first feature map output by the second feature fusion module is obtained.
[0068] Among them, the second self-attention layer is used to divide the first feature map into multiple windows for self-attention processing, and to transfer information between the multiple windows after the first feature map is divided, so as to better perform global feature extraction, and can extract the contextual dependencies of different positions in the pig image, that is, improve its expressive ability, and thus improve the recognition accuracy of the pig posture.
[0069] In one embodiment, the second self-attention layer includes a SW-MSA (Shifted Windows Multi-head Self-Attention) module, so that while the downsampled feature map is divided into multiple windows for self-attention processing respectively, information can be transferred between the multiple windows after the first feature map is divided, so that the contextual dependencies of different positions in the pig image can be extracted.
[0070] Furthermore, the second self-attention layer includes a third standardization layer, a SW-MSA module, a third feature fusion module, a fourth standardization layer, a multi-layer perceptron layer and a fourth feature fusion module connected in sequence. Specifically, the first feature map is input into the third standardization layer, and then the feature map output by the third standardization layer is input into the SW-MSA module, and then the feature map output by the SW-MSA module and the first feature map are input into the third feature fusion module, and the feature map output by the third feature fusion module is input into the fourth standardization layer, and the feature map output by the fourth standardization layer is input into the multi-layer perceptron layer, and the feature map output by the multi-layer perceptron layer and the feature map output by the third feature fusion module are input into the fourth feature fusion module, and the hierarchical feature map output by the fourth feature fusion module is obtained.
[0071] Further, the third feature extraction layer may include a plurality of consecutive first self-attention layers and second self-attention layers. For example, the third feature extraction layer includes a first self-attention layer, a second self-attention layer, a first self-attention layer, and a second self-attention layer connected in sequence.
[0072] The pig posture recognition method provided by the embodiment of the present invention inputs the downsampled feature map into the first self-attention layer in the third feature extraction layer to obtain the first feature map output by the first self-attention layer, and the first self-attention layer is used to divide the downsampled feature map into multiple windows for self-attention processing respectively, and inputs the first feature map into the second self-attention layer in the third feature extraction layer to obtain the hierarchical feature map output by the second self-attention layer, and the second self-attention layer is used to divide the first feature map into multiple windows for self-attention processing, and information is transferred between the multiple windows after the first feature map is divided, so that the input pig image can be effectively extracted with local features and global features, that is, its expression ability is improved, thereby improving the recognition accuracy of the pig posture.
[0073] Based on any of the above embodiments, in the method, the above step 110 includes: Segment the pig image into multiple image blocks; Superimposing the multiple image blocks in the channel dimension to obtain an original feature map; the scale of the original feature map is the preset initial scale; The original feature map is input into the first feature extraction layer to obtain an initial feature map output by the first feature extraction layer.
[0074] Specifically, the pig image is divided into a plurality of image patches, thereby obtaining a plurality of image patches of a preset initial scale. Further, the pig image is divided into a plurality of image patches of the same size. For example, the pig image is divided into 4 image patches of the same size, thereby obtaining a plurality of image patches of a preset initial scale. The output size of the pig image after segmentation and superposition is The original feature map of .
[0075] For example, if the pig image is an RGB image, multiple image blocks are superimposed on the color channel dimension to obtain the original feature map.
[0076] In one embodiment, the first feature extraction layer includes a linear embedding layer, so that the original feature map is feature mapped to obtain an initial feature map. Further, the first feature extraction layer includes a linear embedding layer, a first self-attention layer, and a second self-attention layer connected in sequence; specifically, the original feature map is input into the linear embedding layer, and the feature map output by the linear embedding layer is input into the first self-attention layer to obtain a second feature map output by the first self-attention layer; the first self-attention layer is used to divide the input feature map into multiple windows for self-attention processing respectively; the second feature map is input into the second self-attention layer to obtain the initial feature map output by the second self-attention layer; the second self-attention layer is used to divide the second feature map into multiple windows for self-attention processing, and to enable information transfer between the multiple windows after the second feature map is divided.
[0077] In one embodiment, the pig image is segmented into a plurality of image patches, and the linear embedding layer can be implemented by a two-dimensional convolution.
[0078] The pig posture recognition method provided by the embodiment of the present invention divides the pig image into multiple image blocks, superimposes the multiple image blocks in the channel dimension to obtain an original feature map, and inputs the original feature map to the first feature extraction layer to obtain an initial feature map output by the first feature extraction layer, thereby more accurately capturing the feature information of different positions in the pig image, further improving the feature extraction capability, and further improving the image feature representation capability, thereby ultimately improving the accuracy of pig posture recognition.
[0079] Based on any of the above embodiments, the posture recognition model is trained based on a sample pig image, at least one target detection frame corresponding to the sample pig image, and a pig posture label corresponding to each target detection frame, and any one of the target detection frames is used to mark the position of a pig in the sample pig image; the pig posture recognition result includes a position detection result of at least one pig and a posture detection result of the at least one pig.
[0080] It should be noted that the pigs in the sample pig image are first annotated with a target detection frame, and then the pig posture labels corresponding to the target detection frame are annotated, that is, the sample pig image is annotated with a position and a pig posture label. For example, the target detection frame can be a rectangular frame.
[0081] The pig posture recognition method provided by the embodiment of the present invention has a posture recognition model that is trained based on a sample pig image, at least one target detection frame corresponding to the sample pig image, and a pig posture label corresponding to each target detection frame, and any target detection frame is used to mark the position of a pig in the sample pig image, so that the pig posture recognition result includes the position detection result of at least one pig and the posture detection result of at least one pig. Based on this, not only can the identified pig be accurately located, but the posture of the pig can also be accurately identified, so that the user can better view the pig posture recognition result and improve the user experience; in addition, pig posture recognition can be directly performed on a pig image including multiple pigs, without the need to first perform image segmentation and then perform posture recognition separately, thereby improving the recognition efficiency of the pig posture.
[0082] Based on any of the above embodiments, the posture recognition model is obtained by training based on a loss function, and the loss function includes at least one of a center point loss function, a center point offset loss function, and a target width and height loss function.
[0083] In one embodiment, the gesture recognition layer uses three different convolution operations to respectively predict the heat map, the center point, and the width and height.
[0084] In a specific embodiment, the real target center point generates a real heat map after passing through the Gaussian kernel function, and its number is the number of target categories. During training, the target center point prediction heat map output by the model is compared with the real heat map. The center point loss function is as follows: ; In the formula, Represents the center point loss value; Indicates the number of key points in the image; Represents the predicted value on the heat map; Indicates that for category C, an object of category C is detected in the current (x, y) coordinate; , denote hyperparameters, for example, they are set to 2 and 4 respectively.
[0085] In a specific embodiment, after the target center point predicted on the sampled feature map is remapped to the original image, there will be a certain displacement deviation, so the displacement deviation of the predicted center point is introduced to compensate. The center point offset loss function of the predicted center point offset and the real center point offset is as follows: ; In the formula, Indicates the center point offset loss value; Indicates the number of key points in the image; Indicates the center point of the target box; Indicates the predicted center point offset; Indicates the downsampling multiple; Indicates the actual offset.
[0086] In one specific embodiment, assuming the category is Object The bounding box of , then the width and height of the target object can be expressed as: , the target width and height loss function for calculating width and height is as follows: ; In the formula, Indicates the target width and height loss value; Indicates the number of key points in the image; Represents the predicted value of the target width and height; Indicates the true value of the target width and height.
[0087] In one embodiment, the loss function of the gesture recognition model is as follows: L= .
[0088] Furthermore, during the model training phase, you can set , .
[0089] Based on the above embodiments, the use of computer vision and deep learning methods to recognize the posture of pigs not only has the advantages of accuracy and speed, but also reduces costs and is more conducive to improving the economic benefits of pig farming.
[0090] The pig posture recognition device provided by the present invention is described below. The pig posture recognition device described below and the pig posture recognition method described above can be referred to each other.
[0091] Figure 4 Schematic diagram of the structure of the pig posture recognition device provided by the present invention. Figure 4 As shown, the pig posture recognition device includes a first extraction module 410 , a second extraction module 420 , a feature fusion module 430 and a posture recognition module 440 .
[0092] The first extraction module 410 is used to input the pig image into the first feature extraction layer in the posture recognition model to obtain an initial feature map output by the first feature extraction layer; the first feature extraction layer is used to extract a feature map of a preset initial scale.
[0093] The second extraction module 420 is used to input the initial feature map into the second feature extraction layer in the posture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer; the scale of the at least one hierarchical feature map is smaller than the preset initial scale, and the scales of the at least one hierarchical feature map are different.
[0094] The feature fusion module 430 is used to input the initial feature map and the at least one hierarchical feature map into the feature fusion layer in the posture recognition model to obtain a fused feature map output by the feature fusion layer; the feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and perform feature fusion on each of the upsampled feature maps to obtain the fused feature map.
[0095] The posture recognition module 440 is used to input the fused feature map into the posture recognition layer in the posture recognition model to obtain the pig posture recognition result output by the posture recognition layer.
[0096] The posture recognition model is obtained by training based on sample pig images and pig posture labels corresponding to the sample pig images.
[0097] The pig posture recognition device provided by the embodiment of the present invention inputs the pig image into the first feature extraction layer in the posture recognition model to obtain the initial feature map output by the first feature extraction layer, and the first feature extraction layer is used to extract the feature map of the preset initial scale, and the initial feature map is input into the second feature extraction layer in the posture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer, and the scale of at least one hierarchical feature map is smaller than the preset initial scale, and the scale of at least one hierarchical feature map is different, so that feature maps of different scales and levels can be extracted, thereby further improving the feature extraction capability and ultimately improving the accuracy of pig posture recognition; the initial feature map and at least one hierarchical feature map are input into the feature fusion layer in the posture recognition model to obtain the fused feature map output by the feature fusion layer, and the feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and perform feature fusion on each upsampled feature map The features are fused to obtain a fused feature map, based on which the feature maps of different hierarchical scales extracted by the first feature extraction layer and the second feature extraction layer are fused, and a fused feature map with deep semantic information and shallow feature information is generated while reducing the loss of detail features, thereby improving its expression ability, and thus improving the recognition accuracy of pig posture. Moreover, since the input feature maps of different scales are upsampled to upsampled feature maps with a scale of a preset initial scale, the scale of the fused feature map is the preset initial scale, that is, a high-resolution fused feature map is generated, thereby improving its expression ability, and thus improving the recognition accuracy of pig posture. Finally, the high-resolution fused feature map with deep semantic information and shallow feature information is input into the posture recognition layer in the posture recognition model, and an accurate pig posture recognition result output by the posture recognition layer is obtained, so that there is no need to manually judge the pig posture, thereby reducing the recognition cost of the pig posture while ensuring the accuracy of the pig posture recognition.
[0098] Based on any of the above embodiments, any of the hierarchical feature maps is extracted based on the hierarchical feature extraction layer in the second feature extraction layer, and the second extraction module 420 is further used for: Inputting the input feature map input to the hierarchical feature extraction layer into the downsampling layer in the hierarchical feature extraction layer to obtain the downsampling feature map output by the downsampling layer; the downsampling layer is used to segment the input feature map and splice the segmented feature maps in the channel dimension, so as to reduce the scale of the input feature map and increase the number of channels of the input feature map; The downsampled feature map is input to a third feature extraction layer in the hierarchical feature extraction layer to obtain the hierarchical feature map output by the third feature extraction layer; the scale of the hierarchical feature map is the same as the scale of the downsampled feature map.
[0099] Based on any of the above embodiments, the second extraction module 420 is further used for: Inputting the initial feature map and the at least one hierarchical feature map into the channel number unification layer in the feature fusion layer, obtaining the initial feature map with unified channel numbers and the at least one hierarchical feature map with unified channel numbers output by the channel number unification layer; the channel number unification layer is used to convert the input feature maps with different channel numbers into feature maps with the preset initial channel number; Inputting the initial feature map with a unified number of channels and at least one hierarchical feature map with a unified number of channels into the upsampling layer in the feature fusion layer to obtain a plurality of upsampling feature maps output by the upsampling layer; Each of the upsampled feature maps is input into the feature concatenation layer in the feature fusion layer to obtain a fused feature map output by the feature concatenation layer.
[0100] Based on any of the above embodiments, the second extraction module 420 is further used for: Inputting the downsampled feature map into the first self-attention layer in the third feature extraction layer to obtain a first feature map output by the first self-attention layer; the first self-attention layer is used to divide the downsampled feature map into multiple windows for self-attention processing respectively; The first feature map is input into the second self-attention layer in the third feature extraction layer to obtain the hierarchical feature map output by the second self-attention layer; the second self-attention layer is used to divide the first feature map into multiple windows for self-attention processing, and to transfer information between the multiple windows after the first feature map is divided.
[0101] Based on any of the above embodiments, the first extraction module 410 is further used for: Segment the pig image into multiple image blocks; Superimposing the multiple image blocks in the channel dimension to obtain an original feature map; the scale of the original feature map is the preset initial scale; The original feature map is input into the first feature extraction layer to obtain an initial feature map output by the first feature extraction layer.
[0102] Based on any of the above embodiments, the posture recognition model is trained based on a sample pig image, at least one target detection frame corresponding to the sample pig image, and a pig posture label corresponding to each target detection frame, and any one of the target detection frames is used to mark the position of a pig in the sample pig image; the pig posture recognition result includes a position detection result of at least one pig and a posture detection result of the at least one pig.
[0103] Figure 5 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 5 As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute the pig posture recognition method, which includes: inputting the pig image into the first feature extraction layer in the posture recognition model to obtain the initial feature map output by the first feature extraction layer; the first feature extraction layer is used to extract the feature map of the preset initial scale; the initial feature map is input into the second feature extraction layer in the posture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer; the scale of the at least one hierarchical feature map is smaller than the preset initial scale, and the scales of the at least one hierarchical feature map are different ... The feature map and the at least one hierarchical feature map are input into the feature fusion layer in the posture recognition model to obtain a fused feature map output by the feature fusion layer; the feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and perform feature fusion on each of the upsampled feature maps to obtain the fused feature map; the fused feature map is input into the posture recognition layer in the posture recognition model to obtain the pig posture recognition result output by the posture recognition layer; wherein the posture recognition model is trained based on sample pig images and pig posture labels corresponding to the sample pig images.
[0104] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0105] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the pig posture recognition method provided by the above methods, and the method includes: inputting the pig image into the first feature extraction layer in the posture recognition model to obtain an initial feature map output by the first feature extraction layer; the first feature extraction layer is used to extract a feature map of a preset initial scale; the initial feature map is input into the second feature extraction layer in the posture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer; the scale of the at least one hierarchical feature map is smaller than the scale of the The preset initial scale, the scale of at least one hierarchical feature map is different; the initial feature map and the at least one hierarchical feature map are input into the feature fusion layer in the posture recognition model to obtain a fused feature map output by the feature fusion layer; the feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and perform feature fusion on each of the upsampled feature maps to obtain the fused feature map; the fused feature map is input into the posture recognition layer in the posture recognition model to obtain the pig posture recognition result output by the posture recognition layer; wherein the posture recognition model is trained based on sample pig images and pig posture labels corresponding to the sample pig images.
[0106] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the pig posture recognition method provided by the above-mentioned methods, the method comprising: inputting a pig image into a first feature extraction layer in a posture recognition model to obtain an initial feature map output by the first feature extraction layer; the first feature extraction layer is used to extract a feature map of a preset initial scale; the initial feature map is input into a second feature extraction layer in the posture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer; the scale of the at least one hierarchical feature map is smaller than the preset initial scale, and the at least one hierarchical feature map is output by the second feature extraction layer; The scales of the level feature maps are all different; the initial feature map and the at least one level feature map are input into the feature fusion layer in the posture recognition model to obtain a fused feature map output by the feature fusion layer; the feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and perform feature fusion on each of the upsampled feature maps to obtain the fused feature map; the fused feature map is input into the posture recognition layer in the posture recognition model to obtain the pig posture recognition result output by the posture recognition layer; wherein the posture recognition model is trained based on sample pig images and pig posture labels corresponding to the sample pig images.
[0107] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0108] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0109] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for pig posture recognition, characterized in that: include: Inputting the pig image into a first feature extraction layer in a posture recognition model to obtain an initial feature map output by the first feature extraction layer; The first feature extraction layer is used to extract a feature map of a preset initial scale; Inputting the initial feature map into a second feature extraction layer in the gesture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer; The scale of the at least one hierarchical feature map is smaller than the preset initial scale, and the scales of the at least one hierarchical feature map are different; Inputting the initial feature map and the at least one hierarchical feature map into a feature fusion layer in the gesture recognition model to obtain a fused feature map output by the feature fusion layer; The feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and perform feature fusion on each of the upsampled feature maps to obtain the fused feature map; Inputting the fused feature map into the posture recognition layer in the posture recognition model to obtain the pig posture recognition result output by the posture recognition layer; The posture recognition model is obtained by training based on sample pig images and pig posture labels corresponding to the sample pig images.
2. The pig posture recognition method according to claim 1, characterized in that: Any of the hierarchical feature maps is extracted based on the hierarchical feature extraction layer in the second feature extraction layer, and the hierarchical feature map is extracted based on the following method: Inputting the input feature map input to the hierarchical feature extraction layer into the downsampling layer in the hierarchical feature extraction layer to obtain the downsampling feature map output by the downsampling layer; the downsampling layer is used to segment the input feature map and splice the segmented feature maps in the channel dimension, so as to reduce the scale of the input feature map and increase the number of channels of the input feature map; The downsampled feature map is input to a third feature extraction layer in the hierarchical feature extraction layer to obtain the hierarchical feature map output by the third feature extraction layer; the scale of the hierarchical feature map is the same as the scale of the downsampled feature map.
3. The pig posture recognition method according to claim 2, characterized in that: The number of channels of the initial feature map is a preset initial channel number; the initial feature map and the at least one hierarchical feature map are input into a feature fusion layer in the gesture recognition model to obtain a fused feature map output by the feature fusion layer, including: Inputting the initial feature map and the at least one hierarchical feature map into the channel number unification layer in the feature fusion layer, obtaining the initial feature map with unified channel numbers and the at least one hierarchical feature map with unified channel numbers output by the channel number unification layer; the channel number unification layer is used to convert the input feature maps with different channel numbers into feature maps with the preset initial channel number; Inputting the initial feature map with a unified number of channels and at least one hierarchical feature map with a unified number of channels into the upsampling layer in the feature fusion layer to obtain a plurality of upsampling feature maps output by the upsampling layer; Each of the upsampled feature maps is input into the feature concatenation layer in the feature fusion layer to obtain a fused feature map output by the feature concatenation layer.
4. The pig posture recognition method according to claim 2, characterized in that: The step of inputting the downsampled feature map to a third feature extraction layer in the hierarchical feature extraction layer to obtain the hierarchical feature map output by the third feature extraction layer comprises: Inputting the downsampled feature map into the first self-attention layer in the third feature extraction layer to obtain a first feature map output by the first self-attention layer; the first self-attention layer is used to divide the downsampled feature map into multiple windows for self-attention processing respectively; The first feature map is input into the second self-attention layer in the third feature extraction layer to obtain the hierarchical feature map output by the second self-attention layer; the second self-attention layer is used to divide the first feature map into multiple windows for self-attention processing, and to transfer information between the multiple windows after the first feature map is divided.
5. The pig posture recognition method according to claim 1, characterized in that: The step of inputting the pig image into the first feature extraction layer in the posture recognition model to obtain an initial feature map output by the first feature extraction layer includes: Segment the pig image into multiple image blocks; Superimposing the multiple image blocks in the channel dimension to obtain an original feature map; the scale of the original feature map is the preset initial scale; The original feature map is input into the first feature extraction layer to obtain an initial feature map output by the first feature extraction layer.
6. The method for pig posture recognition according to any one of claims 1 to 5, characterized in that: The posture recognition model is trained based on a sample pig image, at least one target detection frame corresponding to the sample pig image, and a pig posture label corresponding to each target detection frame, wherein any target detection frame is used to mark the position of a pig in the sample pig image; The pig posture recognition result includes a position detection result of at least one pig and a posture detection result of the at least one pig.
7. A pig posture recognition device, characterized in that: include: A first extraction module, used for inputting the pig image into a first feature extraction layer in the posture recognition model to obtain an initial feature map output by the first feature extraction layer; The first feature extraction layer is used to extract a feature map of a preset initial scale; A second extraction module, configured to input the initial feature map into a second feature extraction layer in the gesture recognition model to obtain at least one hierarchical feature map output by the second feature extraction layer; The scale of the at least one hierarchical feature map is smaller than the preset initial scale, and the scales of the at least one hierarchical feature map are different; A feature fusion module, used for inputting the initial feature map and the at least one hierarchical feature map into a feature fusion layer in the gesture recognition model to obtain a fused feature map output by the feature fusion layer; The feature fusion layer is used to upsample the input feature maps of different scales into upsampled feature maps with a scale of the preset initial scale, and perform feature fusion on each of the upsampled feature maps to obtain the fused feature map; A posture recognition module, used for inputting the fused feature map into the posture recognition layer in the posture recognition model to obtain the pig posture recognition result output by the posture recognition layer; The posture recognition model is obtained by training based on sample pig images and pig posture labels corresponding to the sample pig images.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the pig posture recognition method according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the pig posture recognition method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the pig posture recognition method according to any one of claims 1 to 6 is implemented.