Method, device, storage medium and terminal for detecting objects in images
By weighting according to the aspect ratio of the object in the loss function of the object detection model in the image, the problem of low detection performance of objects with large aspect ratios in the existing technology is solved, and more accurate object recognition and positioning are achieved.
Patent Information
- Application Number
- CN202110797281.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-14
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-07-14
AI Technical Summary
Object detection models in existing images have low detection performance for objects with an aspect ratio greater than a certain value and cannot accurately locate or classify objects.
By determining the weight value according to the aspect ratio of the object in the loss function of the object detection model, the loss of objects with large aspect ratios is increased, thereby optimizing the model's detection performance.
The model's detection performance for objects with a large aspect ratio has been improved, and it can more accurately identify and locate objects with a large aspect ratio.
Smart Images

Figure CN113537342B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and in particular to a method, device, storage medium and terminal for detecting objects in an image. Background Art
[0002] Object detection in images is an important research direction in computer vision and digital image processing, and is widely used in many fields such as robot navigation, intelligent video surveillance, industrial inspection, aerospace, etc. The goal of object detection in images is to find the objects of interest in the image, which includes two subtasks: object localization and object classification, that is, determining the category and location of the object at the same time.
[0003] In the prior art, object detection models that use neural networks combined with a large amount of image data for training have become the mainstream model training method in the industry. Neural network-based algorithms can basically be divided into two categories: two-stage algorithms represented by Faster R-CNN and one-stage algorithms represented by YOLO, SSD, etc. Whether it is a one-stage algorithm or a two-stage algorithm, the performance of detecting long objects with a length-to-width ratio greater than a certain value, such as skis, pencils, etc., is greatly reduced compared to detecting objects with a smaller length-to-width ratio, such as footballs, cars, etc. In some cases, the network cannot detect objects with a length-to-width ratio greater than a certain value. In other cases, although the network can detect objects with a length-to-width ratio greater than a certain value, the object position is not accurate enough.
[0004] One of the reasons for this phenomenon is that objects with a length-to-width ratio greater than a certain value account for a small proportion of the objects in the entire data set. When training the model, the model does not take objects with a length-to-width ratio greater than a certain value as the optimization focus, resulting in the model being unable to learn the features of objects with a length-to-width ratio greater than a certain value well, and thus being unable to correctly classify objects with a length-to-width ratio greater than a certain value in the image, or being unable to accurately locate their positions. Summary of the invention
[0005] The embodiments of the present application provide a method, device, storage medium and terminal for detecting objects in an image. In order to have a basic understanding of some aspects of the disclosed embodiments, a simple summary is given below. This summary is not a general review, nor is it intended to identify key / important components or describe the scope of protection of these embodiments. Its only purpose is to present some concepts in a simple form as a preface to the detailed description that follows.
[0006] In a first aspect, an embodiment of the present application provides a method for detecting an object in an image, the method comprising:
[0007] Acquire the target image to be detected;
[0008] Inputting the target image to be detected into a pre-trained object detection model; wherein the loss function of the pre-trained object detection model is generated by weighting after determining the weight value according to the aspect ratio value of the object in the image data;
[0009] Output the location of each object in the target image and multiple category probability values;
[0010] The final category of each object is determined based on multiple category probability values.
[0011] Optionally, follow these steps to generate a pre-trained object detection model, including:
[0012] Collect training samples of image generation models containing various objects;
[0013] Create an object detection model;
[0014] Obtain the first position information and the first category information of each object in the output image from the model training sample and input the n-th image into the object detection model;
[0015] Constructing a target label in the nth image; wherein the target label includes second position information and second category information;
[0016] Determining a weight value of the loss function according to the second position information;
[0017] Constructing a loss function of an object detection model according to the first position information and the first category information, the second position information and the second category information, and the weight value;
[0018] Inputting the first position information and the first category information into a loss function of an object detection model, and outputting a loss value of the model;
[0019] Optimize the object detection model based on the loss value to generate a trained object detection model;
[0020] The trained object detection model is determined as the pre-trained object detection model.
[0021] Optionally, the pre-trained object detection model includes a feature extraction module, a classification module, and a regression module;
[0022] Obtaining the first position information and the first category information of each object in the output image from the model training sample in the object detection model of the nth image input, including:
[0023] Obtain the nth image from the model training sample and input it into the feature extraction module to obtain an image feature map;
[0024] Generate multiple candidate regions of different sizes and aspect ratios for each position in the image feature map;
[0025] After classifying and adjusting the position of the candidate areas using the classification module and the regression module, the first position information and the first category information of each object in the image are output.
[0026] Optionally, the second position information includes at least length and width;
[0027] Determining a weight value of a loss function according to the second position information includes:
[0028] When the length is greater than the width, the ratio of the length to the width is determined as the target ratio;
[0029] or,
[0030] When the length is smaller than the width, the ratio of the width to the length is determined as the target ratio;
[0031] When the target ratio is greater than a preset determination threshold, the ratio of the target ratio to the preset determination threshold is determined as a weight value of the loss function;
[0032] or,
[0033] When the target ratio is less than or equal to the preset determination threshold, the positive integer 1 is determined as the weight value of the loss function.
[0034] Optionally, optimize the object detection model based on the loss value to generate a trained object detection model, including:
[0035] Derivative the parameters of the object detection model according to the loss value to generate a local gradient sequence;
[0036] The object detection model is iteratively optimized using the stochastic gradient descent algorithm and the local gradient sequence;
[0037] When the number of iterative optimizations is equal to the preset upper limit or the loss value is less than the preset threshold, stop optimizing the model;
[0038] Generate a trained object detection model.
[0039] Optionally, when the number of iterative optimizations is equal to a preset upper limit or the loss value is less than a preset threshold, the optimization of the model is stopped, including:
[0040] When the number of iterative optimization is less than the preset upper limit or the loss value is greater than or equal to the preset threshold, continue to execute the step of obtaining the n+1th image input into the object detection model from the model training samples, and when n+1 is greater than the number of model training samples, randomly arrange the order of the images in the model training samples and reset n=1.
[0041] Optionally, the final category of each object is determined based on multiple category probability values, including:
[0042] Select the maximum probability value among multiple category probability values;
[0043] Identify the category corresponding to the selected maximum probability value;
[0044] The category corresponding to the maximum probability value is determined as the final category of each object.
[0045] In a second aspect, an embodiment of the present application provides a device for detecting an object in an image, the device comprising:
[0046] An image acquisition module, used to acquire a target image to be detected;
[0047] An image input module is used to input the target image to be detected into a pre-trained object detection model; wherein the loss function of the pre-trained object detection model is generated by weighting after determining the weight value according to the aspect ratio value of the object in the image data;
[0048] An output module, used to output the position of each object in the target image and multiple category probability values;
[0049] The final category determination module is used to determine the final category of each object according to multiple category probability values.
[0050] In a third aspect, an embodiment of the present application provides a computer storage medium, which stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the above-mentioned method steps.
[0051] In a fourth aspect, an embodiment of the present application provides a terminal, which may include: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the above-mentioned method steps.
[0052] The technical solution provided by the embodiments of the present application may have the following beneficial effects:
[0053] In an embodiment of the present application, the device for detecting objects in an image first obtains the target image to be detected, and then inputs the target image to be detected into a pre-trained object detection model, wherein the loss function of the pre-trained object detection model is generated by weighting after determining the weight value according to the aspect ratio of the object in the image data, and then outputs the position of each object in the target image and multiple category probability values, and finally determines the final category of each object according to the multiple category probability values. Since the weight value is determined by the aspect ratio of the object, and the weight value is used to increase the weight of the loss function of the model, the model has a greater loss for objects with a large aspect ratio, thereby improving the detection performance of the model for objects with a large aspect ratio.
[0054] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0056] Figure 1 It is a flowchart of a method for detecting objects in an image provided by an embodiment of the present application;
[0057] Figure 2 It is a flowchart of a training method for an object detection model provided in an embodiment of the present application;
[0058] Figure 3 is a structural schematic diagram of a device for detecting objects in an image provided by an embodiment of the present application;
[0059] Figure 4 It is a structural diagram of a terminal provided in an embodiment of the present application. DETAILED DESCRIPTION
[0060] The following description and the drawings sufficiently illustrate specific embodiments of the invention to enable those skilled in the art to practice them.
[0061] It should be clear that the described embodiments are only some embodiments of the present invention, not all 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.
[0062] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are only examples of devices and methods consistent with some aspects of the present invention as detailed in the attached claims.
[0063] In the description of the present invention, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances. In addition, in the description of the present invention, unless otherwise specified, "plurality" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previously associated objects are in an "or" relationship.
[0064] The present application provides a method, device, storage medium and terminal for detecting objects in an image to solve the problems existing in the above-mentioned related technical problems. In the technical solution provided by the present application, since the weight value is determined by the aspect ratio of the object, and the weight value is used to increase the weight of the loss function of the model, the model has a greater loss for objects with a large aspect ratio, thereby improving the detection performance of the model for objects with a large aspect ratio. The following is a detailed description using an exemplary embodiment.
[0065] The following will be combined with the attached Figure 1 -Attached Figure 2 , the method for detecting objects in an image provided by an embodiment of the present application is introduced in detail. The method can be implemented by a computer program and can be run on an object detection device in an image based on a von Neumann system. The computer program can be integrated in an application or run as an independent tool application. Among them, the object detection device in the image in the embodiment of the present application can be a user terminal, including but not limited to: a personal computer, a tablet computer, a handheld device, a vehicle-mounted device, a wearable device, a computing device or other processing device connected to a wireless modem. In different networks, the user terminal can be called by different names, such as: user equipment, access terminal, user unit, user station, mobile station, mobile station, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication device, user agent or user device, cellular phone, cordless phone, personal digital assistant (PDA), 5G network or terminal equipment in future evolution network, etc.
[0066] See also Figure 1 , which is a flow chart of a method for detecting objects in an image according to an embodiment of the present application. Figure 1 As shown, the method of the embodiment of the present application may include the following steps:
[0067] S101, obtaining a target image to be detected;
[0068] The target image to be detected is an image used to test the performance of a pre-trained object detection model or an image received when the pre-trained object detection model is applied to a detection scene.
[0069] Generally, when the target image to be detected is an image used to test the performance of a pre-trained object detection model, the target image to be detected can be obtained from a test sample, an image obtained from a user terminal, or an image downloaded from the cloud. When the target image to be detected is an image obtained when a pre-trained object detection model is applied to a detection application scenario, the image to be detected can be an image acquired in real time by an image acquisition device.
[0070] In one possible implementation, after the object detection model is trained and deployed in an actual application scenario, the object sensor or object monitoring algorithm detects that an object has entered the camera monitoring area, triggers the image acquisition camera's camera function to capture the target image entering the monitoring area, and finally determines the target image as the target image to be detected.
[0071] In another possible implementation, after the object detection model is trained, when it is necessary to test the object detection performance in the image of the trained object detection model, the user downloads any image carrying an object from a sample test set, a local gallery, or the cloud through a user terminal and determines the image as a target image to be detected.
[0072] S102, inputting the target image to be detected into a pre-trained object detection model;
[0073] The loss function of the pre-trained object detection model is generated by weighting the weight values determined according to the aspect ratio of the object in the image data. The pre-trained object detection model is a mathematical model that can identify objects in the image to be detected. The model can identify the location and category of objects with different aspect ratios in the image.
[0074] In an embodiment of the present application, when generating a pre-trained object detection model, first, image generation model training samples containing multiple objects are collected, and then an object detection model is created, and then the nth image is obtained from the model training samples and input into the object detection model, and the first position information and first category information of each object in the output image are output, and then the target label in the nth image is constructed; wherein the target label includes the second position information and the second category information, and the weight value of the loss function is determined according to the second position information, and then the loss function of the object detection model is constructed according to the first position information and the first category information, the second position information and the second category information, and the weight value, and then the first position information and the first category information are input into the loss function of the object detection model, the loss value of the model is output, and the object detection model is optimized based on the loss value to generate a trained object detection model, and finally the trained object detection model is determined as the pre-trained object detection model.
[0075] In a possible implementation, after the target image to be detected is acquired according to step S101, the target image is input into a pre-trained object detection model, and the model performs processing according to the generated file after training.
[0076] S103, outputting the position of each object in the target image and multiple category probability values;
[0077] The probability value represents the category probability distribution of the category to which each object in the image belongs.
[0078] In one possible implementation, after processing based on step S102 using a pre-trained object detection model, the position coordinates of each object and the probability values of multiple categories are obtained. Finally, the pre-trained object detection model outputs the position coordinates of each object and the probability values of multiple categories. After output, the position of each object in the target image and the probability values of multiple categories are obtained.
[0079] S104: determining the final category of each object according to the multiple category probability values.
[0080] In one possible implementation, when determining the final category of each object based on multiple category probability values, first select the maximum probability value among the multiple category probability values, then identify the category corresponding to the selected maximum probability value, and finally determine the category corresponding to the maximum probability value as the final category of each object.
[0081] In an embodiment of the present application, the device for detecting objects in an image first obtains the target image to be detected, and then inputs the target image to be detected into a pre-trained object detection model, wherein the loss function of the pre-trained object detection model is generated by weighting after determining the weight value according to the aspect ratio of the object in the image data, and then outputs the position of each object in the target image and multiple category probability values, and finally determines the final category of each object according to the multiple category probability values. Since the weight value is determined by the aspect ratio of the object, and the weight value is used to increase the weight of the loss function of the model, the model has a greater loss for objects with a large aspect ratio, thereby improving the detection performance of the model for objects with a large aspect ratio.
[0082] See also Figure 2 , which is a flow chart of a method for training an object detection model according to an embodiment of the present application. Figure 2 As shown, the training method of the object detection model includes the following steps:
[0083] S201, collecting training samples of image generation model containing multiple objects;
[0084] S202, creating an object detection model;
[0085] Usually, when creating an object detection model, it can be a one-stage model such as SSD, YOLO, etc., or a two-stage model such as Faster R-CNN. The specific model is determined according to the actual situation and is not limited here.
[0086] S203, obtaining first position information and first category information of each object in the output image of the n-th image input object detection model from the model training sample;
[0087] Among them, the pre-trained object detection model includes a feature extraction module, a classification module and a regression module.
[0088] In one possible implementation, the nth image is first input into a feature extraction module from a model training sample to obtain an image feature map, and then a plurality of candidate regions of different sizes and aspect ratios are generated for each position in the image feature map. Finally, a classification module and a regression module are used to classify and adjust the positions of the candidate regions, and then the first position information and the first category information of each object in the image are output.
[0089] S205, constructing a target label in the nth image; wherein the target label includes second position information and second category information;
[0090] In a possible implementation, a target label contained in the nth image is constructed. The target label includes position information and classification information. The target position information includes the length w and width h of the target and the center point position (x, y); the target category information specifies the category to which the target belongs, which is represented by a one-hot vector. The category to which the target belongs is 1, and the rest are 0. For example, [0,1,0,0] means that the target belongs to the second category.
[0091] S206, determining a weight value of a loss function according to the second position information;
[0092] The second position information at least includes length and width.
[0093] In the embodiment of the present application, when constructing the weight value, first determine which is the larger value between the length and the width. When the length is greater than the width, determine the length as the larger value, and then determine the ratio of the length to the width as the target ratio. Alternatively, when the length is less than the width, determine the width as the larger value, and then determine the ratio of the width to the length as the target ratio, and when the target ratio is greater than a preset determination threshold, determine the ratio of the target ratio to the preset determination threshold as the weight value of the loss function. Alternatively, when the target ratio is less than or equal to the preset determination threshold, determine the positive integer 1 as the weight value of the loss function.
[0094] Preferably, the preset determination threshold is 8.
[0095] In a possible implementation, the target ratio may be calculated based on the length and width included in the second position information. The target ratio may be defined as: wh ratio =max(w,h) / min(w,h), max(w,h) is the larger value between w and h, min(w,h) is the smaller value between w and h.
[0096] Further, according to the target ratio wh ratio The required weight value wh of the loss function can be determined weight, if wh ratio When it is greater than the preset judgment threshold r, then wh weight is the target ratio wh ratio The ratio of the preset judgment value r, if wh ratio When it is less than or equal to the preset judgment threshold r, then wh weight is 1.
[0097] Specifically, weight The available formula is:
[0098]
[0099] S207, constructing a loss function of an object detection model according to the first position information and the first category information, the second position information and the second category information, and the weight value;
[0100] Specifically, the constructed loss function is:
[0101]
[0102] Where i represents the index number of the candidate region. i Represents the output category of the object detection model regarding this area, Indicates the true category corresponding to this area, that is, the category in the target label. i Represents the output position information of the object detection model for this area, Indicates the real location information of the target corresponding to this area. i Indicates whether the candidate target is a positive sample, that is, whether it matches one or more real targets. When the candidate region is a positive sample, δ i =1. Otherwise δ i =0,. When the candidate region is a positive sample, the aspect ratio weight of the candidate region is By the weight value wh weight When the candidate area is a background area, that is, the candidate area does not correspond to any real target, Set to 0. L cls Represents the classification loss, and the optimal cross entropy loss can be designed according to the task requirements. reg Indicates the position loss, preferably smooth-L1 loss or various IoU-based losses. cls Represents the sum of the number of positive samples and negative samples, N reg Represents the number of negative samples. α is the weight to balance the classification loss and location loss.
[0103] In the embodiment of the present application, by increasing the loss weight of objects with a large aspect ratio, the loss function guides the model to focus on optimizing the detection of targets with a large aspect ratio.
[0104] S208, inputting the first position information and the first category information into a loss function of an object detection model, and outputting a loss value of the model;
[0105] In a possible implementation, after the loss function is obtained according to step S207, the first position information t obtained in the input model can be i With the first category information p i After being input as a variable into the loss function for calculation, the current loss value of the model is obtained.
[0106] S209, optimizing the object detection model based on the loss value to generate a trained object detection model;
[0107] In one possible implementation, when optimizing the object detection model based on the loss value, the parameters of the object detection model are first differentiated according to the loss value to generate a local gradient sequence, and then the object detection model is iteratively optimized using the stochastic gradient descent algorithm and the local gradient sequence. Finally, when the number of iterative optimizations is equal to a preset upper limit or the loss value is less than a preset threshold, the optimization of the model is stopped and a trained object detection model is generated.
[0108] Furthermore, when the number of iterative optimizations is less than a preset upper limit or the loss value is greater than or equal to a preset threshold, continue to execute the step of obtaining the n+1th image input into the object detection model from the model training samples, and when n+1 is greater than the number of model training samples, randomly arrange the order of the images in the model training samples and reset n=1.
[0109] S210: Determine the trained object detection model as a pre-trained object detection model.
[0110] In an embodiment of the present application, the device for detecting objects in an image first obtains the target image to be detected, and then inputs the target image to be detected into a pre-trained object detection model, wherein the loss function of the pre-trained object detection model is generated by weighting after determining the weight value according to the aspect ratio of the object in the image data, and then outputs the position of each object in the target image and multiple category probability values, and finally determines the final category of each object according to the multiple category probability values. Since the weight value is determined by the aspect ratio of the object, and the weight value is used to increase the weight of the loss function of the model's large aspect ratio object, the model has a greater loss for objects with a large aspect ratio, thereby improving the model's detection performance for objects with a large aspect ratio.
[0111] The following are embodiments of the device of the present invention, which can be used to implement the method embodiments of the present invention. For details not disclosed in the device embodiments of the present invention, please refer to the method embodiments of the present invention.
[0112] See also Figure 3 , which shows a schematic diagram of the structure of an apparatus for detecting objects in an image provided by an exemplary embodiment of the present invention. The apparatus for detecting objects in an image can be implemented as all or part of a terminal through software, hardware, or a combination of both. The apparatus 1 includes an image acquisition module 10, an image input module 20, an output module 30, and a final category determination module 40.
[0113] An image acquisition module 10 is used to acquire a target image to be detected;
[0114] The image input module 20 is used to input the target image to be detected into the pre-trained object detection model; wherein the loss function of the pre-trained object detection model is generated by weighting after determining the weight value according to the aspect ratio value of the object in the image data;
[0115] An output module 30, used to output the position of each object in the target image and multiple category probability values;
[0116] The final category determination module 40 is used to determine the final category of each object according to a plurality of category probability values.
[0117] It should be noted that the device for detecting objects in images provided in the above embodiments only uses the division of the above functional modules as an example when executing the method for detecting objects in images. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the device for detecting objects in images provided in the above embodiments and the method for detecting objects in images are of the same concept, and the implementation process thereof is detailed in the method embodiment, which will not be repeated here.
[0118] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0119] In an embodiment of the present application, the device for detecting objects in an image first obtains the target image to be detected, and then inputs the target image to be detected into a pre-trained object detection model, wherein the loss function of the pre-trained object detection model is generated by weighting after determining the weight value according to the aspect ratio of the object in the image data, and then outputs the position of each object in the target image and multiple category probability values, and finally determines the final category of each object according to the multiple category probability values. Since the weight value is determined by the aspect ratio of the object, and the weight value is used to increase the weight of the loss function of the model, the model has a greater loss for objects with a large aspect ratio, thereby improving the detection performance of the model for objects with a large aspect ratio.
[0120] The present invention also provides a computer-readable medium on which program instructions are stored. When the program instructions are executed by a processor, the method for detecting objects in an image provided by the above-mentioned various method embodiments is implemented.
[0121] The present invention also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the methods for detecting objects in images in the above-mentioned various method embodiments.
[0122] See also Figure 4 , which is a schematic diagram of the structure of a terminal provided in an embodiment of the present application. Figure 4 As shown, the terminal 1000 may include: at least one processor 1001 , at least one network interface 1004 , a user interface 1003 , a memory 1005 , and at least one communication bus 1002 .
[0123] The communication bus 1002 is used to realize the connection and communication between these components.
[0124] The user interface 1003 may include a display screen (Display) and a camera (Camera), and the optional user interface 1003 may also include a standard wired interface and a wireless interface.
[0125] The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0126] Among them, the processor 1001 may include one or more processing cores. The processor 1001 uses various interfaces and lines to connect various parts of the entire electronic device 1000, and executes various functions and processes data of the electronic device 1000 by running or executing instructions, programs, code sets or instruction sets stored in the memory 1005, and calling data stored in the memory 1005. Optionally, the processor 1001 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 1001 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 1001, and it can be implemented separately through a chip.
[0127] Among them, the memory 1005 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 1005 includes a non-transitory computer-readable storage medium. The memory 1005 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 1005 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 1005 may optionally be at least one storage device located away from the aforementioned processor 1001. As Figure 4 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an application program for detecting objects in images.
[0128] exist Figure 4In the terminal 1000 shown, the user interface 1003 is mainly used to provide an input interface for the user and obtain data input by the user; and the processor 1001 can be used to call the image object detection application stored in the memory 1005, and specifically perform the following operations:
[0129] Acquire the target image to be detected;
[0130] Inputting the target image to be detected into a pre-trained object detection model; wherein the loss function of the pre-trained object detection model is generated by weighting after determining the weight value according to the aspect ratio value of the object in the image data;
[0131] Output the location of each object in the target image and multiple category probability values;
[0132] The final category of each object is determined based on multiple category probability values.
[0133] In one embodiment, when the processor 1001 determines the final category of each object according to the multiple category probability values, the processor 1001 specifically performs the following operations:
[0134] Select the maximum probability value among multiple category probability values;
[0135] Identify the category corresponding to the selected maximum probability value;
[0136] The category corresponding to the maximum probability value is determined as the final category of each object.
[0137] In one embodiment, when generating a pre-trained object detection model, the processor 1001 specifically performs the following operations:
[0138] Collect training samples of image generation models containing various objects;
[0139] Create an object detection model;
[0140] Obtain the first position information and the first category information of each object in the output image from the model training sample and input the n-th image into the object detection model;
[0141] Constructing a target label in the nth image; wherein the target label includes second position information and second category information;
[0142] Determining a weight value of a loss function according to the second position information;
[0143] Constructing a loss function of an object detection model according to the first position information and the first category information, the second position information and the second category information, and the weight value;
[0144] Inputting the first position information and the first category information into a loss function of an object detection model, and outputting a loss value of the model;
[0145] Optimize the object detection model based on the loss value to generate a trained object detection model;
[0146] The trained object detection model is determined as the pre-trained object detection model.
[0147] In one embodiment, when the processor 1001 executes the first position information and the first category information of each object in the output image in the object detection model of the nth image input obtained from the model training sample, the processor 1001 specifically performs the following operations:
[0148] Obtain the nth image from the model training sample and input it into the feature extraction module to obtain an image feature map;
[0149] Generate multiple candidate regions of different sizes and aspect ratios for each position in the image feature map;
[0150] After classifying and adjusting the position of the candidate areas using the classification module and the regression module, the first position information and the first category information of each object in the image are output.
[0151] In one embodiment, when the processor 1001 determines the weight value of the loss function according to the second position information, the processor 1001 specifically performs the following operations:
[0152] When the length is greater than the width, the ratio of the length to the width is determined as the target ratio;
[0153] or,
[0154] When the length is smaller than the width, the ratio of the width to the length is determined as the target ratio;
[0155] When the target ratio is greater than a preset determination threshold, the ratio of the target ratio to the preset determination threshold is determined as a weight value of the loss function;
[0156] or,
[0157] When the target ratio is less than or equal to the preset determination threshold, the positive integer 1 is determined as the weight value of the loss function.
[0158] In one embodiment, when the processor 1001 optimizes the object detection model based on the loss value to generate the trained object detection model, the processor 1001 specifically performs the following operations:
[0159] Derivative the parameters of the object detection model according to the loss value to generate a local gradient sequence;
[0160] The object detection model is iteratively optimized using the stochastic gradient descent algorithm and the local gradient sequence;
[0161] When the number of iterative optimizations is equal to the preset upper limit or the loss value is less than the preset threshold, stop optimizing the model;
[0162] Generate a trained object detection model.
[0163] In one embodiment, when the processor 1001 stops optimizing the model when the number of optimization times of iterative optimization is equal to a preset upper limit value or the loss value is less than a preset threshold value, the processor 1001 specifically performs the following operations:
[0164] When the number of iterative optimization is less than the preset upper limit or the loss value is greater than or equal to the preset threshold, continue to execute the step of obtaining the n+1th image input into the object detection model from the model training samples, and when n+1 is greater than the number of model training samples, randomly arrange the order of the images in the model training samples and reset n=1.
[0165] In an embodiment of the present application, the device for detecting objects in an image first obtains the target image to be detected, and then inputs the target image to be detected into a pre-trained object detection model, wherein the loss function of the pre-trained object detection model is generated by weighting after determining the weight value according to the aspect ratio of the object in the image data, and then outputs the position of each object in the target image and multiple category probability values, and finally determines the final category of each object according to the multiple category probability values. Since the weight value is determined by the aspect ratio of the object, and the weight value is used to increase the weight of the loss function of the model, the model has a greater loss for objects with a large aspect ratio, thereby improving the detection performance of the model for objects with a large aspect ratio.
[0166] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0167] The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A method for detecting objects in an image, It is characterized in that The method comprises: Acquire the target image to be detected; Inputting the target image to be detected into a pre-trained object detection model; wherein the loss function of the pre-trained object detection model is generated by weighting after determining a weight value according to the aspect ratio value of the object in the image data; Outputting the position of each object in the target image and multiple category probability values; Determining a final category of each object according to the multiple category probability values; The pre-trained object detection model is generated according to the following steps, including: Collect training samples of image generation models containing various objects; Create an object detection model; Obtaining an nth image from the model training sample and inputting it into the object detection model, and outputting first position information and first category information of each object in the image; Constructing a target label in the nth image; wherein the target label includes second position information and second category information; Determining a weight value of a loss function according to the second position information; Constructing a loss function of the object detection model according to the first position information and the first category information, the second position information and the second category information, and the weight value; Inputting the first position information and the first category information into a loss function of the object detection model, and outputting a loss value of the model; Optimizing the object detection model based on the loss value to generate a trained object detection model; Determining the trained object detection model as a pre-trained object detection model; Define the target ratio as: , To take the larger value between w and h, To take the smaller value between w and h, w is the length of the target, h is the width of the target; according to the target ratio Determine the required weights for the loss function ,like When it is greater than the preset judgment threshold r, The target ratio The ratio of the preset judgment value r, if When it is less than or equal to the preset judgment threshold r, is 1; The available formula is: ; Specifically, the constructed loss function is: ; in, Indicates the index number of the candidate region. Represents the output category of the object detection model regarding this area, Indicates the true category corresponding to this area, that is, the category in the target label; Represents the output position information of the object detection model for this area, Indicates the real location information of the target corresponding to this area. Indicates whether the candidate target is a positive sample, that is, whether it matches one or more real targets. When the candidate region is a positive sample, =1, otherwise =0, when the candidate region is a positive sample, the aspect ratio weight of the candidate region is , by the weight value The formula is calculated; when the candidate area is the background area, that is, the candidate area does not correspond to any real target, Set to 0, Represents the classification loss, which is designed as cross entropy loss according to the task requirements. Represents the position loss, which is smooth-L1 loss or IoU-based loss. Represents the sum of the number of positive samples and negative samples, represents the number of negative samples, is the weight to balance the classification loss and location loss.
2. The method according to claim 1, It is characterized in that The pre-trained object detection model includes a feature extraction module, a classification module and a regression module; The step of obtaining the nth image from the model training sample and inputting it into the object detection model, and outputting the first position information and the first category information of each object in the image, comprises: Obtaining the nth image from the model training sample and inputting it into the feature extraction module to obtain an image feature map; Generating a plurality of candidate regions of different sizes and aspect ratios for each position of the image feature map; After the classification module and the regression module are used to classify and adjust the position of the candidate area, the first position information and the first category information of each object in the image are output.
3. The method according to claim 1, It is characterized in that The step of optimizing the object detection model based on the loss value to generate a trained object detection model includes: Derivative the parameters of the object detection model according to the loss value to generate a local gradient sequence; Iteratively optimizing the object detection model using a stochastic gradient descent algorithm and the local gradient sequence; When the optimization times of the iterative optimization are equal to a preset upper limit value or the loss value is less than a preset threshold value, the optimization of the model is stopped; Generate a trained object detection model.
4. The method according to claim 3, It is characterized in that When the optimization times of the iterative optimization are equal to a preset upper limit value or the loss value is less than a preset threshold value, stopping the optimization of the model comprises: When the number of optimization times of the iterative optimization is less than a preset upper limit value or the loss value is greater than or equal to a preset threshold value, continue to execute the step of obtaining the n+1th image from the model training sample and inputting it into the object detection model, and when n+1 is greater than the number of the model training samples, randomly arrange the order of the images in the model training samples and reset n=1.
5. The method according to claim 1, It is characterized in that Determining the final category of each object according to the multiple category probability values includes: Selecting the maximum probability value among the plurality of class probability values; Identify the category corresponding to the selected maximum probability value; The category corresponding to the maximum probability value is determined as the final category of each object.
6. A device for detecting objects in an image, It is characterized in that The device comprises: An image acquisition module, used to acquire a target image to be detected; An image input module, used for inputting the target image to be detected into a pre-trained object detection model; wherein the loss function of the pre-trained object detection model is generated by weighting after determining a weight value according to the aspect ratio value of the object in the image data; An output module, used to output the position of each object in the target image and multiple category probability values; A final category determination module, used to determine the final category of each object according to the multiple category probability values; The pre-trained object detection model is generated according to the following steps, including: Collect training samples of image generation models containing various objects; Create an object detection model; Obtaining an nth image from the model training sample and inputting it into the object detection model, and outputting first position information and first category information of each object in the image; Constructing a target label in the nth image; wherein the target label includes second position information and second category information; Determining a weight value of a loss function according to the second position information; Constructing a loss function of the object detection model according to the first position information and the first category information, the second position information and the second category information, and the weight value; Inputting the first position information and the first category information into a loss function of the object detection model, and outputting a loss value of the model; Optimizing the object detection model based on the loss value to generate a trained object detection model; Determining the trained object detection model as a pre-trained object detection model; Define the target ratio as: , To take the larger value between w and h, To take the smaller value between w and h, w is the length of the target, h is the width of the target; according to the target ratio Determine the required weights for the loss function ,like When it is greater than the preset judgment threshold r, The target ratio The ratio of the preset judgment value r, if When it is less than or equal to the preset judgment threshold r, is 1; The available formula is: ; Specifically, the constructed loss function is: ; in, Indicates the index number of the candidate region. Represents the output category of the object detection model regarding this area, Indicates the true category corresponding to this area, that is, the category in the target label; Represents the output position information of the object detection model for this area, Indicates the real location information of the target corresponding to this area. Indicates whether the candidate target is a positive sample, that is, whether it matches one or more real targets. When the candidate region is a positive sample, =1, otherwise =0, when the candidate region is a positive sample, the aspect ratio weight of the candidate region is , by the weight value The formula is calculated; when the candidate area is the background area, that is, the candidate area does not correspond to any real target, Set to 0, Represents the classification loss, which is designed as cross entropy loss according to the task requirements. Represents the position loss, which is smooth-L1 loss or IoU-based loss. Represents the sum of the number of positive samples and negative samples, represents the number of negative samples, is the weight to balance the classification loss and location loss.
7. A computer storage medium, It is characterized in that The computer storage medium stores a plurality of instructions, which are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 5.
8. A terminal, It is characterized in that include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps as claimed in any one of claims 1 to 5.
Citation Information
Patent Citations
Object detection network training method and device
CN109117831A
Pedestrian identification method under road traffic environment based on improved YOLOv3.
CN109325418A
Underwater target detection method based on improved YOLO algorithm
CN110765865A
Automatic and accurate detection method for multiple small targets
CN111738070A
Key point target detection method based on YOLO
CN111814827A
