Pig re-identification method and device based on instance segmentation, medium and equipment
Through the pig-limit recognition method based on instance segmentation, using infrared images and instance segmentation models for feature extraction and object detection, the problem of misidentification and misidentification in complex scenarios is solved, and high accuracy and convenient pig-limit recognition are achieved.
Patent Information
- Application Number
- CN202510122116.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-26
- Publication Date
- 2025-05-30
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional pig-only recognition methods are prone to misidentification or misidentification problems in complex scenarios, and have limitations such as low accuracy, inconvenient management, and influenced by environmental factors.
The pig's re-identification method based on instance segmentation is adopted. By obtaining the infrared image of the pig, inputting it into the trained instance segmentation model, feature extraction and object detection are used using convolutional neural network and candidate region generation algorithm, and the final object detection box and object segmentation results are obtained through multiple bilinear interpolation and target segmentation.
It improves the accuracy of pig identification, has good adaptability, accuracy and convenience, and is suitable for a wide range of daily pig monitoring and management scenarios.
Smart Images

Figure CN120071393A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of intelligent agriculture technology, and particularly relates to a method, device, storage medium and electronic device for pig weight recognition based on instance segmentation. Background Art
[0002] Pig weight recognition, as a key research area in the livestock industry, has far-reaching significance in improving breeding efficiency, management level and production environment monitoring. Traditional pig weight recognition methods mainly rely on the management of individual pig weight measurement, physical characteristics and ear tags. Among them, the method of regular weight measurement is simple, but it is affected by the weight fluctuation of pigs and the similarity of weights of different individuals. Another method is to identify by observing appearance characteristics such as body shape, color and markings, but there are similarities in the same breed or the same batch, and the accuracy for individual pigs is limited. The currently commonly used ear tag recognition method, although each pig has a unique ear tag number, is easily interfered by factors such as falling off, wear and dirt. Radio frequency identification technology identifies by implanting chips in the body or ears. Although it is more advanced than traditional ear tags, it may cause harm to pigs. The above methods have limitations such as low accuracy, inconvenient management and being affected by environmental factors in practical applications. To overcome these problems, introducing advanced computer vision technology has become the solution.
[0003] Object detection is the mainstream method in computer vision technology, but it is prone to problems of misidentification or missed identification in complex scenes. Summary of the Invention
[0004] The embodiments of this application provide a method, device, storage medium and electronic device for pig weight recognition based on instance segmentation, which can solve the problem of easy misidentification or missed identification in complex scenes.
[0005] The embodiments of this application provide a method for pig weight recognition based on instance segmentation, including: Obtain the infrared image of the pig to be detected; Input the infrared image of the pig to be detected into the trained instance segmentation model to obtain the target detection frame and the target segmentation result; Among them, the step of inputting the infrared image of the pig to be detected into the trained instance segmentation model to obtain the target detection frame and the target segmentation result includes: Extract features from the infrared image of the pig to be detected to obtain the pig feature map, and process the pig feature map through the candidate region generation algorithm to obtain multiple candidate regions; The initial target detection frame is obtained by extracting key features from the candidate region through bilinear interpolation. The initial target detection frame is repeatedly subjected to key feature extraction and target segmentation to obtain the final target detection frame and target segmentation result.
[0006] As a further improvement of the present invention, in the above pig re-identification method based on instance segmentation, the instance segmentation model includes a convolutional neural network. The infrared image of the pig to be detected is subjected to feature extraction through the pre-trained convolutional neural network to obtain a pig feature map.
[0007] As a further improvement of the present invention, in the above pig re-identification method based on instance segmentation, the processing of the pig feature map through the candidate region generation algorithm to obtain multiple candidate regions includes: Construct a region candidate network based on the candidate region generation algorithm. The region candidate network includes multiple sliding windows, a classification layer, and a regression layer; Input the pig feature map into the region candidate network, and generate anchor boxes through the sliding windows; Classify the output anchor boxes through the classification layer to obtain the classification result of the anchor boxes; Calculate the probability that the anchor box contains a target through the regression layer. If the probability of containing a target exceeds the probability threshold, the corresponding anchor box is used as a candidate region.
[0008] As a further improvement of the present invention, in the above pig re-identification method based on instance segmentation, the obtaining of the target detection frame by extracting key features from the candidate region through bilinear interpolation includes: Assume that the coordinates of four known pixel points in the candidate region are , , , , and find the values of the four pixel points adjacent to the point in the candidate region; Perform linear interpolation on the x-axis to obtain:
[0009]
[0010] Perform linear interpolation on the y-axis to obtain:
[0011] Combine the linear interpolation result on the x-axis with the linear interpolation result on the y-axis to obtain: .
[0012] As a further improvement of the present invention, in the above-mentioned pig weight recognition method based on instance segmentation, where the step of performing key feature extraction and object segmentation on the target detection box multiple times to obtain the final target detection box and object segmentation result includes: Perform bilinear interpolation on the target detection box to obtain a first intermediate detection box; Perform object segmentation on the first intermediate detection box to obtain a first intermediate segmentation result; Perform bilinear interpolation on the first intermediate detection box to obtain a second intermediate detection box; Perform object segmentation on the second intermediate detection box to obtain a second intermediate segmentation result; Perform bilinear interpolation on the second intermediate detection box to obtain the final target detection box; Perform object segmentation on the second intermediate detection box to obtain the object segmentation result.
[0013] As a further improvement of the present invention, in the above-mentioned pig weight recognition method based on instance segmentation, after the step of performing object segmentation on the second intermediate detection box to obtain the object segmentation result, it includes: Perform color annotation on multiple object segmentation results respectively, and the colors of different object segmentation results are different.
[0014] As a further improvement of the present invention, in the above-mentioned pig weight recognition method based on instance segmentation, the training process of the instance segmentation model includes: Obtain a pig infrared image dataset; Perform polygon annotation on the pig infrared images in the pig infrared image dataset; Input the pig infrared image dataset into the instance segmentation model to obtain a target detection box and an object segmentation result; Construct a loss function based on the object segmentation result and the polygon annotation, and train the instance segmentation model based on the loss function.
[0015] The embodiment of the present application also provides a pig weight recognition device based on instance segmentation, including: An acquisition module, configured to acquire a pig infrared image to be detected; An object recognition module, configured to input the pig infrared image to be detected into a trained instance segmentation model to obtain a target detection box and an object segmentation result; Wherein, the step of inputting the pig infrared image to be detected into a trained instance segmentation model to obtain a target detection box and an object segmentation result includes: Feature extraction is performed on the infrared image of the pig to be detected to obtain a pig feature map, and a candidate region generation algorithm is used to process the pig feature map to obtain multiple candidate regions; Key feature extraction is performed on the candidate regions through bilinear interpolation to obtain an initial target detection frame, and key feature extraction and target segmentation are performed on the initial target detection frame multiple times to obtain a final target detection frame and a target segmentation result.
[0016] An embodiment of the present application also provides a computer-readable storage medium, in which multiple instructions are stored, and the instructions are suitable for being loaded by a processor to execute any one of the above-mentioned pig re-identification methods based on instance segmentation.
[0017] An embodiment of the present application also provides an electronic device, including a processor and a memory, the processor is electrically connected to the memory, the memory is used to store instructions and data, and the processor is used for the steps in any one of the above-mentioned pig re-identification methods based on instance segmentation.
[0018] The pig re-identification method, device, storage medium and electronic device provided by the present application. The present application identifies the infrared image of the pig through an instance segmentation model, processes the pig feature map through a candidate region generation algorithm to obtain multiple candidate regions, performs key feature extraction on the candidate regions through bilinear interpolation to obtain an initial target detection frame, and performs bilinear interpolation and target segmentation on the initial target detection frame multiple times to obtain a final target detection frame and a target detection result. The present application generates candidate regions through a candidate region generation algorithm, and obtains a final recognition result through multiple uses of bilinear interpolation and target segmentation. The present application improves the accuracy of pig identification, has good adaptability, accuracy and convenience, and is applicable to a wide range of daily monitoring and management scenarios of pigs. Description of the Drawings
[0019] The following combines the drawings and describes the specific implementation manners of the present application in detail, and the technical solutions and other beneficial effects of the present application will be obvious.
[0020] Figure 1 It is a flowchart of the pig re-identification method based on instance segmentation provided by an embodiment of the present application.
[0021] Figure 2 It is an overall schematic diagram of pig image acquisition provided by an embodiment of the present application.
[0022] Figure 3 It is the infrared image of the pig collected by an embodiment of the present application.
[0023] Figure 4 It is a flowchart of generating a target detection frame and a target segmentation result provided by an embodiment of the present application.
[0024] Figure 5 This is the target segmentation result provided by the embodiment of the present application.
[0025] Figure 6 This is the schematic diagram of Labelme annotation of pigs provided by the embodiment of the present application.
[0026] Figure 7 This is the structural schematic diagram of the pig re-identification device based on instance segmentation provided by the embodiment of the present application.
[0027] Figure 8 This is the structural schematic diagram of the electronic device provided by the embodiment of the present application. Detailed implementation manners
[0028] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative efforts belong to the scope of protection of the present application.
[0029] The embodiment of the present application provides a pig re-identification method, device, storage medium and electronic device based on instance segmentation. A pig re-identification device based on instance segmentation provided by the embodiment of the present application can be integrated in an electronic device, and the electronic device can be a device such as a terminal or a server. Among them, the terminal can include a tablet computer, a notebook computer, a personal computer (PC), a microprocessing box, or other devices, etc.
[0030] Please refer to Figure 1 , Figure 1 This is the flowchart of the pig re-identification method based on instance segmentation provided by the embodiment of the present application, which is applied to an electronic device. The pig re-identification method based on instance segmentation includes the following steps: S1. Obtain an infrared image of the pig to be detected.
[0031] The infrared image of the pig to be detected is obtained by taking a top-down photo of the pig through an infrared lens.
[0032] Figure 2 This is the overall schematic diagram of pig image acquisition provided by the embodiment of the present application, Figure 3 This is the infrared image of the pig collected provided by the embodiment of the present application, such as Figure 2 And Figure 3As shown, specifically, an infrared camera is placed at a position 4.5 meters above the pigsty for shooting. An image is collected every 2 seconds and lasts for 1 minute. This shooting is carried out every hour. The collected images have a resolution of 640x480 and are in the bmp format.
[0033] S2. Input the infrared image of the pig to be detected into the trained instance segmentation model to obtain the target detection frame and the target segmentation result.
[0034] Specifically, step S2 includes the following steps: S21. Extract features from the infrared image of the pig to be detected to obtain the pig feature map, and process the pig feature map through the candidate region generation algorithm to obtain multiple candidate regions.
[0035] Among them, the instance segmentation model includes a convolutional neural network and a region candidate network.
[0036] Step S21 includes the following steps: S211. Extract features from the infrared image of the pig to be detected through the pre-trained convolutional neural network to obtain the pig feature map.
[0037] Specifically, use the pre-trained convolutional neural network ResNet50 as the backbone to extract features from the input image to obtain the feature map of the image.
[0038] S212. Build a region candidate network based on the candidate region generation algorithm. The region candidate network includes multiple sliding windows, a classification layer, and a regression layer.
[0039] S213. Input the pig feature map into the region candidate network to generate anchor boxes through the sliding window.
[0040] Specifically, perform sliding windows of different window sizes on the pig feature map (way: from left to right, from top to bottom). Each time of sliding, execute the classifier (the classifier is pre-trained) on the current window. If the current window obtains a relatively high classification probability, it is considered that the target is detected. After detecting each sliding window of different window sizes, the object markers detected by different windows will be obtained, and there will be a relatively high repetition part in these window sizes. Finally, use the method of non-maximum suppression (Non-Maximum Suppression, NMS) for screening.
[0041] S214. Classify the output anchor boxes through the classification layer to obtain the classification results of the anchor boxes.
[0042] Among them, the classification results include two categories: the anchor box contains the target and the anchor box is the background.
[0043] S215. Calculate the probability that the anchor box contains the target through the regression layer. If the probability that the anchor box contains the target exceeds the probability threshold, then use the corresponding anchor box as the candidate region.
[0044] S22. Perform key feature extraction on the candidate region through bilinear interpolation to obtain the initial target detection box. Perform key feature extraction and target segmentation on the initial target detection box multiple times to obtain the final target detection box and the target segmentation result.
[0045] In one embodiment, step S22 includes the following steps: S221. Assume that the coordinates of four known pixel points in the candidate region are , , , , and find the values of the four pixel points adjacent to the point in the candidate region; S222. Perform linear interpolation on the x-axis to obtain:
[0046]
[0047] S223. Perform linear interpolation on the y-axis to obtain:
[0048] S224. Combine the linear interpolation result on the x-axis and the linear interpolation result on the y-axis to obtain:
[0049] S225. Perform bilinear interpolation on the target detection box to obtain the first intermediate detection box; S226. Perform target segmentation on the first intermediate detection box to obtain the first intermediate segmentation result; S227. Perform bilinear interpolation on the first intermediate detection box to obtain the second intermediate detection box; S228. Perform target segmentation on the second intermediate detection box to obtain the second intermediate segmentation result; S229. Perform bilinear interpolation on the second intermediate detection box to obtain the final target detection box; S22A. Perform target segmentation on the second intermediate detection box to obtain the target segmentation result.
[0050] Figure 4 This is the flowchart for generating the target detection box and the target segmentation result provided by the embodiment of the present application. The above steps can be referred to Figure 4 .
[0051] Further, color annotation is performed on multiple target segmentation results respectively, and different target segmentation results have different colors. Figure 5 This is the target segmentation result provided by the embodiment of the present application. As Figure 5 shown, each pig is marked with a different color.
[0052] The above steps are the application process of the instance segmentation model. The training process of the instance segmentation model is briefly introduced below: A1. Obtain the pig infrared image dataset.
[0053] To ensure the diversity of the dataset, images with different background complexities, different pig poses, and different imaging qualities are selected as the dataset.
[0054] A2. Perform polygon annotation on the pig infrared images in the pig infrared image dataset.
[0055] Specifically, use the Labelme annotation software to perform polygon annotation on all pigs. Figure 6 This is the schematic diagram of Labelme annotating pigs provided by the embodiment of the present application.
[0056] A3. Input the pig infrared image dataset into the instance segmentation model to obtain the target detection box and the target segmentation result.
[0057] A4. Construct a loss function based on the target segmentation result and the polygon annotation, and train the instance segmentation model based on the loss function.
[0058] In this application, the pig infrared image is recognized through the instance segmentation model. Multiple candidate regions are obtained by processing the pig feature map through the candidate region generation algorithm. The initial target detection box is obtained by extracting key features from the candidate regions through bilinear interpolation. The final target detection box and the target detection result are obtained by performing bilinear interpolation and target segmentation on the initial target detection box multiple times. In this application, candidate regions are generated through the candidate region generation algorithm, and the final recognition result is obtained by using bilinear interpolation and target segmentation multiple times. This application improves the accuracy of pig recognition, has good adaptability, accuracy, and convenience, and is applicable to a wide range of daily monitoring and management scenarios of pigs.
[0059] In addition, the contour of each individual pig is accurately marked in this application. The instance segmentation model is trained through the marked pig contour, making the re-identification of the instance segmentation model more accurate. It can not only distinguish different individuals of the same category, but also assign a unique color to each individual for easier distinction.
[0060] According to the method described in the above embodiments, this embodiment will be further described from the perspective of a pig re-identification device based on instance segmentation. The pig re-identification device based on instance segmentation can be specifically implemented as an independent entity or integrated in an electronic device, which can be a device such as a terminal, a server, etc. Among them, the terminal can include a tablet computer, a notebook computer, a personal computer (PC), a microprocessing box, or other devices, etc.
[0061] Please refer to Figure 7 , Figure 7 which specifically describes the pig re-identification device based on instance segmentation provided in the embodiments of the present application, applied in an electronic device. The pig re-identification device based on instance segmentation may include: An acquisition module, configured to acquire an infrared image of a pig to be detected; A target recognition module, configured to input the infrared image of the pig to be detected into a trained instance segmentation model to obtain a target detection frame and a target segmentation result; Among them, the step of inputting the infrared image of the pig to be detected into a trained instance segmentation model to obtain a target detection frame and a target segmentation result includes: Performing feature extraction on the infrared image of the pig to be detected to obtain a pig feature map, and processing the pig feature map through a candidate region generation algorithm to obtain a plurality of candidate regions; Performing key feature extraction on the candidate regions through bilinear interpolation to obtain an initial target detection frame, and performing key feature extraction and target segmentation on the initial target detection frame multiple times to obtain a final target detection frame and a target segmentation result.
[0062] In specific implementation, each of the above modules and / or units can be implemented as an independent entity, or can be combined arbitrarily to be implemented as the same or several entities. The specific implementation of each of the above modules and / or units can refer to the method embodiments above, and the specific beneficial effects that can be achieved can also refer to the beneficial effects in the method embodiments above, which will not be elaborated here.
[0063] In addition, the embodiments of the present application further provide an electronic device, which can be a device such as a computer, a tablet computer, etc. The electronic device can implement the steps in any of the embodiments of the pig re-identification method based on instance segmentation provided in the embodiments of the present application. Therefore, the beneficial effects that can be achieved by any of the pig re-identification methods based on instance segmentation provided in the embodiments of the present invention can be achieved. For details, please refer to the previous embodiments, which will not be elaborated here.
[0064] Figure 8The specific structural block diagram of the electronic device provided by the embodiment of the present invention is shown. This electronic device can be used to implement the pig weight recognition method based on instance segmentation provided in the above embodiments. The electronic device 500 can be a device such as a terminal or a server. Among them, the terminal can include a tablet computer, a notebook computer, a personal computer (PC), a microprocessing box, or other devices, etc.
[0065] The RF circuit 510 is used to receive and send electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, so as to communicate with a communication network or other devices. The RF circuit 510 may include various existing circuit elements for performing these functions. For example, antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, subscriber identity module (SIM) cards, memories, and so on. The RF circuit 510 can communicate with various networks such as the Internet, enterprise intranets, wireless networks or communicate with other devices through a wireless network. The above-mentioned wireless network may include a cellular phone network, a wireless local area network or a metropolitan area network. The above-mentioned wireless network can use various communication standards, protocols and technologies, including but not limited to Global System for Mobile Communication (GSM), Enhanced Data GSM Environment (EDGE), Wideband Code Division Multiple Access (WCDMA), Code Division Access (CDMA), Time Division Multiple Access (TDMA), Wireless Fidelity (Wi-Fi) (such as Institute of Electrical and Electronics Engineers standards IEEE 802.11a, IEEE 802.11b, IEEE 802.11g and / or IEEE 802.11n), Voice over Internet Protocol (VoIP), Worldwide Interoperability for Microwave Access (Wi-Max), other protocols for email, instant messaging and short messages, and any other suitable communication protocols, and may even include those protocols that have not been developed yet.
[0066] The memory 520 can be used to store software programs and modules, such as the corresponding program instructions / modules in the above embodiments. The processor 580 executes various functional applications and data processing by running the software programs and modules stored in the memory 520, that is, realizes functions such as taking pictures with the front camera, processing the captured images, and switching the display colors of the display content on the display screen. The memory 520 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some instances, the memory 520 may further include a memory remotely disposed relative to the processor 580, and these remote memories can be connected to the electronic device 500 through a network. Examples of the above network include but are not limited to the Internet, enterprise intranet, local area network, mobile communication network, and combinations thereof.
[0067] The input unit 530 can be used to receive input digital or character information, and generate a keyboard and a mouse related to user settings and function controls. The display unit 540 can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces, and these graphical user interfaces can be composed of graphics, text, icons, videos, and any combination thereof. The display unit 540 may include a display panel 541. Optionally, the display panel 541 can be configured in the form of an LCD (Liquid Crystal Display) or an OLED (Organic Light-Emitting Diode).
[0068] The audio circuit 560, the speaker 561, and the microphone 562 can provide an audio interface between the user and the electronic device 500. The audio circuit 560 can transmit the electrical signal converted from the received audio data to the speaker 561, and the speaker 561 converts it into a sound signal for output; on the other hand, the microphone 562 converts the collected sound signal into an electrical signal, which is received by the audio circuit 560 and then converted into audio data. After the audio data is output to the processor 580 for processing, it is sent to another terminal, for example, through the RF circuit 510, or the audio data is output to the memory 520 for further processing. The audio circuit 560 may further include an earphone jack to provide communication between the peripheral earphone and the electronic device 500.
[0069] The electronic device 500 can help the user receive requests, send information, etc. through the transmission module 570 (such as a Wi-Fi module), and it provides the user with wireless broadband Internet access. Although the transmission module 570 is shown in the figure, it can be understood that it does not belong to the essential components of the electronic device 500, and it can be completely omitted within the scope of not changing the essence of the invention according to needs.
[0070] The processor 580 is the control center of the electronic device 500, connecting various parts of the entire mobile phone through various interfaces and circuits. By running or executing software programs and / or modules stored in the memory 520, and by calling the data stored in the memory 520, it executes various functions of the electronic device 500 and processes data, thereby monitoring the electronic device as a whole. Optionally, the processor 580 may include one or more processing cores; in some embodiments, the processor 580 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor may not be integrated into the processor 580 either.
[0071] The electronic device 500 also includes a power supply 590 (such as a battery) for powering each component. In some embodiments, the power supply can be logically connected to the processor 580 through a power management system, so as to realize functions such as management of charging, discharging, and power consumption management through the power management system. The power supply 590 may also include any components such as one or more DC or AC power supplies, a recharge system, a power failure detection circuit, a power converter or inverter, and a power status indicator.
[0072] Although not shown, the electronic device 500 also includes a camera (such as a front camera and a rear camera), a Bluetooth module, etc., which will not be elaborated here. Specifically, in this embodiment, the display unit of the electronic device is a touch screen display, and the mobile terminal also includes a memory, and one or more programs, where one or more programs are stored in the memory and are configured to be executed by one or more processors. The one or more programs include instructions for performing the following operations: Obtain the infrared image of the pig to be detected; Input the infrared image of the pig to be detected into the trained instance segmentation model to obtain a target detection frame and a target segmentation result; Among them, the step of inputting the infrared image of the pig to be detected into the trained instance segmentation model to obtain a target detection frame and a target segmentation result includes: Extract features from the infrared image of the pig to be detected to obtain a pig feature map, and process the pig feature map through a candidate region generation algorithm to obtain a plurality of candidate regions; Extract key features from the candidate regions through bilinear interpolation to obtain an initial target detection frame, and perform key feature extraction and target segmentation on the initial target detection frame multiple times to obtain the final target detection frame and target segmentation result.
[0073] In specific implementation, each of the above modules can be implemented as an independent entity, or can be combined arbitrarily and implemented as the same or several entities. For the specific implementation of each of the above modules, reference can be made to the foregoing method embodiments, which will not be elaborated herein.
[0074] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions or by controlling related hardware through instructions. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. For this purpose, an embodiment of the present invention provides a storage medium in which multiple instructions are stored. These instructions can be loaded by a processor to execute the steps of any one of the embodiments of the method for re-identifying pigs based on instance segmentation provided by the embodiments of the present invention.
[0075] Among them, the computer-readable storage medium may include: read-only memory (ROM, Read Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disc, etc.
[0076] Since the instructions stored in this storage medium can execute the steps in any one of the embodiments of the method for re-identifying pigs based on instance segmentation provided by the embodiments of the present invention, the beneficial effects achievable by any of the methods for re-identifying pigs based on instance segmentation provided by the embodiments of the present invention can be realized. For details, refer to the foregoing embodiments, which will not be elaborated herein.
[0077] The above has introduced in detail a method, device, storage medium and electronic device for re-identifying pigs based on instance segmentation provided by the embodiments of the present application. Specific examples are used in this article to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application; at the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present application.
Claims
1. A pig re-identification method based on instance segmentation, characterized in that: The method comprises: Obtain infrared images of the pigs to be detected; Inputting the infrared image of the pig to be detected into the trained instance segmentation model to obtain a target detection frame and a target segmentation result; The step of inputting the infrared image of the pig to be detected into the trained instance segmentation model to obtain the target detection frame and the target segmentation result includes: Extracting features from the infrared image of the pig to be detected to obtain a pig feature map, and processing the pig feature map using a candidate region generation algorithm to obtain a plurality of candidate regions; The key features of the candidate area are extracted by bilinear interpolation to obtain an initial target detection frame, and the key features are extracted and the target is segmented for multiple times on the initial target detection frame to obtain a final target detection frame and target segmentation result.
2. The method for pig re-identification based on instance segmentation according to claim 1, characterized in that: The instance segmentation model includes a convolutional neural network, and the pre-trained convolutional neural network is used to extract features from the infrared image of the pig to be detected to obtain a pig feature map.
3. The method for pig re-identification based on instance segmentation according to claim 1, characterized in that: The pig feature map is processed by the candidate region generation algorithm to obtain multiple candidate regions, including: Building a region candidate network based on a candidate region generation algorithm, wherein the region candidate network includes multiple sliding windows, a classification layer, and a regression layer; Inputting the pig feature map into the region candidate network, and generating an anchor frame through a sliding window; Classifying the output anchor frame through the classification layer to obtain a classification result of the anchor frame; The probability of the anchor frame containing the target is calculated through the regression layer. If the probability of containing the target exceeds a probability threshold, the corresponding anchor frame is used as a candidate region.
4. The method for pig re-identification based on instance segmentation according to claim 1, characterized in that: The step of extracting key features of the candidate region by bilinear interpolation to obtain a target detection frame includes: Assume that the coordinates of the four known pixels in the candidate area are , , , , find the point in the candidate area The values of the four adjacent pixels; Doing linear interpolation on the x-axis, we get: Doing linear interpolation on the y-axis, we get: Combining the linear interpolation result on the x-axis with the linear interpolation result on the y-axis, we get: 。 5. The method for pig re-identification based on instance segmentation according to claim 1, characterized in that: The target detection frame is subjected to multiple key feature extraction and target segmentation to obtain a final target detection frame and target segmentation result, including: Performing bilinear interpolation on the target detection frame to obtain a first intermediate detection frame; Performing object segmentation on the first intermediate detection frame to obtain a first intermediate segmentation result; Performing bilinear interpolation on the first middle detection frame to obtain a second middle detection frame; Performing object segmentation on the second intermediate detection frame to obtain a second intermediate segmentation result; Perform bilinear interpolation on the second intermediate detection frame to obtain a final object detection frame; Perform object segmentation on the second middle detection frame to obtain an object segmentation result.
6. The method for pig re-identification based on instance segmentation according to claim 5, characterized in that: After the step of performing target segmentation on the second middle detection frame to obtain a target segmentation result, the method further comprises: The plurality of target segmentation results are respectively color-labeled, and different target segmentation results have different colors.
7. The method for pig re-identification based on instance segmentation according to claim 1, characterized in that: The training process of the instance segmentation model includes: Obtain a pig infrared image dataset; Performing polygon annotation on the infrared images of pigs in the infrared image dataset of pigs; Inputting the pig infrared image dataset into an instance segmentation model to obtain a target detection frame and a target segmentation result; A loss function is constructed based on the target segmentation result and the polygon annotation, and the instance segmentation model is trained based on the loss function.
8. A pig re-identification device based on instance segmentation, characterized in that: include: An acquisition module is used to acquire infrared images of pigs to be detected; A target recognition module is used to input the infrared image of the pig to be detected into the trained instance segmentation model to obtain a target detection frame and a target segmentation result; The step of inputting the infrared image of the pig to be detected into the trained instance segmentation model to obtain the target detection frame and the target segmentation result includes: Extracting features from the infrared image of the pig to be detected to obtain a pig feature map, and processing the pig feature map using a candidate region generation algorithm to obtain a plurality of candidate regions; The key features of the candidate area are extracted by bilinear interpolation to obtain an initial target detection frame, and the key features are extracted and the target is segmented for multiple times on the initial target detection frame to obtain a final target detection frame and target segmentation result.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the pig re-identification method based on instance segmentation according to any one of claims 1 to 7.
10. An electronic device, characterized in that: It comprises a processor and a memory, wherein the processor is electrically connected to the memory, the memory is used to store instructions and data, and the processor is used to execute the steps in the pig re-identification method based on instance segmentation as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Battlefield target detection method based on optimized RPN network
CN110766058A
Pig weight estimation method and device
CN118366184A
Key target positioning and segmentation method and system based on human fuzzy intuition driving
CN118429422A
Cited By
Target detection method and device based on registration instance segmentation, equipment and medium
CN121121162A