A method and device for training a model
By introducing a semi-supervised learning method into the monocular camera depth estimation model and using calibration objects and ground masks to calculate the depth loss, the problem of low depth estimation accuracy in unsupervised learning is solved and more accurate depth prediction is achieved.
Patent Information
- Application Number
- CN201910655547.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-07-19
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2039-07-19
AI Technical Summary
When existing monocular camera depth estimation models are trained through unsupervised learning, the true depth of the scene cannot be accurately predicted due to large relative depth errors.
A semi-supervised learning method is used to obtain scene images containing pre-calibrated calibration objects, calculate the calibration depth, generate a depth map, and calculate the depth loss combined with the ground mask to train the depth estimation model to improve the accuracy of depth prediction.
Calculating the true depth value through calibration reduces errors in unsupervised learning, improves the accuracy of the depth estimation model, and can more accurately predict the true depth of the scene.
Smart Images

Figure CN112241976B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and device for training a model. Background Art
[0002] A monocular camera is a camera device that uses a single lens to shoot. A depth estimation model can be preset in the monocular camera. The depth estimation model is an algorithm for predicting the depth of a scene in an image. The monocular camera can capture a scene image, input the scene image into the depth estimation model, and output a depth map of the scene image.
[0003] At present, unsupervised learning training is usually used to train the depth estimation model in the monocular camera to improve the accuracy of the monocular camera in identifying the scene depth. The specific processing process is: the electronic device obtains the sample scene image and the adjacent frame scene image, inputs the sample scene image and the adjacent frame scene image into the pose estimation model, outputs the pose parameters, inputs the sample scene image into the depth estimation model, and outputs the depth map. The electronic device can calculate the depth loss based on the pose parameters, the depth map and the sample scene image, and train the pose estimation model and the depth estimation model based on the depth loss. Among them, the pose parameters are the translation amount, pitch angle, yaw angle, roll angle and other parameters between the two frames of images. The depth loss is the loss value of the relative depth of the sample scene image and the adjacent frame scene image.
[0004] When users use unsupervised learning to train a depth estimation model, since the unsupervised learning training method is to calculate the relative depth loss value of two adjacent image frames by the difference in the positions of the two adjacent image frames, and then train the estimation model based on the relative depth loss value, there is a large error between the relative depth and the true depth, the trained estimation model cannot accurately predict the true depth of the scene. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a method and device for training a model, and an estimation model trained by an electronic device through the training method can predict the real depth of a scene and improve the accuracy of training. The specific technical solution is as follows:
[0006] In a first aspect, a method for training a model is provided, the method being applied to an electronic device, the method comprising:
[0007] Acquire a first sample scene image, where the first sample scene image is an image containing a pre-calibrated calibration object;
[0008] Obtaining a preset calibration depth of the calibration object, calculating the depth value of each pixel in the first sample scene image according to the calibration depth to obtain a first depth map, and inputting the first sample scene image into a depth estimation model to be trained to output a second depth map;
[0009] Calculating a first depth loss according to a depth value of each pixel in the first depth map and a depth value of each pixel in the second depth map;
[0010] The depth estimation model is trained according to the first depth loss and a preset training algorithm.
[0011] Optionally, after acquiring the first sample scene image, the method further includes:
[0012] If the first sample scene image is an image containing an interference area, obtaining a preset ground mask corresponding to the first sample scene image;
[0013] The calculating a first depth loss according to the depth value of each pixel in the first depth map and the depth value of each pixel in the second depth map includes:
[0014] A first depth loss is calculated according to the depth value of each pixel in the first depth map, the depth value of each pixel in the second depth map, and the ground mask.
[0015] Optionally, the method further includes:
[0016] Acquire a second sample scene image, where the second sample scene image is an adjacent frame image in the sample image set where the first sample scene image is located;
[0017] Inputting the first sample scene image and the second sample scene image into a pose estimation model to be trained, and outputting a first pose parameter;
[0018] Generate a first reconstructed image corresponding to the first sample scene image according to the first pose parameter, the first sample scene image and the second depth map;
[0019] Calculating a second depth loss according to a depth value of each pixel in the first reconstructed image and a depth value of each pixel in the first sample scene image;
[0020] Calculating a third depth loss according to the first depth loss and the second depth loss;
[0021] The pose estimation model is trained according to the third depth loss and the preset training algorithm.
[0022] Optionally, the training the depth estimation model according to the first depth loss and a preset training algorithm includes:
[0023] The depth estimation model is trained according to the third depth loss and the preset training algorithm.
[0024] In a second aspect, a device for training a model is provided, the device being applied to an electronic device, the device comprising:
[0025] A first acquisition module, configured to acquire a first sample scene image, wherein the first sample scene image is an image containing a pre-calibrated calibration object;
[0026] A first output module is used to obtain a preset calibration depth of the calibration object, calculate the depth value of each pixel in the first sample scene image according to the calibration depth, obtain a first depth map, input the first sample scene image into the depth estimation model to be trained, and output a second depth map;
[0027] A first calculation module, configured to calculate a first depth loss according to a depth value of each pixel in the first depth map and a depth value of each pixel in the second depth map;
[0028] The first training module is used to train the depth estimation model according to the first depth loss and a preset training algorithm.
[0029] Optionally, the device further comprises:
[0030] A second acquisition module, configured to acquire a preset ground mask corresponding to the first sample scene image if the first sample scene image is an image containing an interference area;
[0031] The first calculation module is specifically used for:
[0032] A first depth loss is calculated according to the depth value of each pixel in the first depth map, the depth value of each pixel in the second depth map, and the ground mask.
[0033] Optionally, the device further comprises:
[0034] A third acquisition module is used to acquire a second sample scene image, where the second sample scene image is an adjacent frame image in the sample image set where the first sample scene image is located;
[0035] A second output module, used for inputting the first sample scene image and the second sample scene image into a pose estimation model to be trained, and outputting a first pose parameter;
[0036] A generating module, configured to generate a first reconstructed image corresponding to the first sample scene image according to the first posture parameter, the first sample scene image and the second depth map;
[0037] A second calculation module, used for calculating a second depth loss according to a depth value of each pixel in the first reconstructed image and a depth value of each pixel in the first sample scene image;
[0038] A third calculation module, configured to calculate a third depth loss according to the first depth loss and the second depth loss;
[0039] The second training module is used to train the pose estimation model according to the third depth loss and the preset training algorithm.
[0040] Optionally, the first training module is specifically used to:
[0041] The depth estimation model is trained according to the third depth loss and the preset training algorithm.
[0042] In a third aspect, an electronic device is provided, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0043] Memory, used to store computer programs;
[0044] The processor is used to implement the method steps described in the first aspect when executing the program stored in the memory.
[0045] In a fourth aspect, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the method steps described in the first aspect are implemented.
[0046] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the method described in the first aspect.
[0047] The embodiment of the present application provides a method and device for training a model. An electronic device can obtain a first sample scene image, which is an image containing a pre-calibrated calibration object. The electronic device can obtain the preset calibration depth of the calibration object, calculate the depth value of each pixel in the first sample scene image according to the calibration depth, obtain a first depth map, and input the first sample scene image into the depth estimation model to be trained, and output a second depth map. The electronic device can calculate the first depth loss according to the depth value of each pixel in the first depth map and the depth value of each pixel in the second depth map. The electronic device can train the depth estimation model according to the first depth loss and the preset training algorithm. In this way, the electronic device can calculate the true depth value of the sample scene image by calibration. Through the true depth value, the electronic device can calculate the depth loss. Since the electronic device adds calibration points to the unsupervised learning training method for supervised learning, a semi-supervised learning method is formed. Therefore, the estimation model trained by the semi-supervised learning training method can predict the true depth of the scene.
[0048] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0050] Figure 1 A flow chart of a method for training a model provided in an embodiment of the present application;
[0051] Figure 2 A schematic diagram of the effect of a training model provided in an embodiment of the present application;
[0052] Figure 3 A flow chart of a method for training a model provided in an embodiment of the present application;
[0053] Figure 4 A system block diagram of an implementable solution provided in an embodiment of the present application;
[0054] Figure 5 A system block diagram of an implementable solution provided in an embodiment of the present application;
[0055] Figure 6 A system block diagram of an implementable solution provided in an embodiment of the present application;
[0056] Figure 7 A system block diagram of an implementable solution provided in an embodiment of the present application;
[0057] Figure 8 A schematic diagram of the structure of a device for training a model provided in an embodiment of the present application;
[0058] Fig. 9 A schematic diagram of the structure of a device for training a model provided in an embodiment of the present application;
[0059] Fig.10 A schematic diagram of the structure of a device for training a model provided in an embodiment of the present application;
[0060] Fig.11 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0061] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0062] The embodiment of the present application provides a method for training a model, which can be applied to an electronic device. After a user uses a camera to capture a scene image, the captured scene image can be input into the electronic device. The electronic device can train an estimation model through a training algorithm. In the embodiment of the present application, the estimation model can include a depth estimation model and a pose estimation model. The electronic device can be a mobile terminal (such as a tablet computer) or a PC (English: personal computer, Chinese: personal computer) terminal.
[0063] The following will describe in detail a method for training a model provided in an embodiment of the present application in combination with a specific implementation method. Figure 1 As shown, the specific steps are as follows:
[0064] Step 101: Acquire a first sample scene image.
[0065] The first sample scene image is an image containing a pre-calibrated calibration object, and the calibration objects in the same scene are the same.
[0066] In an embodiment of the present application, a camera device can take an image of a scene as a first sample scene image and send it to an electronic device. The electronic device can obtain a first sample scene image, which contains a pre-calibrated calibration object. Among them, the calibration object is a mark point set manually in the scene, and the mark point is an object marked by a user in a scene. The electronic device can obtain the real distance from the calibration object to the lens on the camera device, and the real distance is the calibration depth. Since the electronic device obtains the calibration depth by manually setting the mark point, it abandons expensive equipment such as conventional lidar, which saves the cost of training the model to a certain extent.
[0067] Optionally, after acquiring the first sample scene image, the electronic device may also acquire a ground mask of the first sample scene image to filter out interference areas in the first sample scene image. The specific processing process may be: if the first sample scene image is an image containing an interference area, then acquiring a preset ground mask corresponding to the first sample scene image.
[0068] In an embodiment of the present application, the electronic device can detect the interference area in the sample scene image and obtain the ground mask through the ground segmentation network preset in the sample scene image. The ground segmentation network can be used to segment the sample scene image to obtain the ground mask corresponding to the sample scene image. The interference area may include ground reflection, ground shadow, and ground water stains. The pixel value of the pixel point in the interference area in the sample scene image is lower than the pixel value of the pixel point in the non-interference area in the sample scene image, so an area inconsistent with the actual scene will be formed during the imaging process. If the electronic device detects that there is an interference area in the first sample scene image, the electronic device can obtain the ground mask of the first sample scene image, wherein the function of the ground mask is to remove the pixel values of the pixel points in the interference area that appear in the calculation process by mathematical methods during the process of the electronic device calculating the depth loss. That is, the problem of serious errors in depth estimation in scenes such as ground reflection, self-ground projection, and ground water stains is solved.
[0069] The embodiment of the present application provides an implementation method for an electronic device to distinguish between an interference area and a non-interference area. The specific processing process may be: the electronic device may determine whether the pixel point is a pixel point in the interference area based on the pixel value of the pixel point in the image. Among them, the electronic device may obtain the pixel value of each pixel point in the sample scene image, and predict the height of the pixel point from the horizontal ground in the actual scene through the pixel value. When there is an interference area in the image, the pixel value of the pixel point in this area is often lower than the pixel value of the pixel point in the non-interference area at the same height and depth. Therefore, the electronic device can determine whether the pixel point in the sample scene image is a pixel point in the interference area. If the pixel value of the pixel point predicted by the electronic device is lower than the pixel value of the pixel point in the non-interference area, the electronic device can determine that the pixel point is a pixel point in the interference area. Otherwise, the electronic device can determine that the pixel point is a pixel point in the non-interference area. When the electronic device calculates the loss later, the electronic device can filter out the pixel value of the pixel point in the interference area through the ground mask.
[0070] Step 102: obtain a calibration depth of a preset calibration object, calculate the depth value of each pixel in the first sample scene image according to the calibration depth, obtain a first depth map, input the first sample scene image into a depth estimation model to be trained, and output a second depth map.
[0071] In an embodiment of the present application, the electronic device can input the depth of the calibrated object into a homography matrix, and the homography matrix can calculate the depth of all pixels in the first sample scene image, thereby obtaining a first depth map. Among them, the homography matrix is a matrix calculated by the electronic device based on the intrinsic and extrinsic parameters of the lens of the camera device. After the electronic device obtains the first depth map, the pixel value of the pixel point in the first depth map can be used as the true value of the depth of the first sample scene image. In the subsequent training process of the depth estimation model, the electronic device can calculate the loss based on the first depth map as the true value of the depth.
[0072] The electronic device may also input the first sample scene image into a depth estimation model to be trained, wherein the depth estimation model may be a neural network model (e.g., a convolutional neural network model), and the electronic device may input the first sample scene image into the depth estimation model to be trained, and output a depth map of the first sample scene image. After the electronic device inputs the first sample scene image into the depth estimation model to be trained, the depth estimation model may output a second depth map. The second depth map is a depth map predicted by the electronic device through the depth estimation model, and the pixel values of the pixels in the second depth map are predicted values.
[0073] Step 103: Calculate a first depth loss according to the depth value of each pixel in the first depth map and the depth value of each pixel in the second depth map.
[0074] In the embodiment of the present application, after the electronic device obtains the first depth map and the second depth map, it can calculate the first depth loss according to the depth value of each pixel in the first depth map and the depth value of each pixel in the second depth map. The depth loss can represent the deviation of the predicted value compared to the true value, and the electronic device can train the estimation model according to the deviation.
[0075] The embodiment of the present application provides a formula for calculating the first depth loss, and the specific formula is as follows:
[0076]
[0077] Among them, gt (Chinese: ground truth, English: ground truth) is the ground truth, pt (Chinese: pixel point, English: point), L gt is the first depth loss, D(pt) is the depth value of each pixel in the second depth map, gt(pt) is the depth value of each pixel in the first depth map, and count(pt) is the number of pixels in the depth map. The formula for calculating the first depth loss can be used for more than just calculating the first depth loss, and this embodiment of the application does not limit this.
[0078] Optionally, the process of calculating the first depth loss may further include: calculating the first depth loss according to the depth value of each pixel in the first depth map and the depth value of each pixel in the second depth map.
[0079] In an embodiment of the present application, if there is an interference area in the first sample scene image, the electronic device can calculate the first depth loss based on the depth value of each pixel in the first depth map, the depth value of each pixel in the second depth map, and the ground mask. Among them, the depth value of each pixel in the first depth map can be considered to be the true value of the depth of each pixel in the first sample scene image, and the depth value of each pixel in the second depth map is the predicted depth value of each pixel in the first sample scene image. The ground mask can be reflected in the process of calculating the depth loss in the form of "0" or "1". When the electronic device calculates the first depth loss, the electronic device can multiply the items of the pixel points in the interference area by "0" so that the items of the pixel points in the interference area are "0", and the electronic device can multiply the items of the pixel points in the non-interference area by "1" so that the items of the pixel points in the non-interference area are not affected.
[0080] Step 104: train a depth estimation model according to the first depth loss and a preset training algorithm.
[0081] In an embodiment of the present application, the electronic device can train the depth estimation model according to the first depth loss and a preset training algorithm. The training algorithm can train the estimation model according to the depth loss between the real depth of the sample scene image and the depth predicted by the estimation model, and the training algorithm can include but is not limited to a back propagation algorithm or a gradient back propagation update algorithm.
[0082] Optionally, the process of training the pose estimation model may include:
[0083] Step 1: Obtain a second sample scene image.
[0084] In an embodiment of the present application, the electronic device may obtain a second sample scene image, which is an adjacent frame image in the sample image set where the first sample scene image is located. The image set may be a group of sample scene images continuously captured by a camera device in a certain scene, and the image set may include several frame images.
[0085] Step 2: Input the first sample scene image and the second sample scene image into the pose estimation model to be trained, and output the first pose parameter.
[0086] The electronic device can input the first sample scene image and the second sample scene image into the pose estimation model to be trained, and output the first pose parameter. The pose estimation model is an estimation model, and the electronic device can input two images into the pose estimation model to obtain the parameters of the relative position relationship between the two images, that is, the pose parameters.
[0087] Step three: generating a first reconstructed image corresponding to the first sample scene image according to the first pose parameter, the first sample scene image and the second depth map.
[0088] In the embodiment of the present application, the electronic device can generate a first reconstructed image corresponding to the first sample scene image according to the first pose parameter, the first sample scene image and the second depth map, wherein the first reconstructed image is a predicted depth map of the first sample scene image.
[0089] Step 4: Calculate a second depth loss according to the depth value of each pixel in the first reconstructed image and the depth value of each pixel in the first sample scene image.
[0090] In the embodiment of the present application, the electronic device can calculate the second depth loss according to the depth value of each pixel in the first reconstructed image and the depth value of each pixel in the first sample scene image. The depth value of each pixel in the first reconstructed image is a predicted depth value, and the depth value of each pixel in the first sample scene image is a depth value calculated by calibrating the object. The second depth loss is the depth value of each pixel in the first reconstructed image and the depth value of each pixel in the first sample scene image, and the depth value of each pixel in the first reconstructed image and the depth value of each pixel in the first sample scene image are calculated by the above
[0091]
[0092] Formula, calculate the second depth loss. Among them, L gt is the second depth loss, D(pt) is the depth value of each pixel in the first reconstructed image, gt(pt) is the depth value of each pixel in the first sample scene image, and count(pt) is the number of pixels in the depth map.
[0093] In the process of calculating the second depth loss, gt(pt) is the absolute depth value calculated by the electronic device according to the calibrated depth (ie, the true depth of the first sample scene image), so the second depth loss L gt It is the loss calculated based on the real depth of the first sample scene image. If the user wants to obtain the second depth loss of the relative depth at a certain scale, the user can add one or more scale factor coefficients to the above formula for calculating the second depth loss through an electronic device, that is, the second depth loss of the relative depth at a certain scale can be obtained. Among them, the scale factor coefficient is a coefficient that can scale the depth value in the formula, so as to fix the second depth loss calculated by the formula to a certain scale, and then fix the estimation model calculated by the loss to a certain scale.
[0094] Step 5: Calculate the third depth loss according to the first depth loss and the second depth loss.
[0095] In the embodiment of the present application, the electronic device can calculate the third depth loss according to the first depth loss and the second depth loss. The third depth loss is the first depth loss (which can be called supervised loss) and the second depth loss (which can be called unsupervised loss), and the depth loss is calculated according to the weights of the first depth loss and the second depth loss through a weighted average algorithm.
[0096] When calculating the first depth loss, the electronic device can introduce a ground mask to filter out errors caused by the interference area during the training process. Therefore, when the electronic device trains the pose estimation model, since the electronic device introduces the first depth loss to train the pose estimation model, the electronic device can also filter out errors caused by the interference area to the sample scene image during the training process.
[0097] Step 6: Train the pose estimation model according to the third depth loss and a preset training algorithm.
[0098] In the embodiment of the present application, the training algorithm for training the pose estimation model may be, but is not limited to, a gradient back-propagation update algorithm.
[0099] Optionally, for the above process of training the pose estimation model, the specific processing process of training the depth estimation model may be: training the depth estimation model according to the third depth loss and a preset training algorithm.
[0100] In an embodiment of the present application, based on the third depth loss and a preset training algorithm, the process of training the depth estimation model is an unsupervised training process. Since the electronic device introduces a calibration depth in the process of calculating the third depth loss, after the electronic device trains the depth estimation model, the depth model can more accurately predict the depth of the scene image.
[0101] like Figure 2 As shown, Figure 2 A comparison diagram of the effects of an estimation model after training an electronic device in the prior art and an estimation model after training an electronic device in an embodiment of the present application in actual application is shown. The effect comparison diagram includes image group 201, image group 202, image group 203, and image group 204, wherein image group 201 and image group 203 are the same group of scene images taken by a camera device. Image group 202 is a depth map predicted by an estimation model after training an electronic device in the prior art, and image group 204 is a depth map predicted by an estimation model after training an electronic device in an embodiment of the present application. It is obvious that the depth map in image group 204 is clearer than the depth map in image group 202.
[0102] like Figure 3 As shown, the embodiment of the present application also provides an example of a method for training a model, which may specifically include the following steps:
[0103] Step 301: Acquire a sample scene image and adjacent frame images of the sample scene image.
[0104] Step 302: Determine whether the sample scene image contains a calibration object. If the sample scene image contains a calibration object, execute step 303; if the sample scene image does not contain a calibration object, execute step 313.
[0105] Step 303: Determine the calibration depth and ground mask of the calibration object.
[0106] Step 304: Input the sample scene image to the depth estimation model to be trained, and output a first depth map. After executing step 304, execute steps 305 and 308.
[0107] Step 305: Calculate the depth values of all pixels in the sample scene image through the homography matrix and the calibrated depth to obtain a second depth map.
[0108] Step 306: Calculate the first depth loss according to the first depth map, the second depth map and the ground mask. After executing step 306, execute steps 307 and 311.
[0109] Step 307: Train a depth estimation model according to the training algorithm and the first depth loss.
[0110] Step 308: Input the sample scene image and the adjacent frame images into the pose estimation model, and output the pose parameters.
[0111] Step 309: Generate a reconstructed image of the sample scene image according to the sample scene image, the first depth map and the pose parameters.
[0112] Step 310: Calculate a second depth loss according to the reconstructed image and the sample scene image.
[0113] Step 311: Calculate a third depth loss according to the first depth loss and the second depth loss.
[0114] Step 312: train a pose estimation model according to the training algorithm and the third depth loss.
[0115] Step 313: input the sample scene image and the adjacent frame image into the pose estimation model, output the pose parameters, input the sample scene image into the depth estimation model to be trained, and output the third depth map.
[0116] Step 314: Generate a reconstructed image of the sample scene image according to the sample scene image, the third depth map and the pose parameters.
[0117] Step 315: Calculate a fourth depth loss according to the reconstructed image and the sample scene image.
[0118] Step 316: train the pose estimation model and the depth estimation model according to the training algorithm and the fourth depth loss.
[0119] Step 317: Determine whether the training termination condition is met. If the training termination condition is not met, execute step 301.
[0120] A method for training a model provided in an embodiment of the present application, an electronic device can obtain a first sample scene image, the first sample scene image is an image containing a pre-calibrated calibration object. The electronic device can obtain the preset calibration depth of the calibration object, calculate the depth value of each pixel in the first sample scene image according to the calibration depth, obtain a first depth map, and input the first sample scene image into the depth estimation model to be trained, and output a second depth map. The electronic device can calculate the first depth loss according to the depth value of each pixel in the first depth map and the depth value of each pixel in the second depth map. The electronic device can train the depth estimation model according to the first depth loss and the preset training algorithm. In this way, the electronic device can calculate the true depth value of the sample scene image by calibration. Through the true depth value, the electronic device can calculate the depth loss. Since the electronic device adds calibration points to the unsupervised learning training method for supervised learning, a semi-supervised learning method is formed. Therefore, the estimation model trained by the semi-supervised learning training method can predict the true depth of the scene.
[0121] Based on the same technical concept, the embodiment of the present application also provides a specific implementation method based on monocular depth estimation, such as Figure 4 , Figure 5 , Figure 6 and Figure 7 As shown, the specific implementation method may be:
[0122] Figure 4 is a system block diagram of the monocular depth estimation solution of the embodiment of the present application. Figure 4 As shown, in the training of the monocular depth estimation network model, the ground depth truth and the depth map estimated by the network are used to calculate the ground loss of the network, and then the loss is used for back propagation to update the parameters of the monocular depth estimation neural network, thereby achieving the training purpose of the monocular depth estimation neural network.
[0123] exist Figure 4Module 101 in describes the ground mask and depth value of the training sample. When the monocular lens image training data is collected, continuous images taken by a single camera can be obtained. The lens installation posture needs to be calibrated before collecting data, and the lens is fixed during the collection process. The embodiment of the present application proposes to obtain a ground mask for some of the samples using ground marking. The ground here refers to the approximately horizontal ground. If the ground slope is very large, it is not marked. The homography matrix of the horizontal ground can be calculated using the intrinsic and extrinsic parameters of the lens. For any ground pixel point in the image, the depth value can be calculated using the homography matrix. This method can be used to calculate the depth values of all calibrated grounds, so as to construct a supervised loss as a true value in model training to update the network parameters. In practical applications, a ground segmentation network can be used to preprocess the training samples to obtain a ground mask, and then the homography matrix can be used to calculate the corresponding depth value. The ground depth value used in this scheme is not limited to the above two schemes, and can also be obtained using laser and other schemes.
[0124] Figure 4 105 is the ground truth loss construction module when training the model. For the ground part of the sample, its depth value is known. After the network outputs the depth value, it can directly construct a general L1 loss or other effective types of losses, and then update the neural network weights through the gradient back propagation method. When calculating the ground truth loss, there are two ways to calculate the loss for each ground point. One is to directly calculate the L1 loss of the predicted value and the true value, and the other is to calculate the error of each predicted point and divide it by the depth truth value, as shown in formula (1) (2). Due to the large difference between the distance and the nearness on the same image, if the normalization operation of dividing by the true value is not performed, it will result in a large deviation in the near part, but it cannot be well reflected in the calculated loss. In the actual model, the performance is that the distance is better and the near part is worse. The normalization operation of dividing by the true value can improve the distance preference problem of this model. Because the ground loss is calculated using the depth truth value, we call this part of the loss supervised loss. When calculating supervised loss, if the system wants the model to directly predict the absolute depth, the absolute depth of the ground is used in the calculation. If the system wants to obtain the relative depth at a unified scale, the ground depth can be multiplied by a scale factor to obtain the relative depth. In this case, the depth predicted by the trained model is also the relative depth value at this scale. In this way, not only many problems with the ground part of the original model are solved, but also the trained model can be fixed to the scale that the system needs to output according to demand.
[0125]
[0126]
[0127] If the scene below the ground does not exist or does not need to be considered in the application scenario of monocular depth estimation, the embodiment of the present application proposes a ground self-supervision solution to solve the problem of model ground depth prediction errors. The main factors of ground prediction errors are ground reflections, ground water stains, ground reflections and other parts on the image. When the vehicle that collects the image moves, these parts are still in the same position in the image. According to the loss function of the unsupervised monocular depth estimation model, the direction of convergence during model training is to predict the depth values of these areas much greater than their true depths. According to the imaging principle, when the depth of a pixel point is greater than the pixel is a ground point, the height of the point must be lower than the ground. In this scenario, there is no or no ground point. When the predicted height of a pixel point is lower than the ground, it can be considered that the point is predicted incorrectly. The part below the ground in the prediction result is considered to be a ground light spot or a reflection of the vehicle body. In this way, combined with the lens external parameters, the true depth value of this part can be calculated. When training the model, this method can be used to calculate the ground mask and its depth value for each sample in real time during training. After obtaining the ground mask and depth value, the ground loss can be calculated according to the supervised loss calculation method above, thereby achieving the same ground improvement effect as the marked ground. In this scenario, the block diagram of the model training system is as follows: Figure 5 .
[0128] Figure 4 and Figure 5 There are two optional solutions for model training, which can be used in general scenarios Figure 4 The system solution shown in the figure can be selected when the above conditions are met. Figure 5 plan.
[0129] Figure 6 yes Figure 1 An optional solution of the deep neural network module 103 in the present application embodiment includes but is not limited to using Figure 6 The unsupervised depth estimation neural network is trained in the manner shown, Figure 6 It includes a monocular deep neural network and a pose estimation network. The monocular depth estimation network input is a single target frame image, and the output is the depth map corresponding to the frame. The pose estimation neural network input is the target frame and the adjacent frames of the frame, and the output is the pose parameters between the two frames. The adjacent frames can be reconstructed using the pose parameters, depth map and the target frame itself. The network loss is constructed by calculating the similarity between adjacent frames and real adjacent frames, and then the depth estimation network parameters are updated to achieve unsupervised learning.
[0130] According to the above description, the update of the parameters of the monocular depth estimation neural network includes two parts: unsupervised loss and supervised loss. Most of the samples used in model training do not have ground depth values, and only a small amount of data has ground depth values. For the part without ground depth, only unsupervised loss is used to update the network parameters during training. For samples with ground masks and their depth values, supervised loss and unsupervised loss are used to update the neural network parameters. Since the samples with ground truth values only account for a small proportion, we need to use this part of the data with the data without ground truth values when training the model, so that each batch of training contains at least one sample with ground depth information, which can make the network converge faster during training and the trained model generalize better.
[0131] Figure 6 Module 204 is a pose estimation module. The model input is the target frame and the adjacent frame, and the output is a 6-dimensional pose relationship between the target frame and the adjacent frame. The vector describes the rotation and translation between the two frames. During model training, the pose estimation network and the monocular depth estimation network gradually converge together and finally reach stability. When the pose network cannot predict a good result, the network cannot construct a loss that meets the expectation, and the network is difficult to converge to a good performance. Therefore, while improving the depth estimation network, it is also necessary to find a solution to improve the prediction accuracy of the pose estimation network. The pose estimation network is different from the depth estimation network. The network obtains the pose relationship of the camera when taking two images by inputting the global information of the image. In general scenes, the collected training samples are mainly the ground near the bottom and the sky and other distant scenes near the top. The texture of the ground and sky parts is not rich enough, which has a negative impact on pose estimation. During model training in the embodiment of the present application, the pose network only inputs the middle part of the image. This optimized network input can improve the performance of the pose network, and the output camera pose is more accurate, which also improves the overall performance of the depth map output by the depth estimation network to a certain extent.
[0132] like Figure 7 As shown, after the electronic device obtains the training model using the solution proposed in the embodiment of the present application, when performing monocular depth estimation, it only needs to send a single picture into the monocular depth estimation network to output the corresponding depth map. The final effect is as follows Figure 2 As shown, the first row is the depth estimation effect of the monocular depth estimation network 203 before optimization, and the second row is the depth estimation effect of the monocular depth estimation network 103 after optimization using this solution. It can be seen from the figure that the optimization effect of the solution of the embodiment of the present application is significant.
[0133] Based on the same technical concept, the embodiment of the present application also provides a device for training a model, such as Figure 8 As shown, the device comprises:
[0134] A first acquisition module 801 is used to acquire a first sample scene image, where the first sample scene image is an image containing a pre-calibrated calibration object;
[0135] A first output module 802 is used to obtain a preset calibration depth of the calibration object, calculate the depth value of each pixel in the first sample scene image according to the calibration depth, obtain a first depth map, input the first sample scene image into the depth estimation model to be trained, and output a second depth map;
[0136] A first calculation module 803, configured to calculate a first depth loss according to a depth value of each pixel in the first depth map and a depth value of each pixel in the second depth map;
[0137] The first training module 804 is used to train the depth estimation model according to the first depth loss and a preset training algorithm.
[0138] Optional, such as Fig. 9 As shown, the device also includes:
[0139] A second acquisition module 805 is configured to acquire a preset ground mask corresponding to the first sample scene image if the first sample scene image is an image containing an interference area;
[0140] The first calculation module 803 is specifically used for:
[0141] A first depth loss is calculated according to the depth value of each pixel in the first depth map, the depth value of each pixel in the second depth map, and the ground mask.
[0142] Optional, such as Fig.10 As shown, the device also includes:
[0143] A third acquisition module 806 is used to acquire a second sample scene image, where the second sample scene image is an adjacent frame image in the sample image set where the first sample scene image is located;
[0144] A second output module 807, used for inputting the first sample scene image and the second sample scene image into a pose estimation model to be trained, and outputting a first pose parameter;
[0145] A generating module 808, configured to generate a first reconstructed image corresponding to the first sample scene image according to the first pose parameter, the first sample scene image and the second depth map;
[0146] A second calculation module 809, configured to calculate a second depth loss according to a depth value of each pixel in the first reconstructed image and a depth value of each pixel in the first sample scene image;
[0147] A third calculation module 810, configured to calculate a third depth loss according to the first depth loss and the second depth loss;
[0148] The second training module 811 is used to train the pose estimation model according to the third depth loss and the preset training algorithm.
[0149] Optionally, the first training module 804 is specifically used to:
[0150] The depth estimation model is trained according to the third depth loss and the preset training algorithm.
[0151] The embodiment of the present application provides a method and device for training a model. An electronic device can obtain a first sample scene image, which is an image containing a pre-calibrated calibration object. The electronic device can obtain the preset calibration depth of the calibration object, calculate the depth value of each pixel in the first sample scene image according to the calibration depth, obtain a first depth map, and input the first sample scene image into the depth estimation model to be trained, and output a second depth map. The electronic device can calculate the first depth loss according to the depth value of each pixel in the first depth map and the depth value of each pixel in the second depth map. The electronic device can train the depth estimation model according to the first depth loss and the preset training algorithm. In this way, the electronic device can calculate the true depth value of the sample scene image by calibration. Through the true depth value, the electronic device can calculate the depth loss. Since the electronic device adds calibration points to the unsupervised learning training method for supervised learning, a semi-supervised learning method is formed. Therefore, the estimation model trained by the semi-supervised learning training method can predict the true depth of the scene.
[0152] The present application also provides an electronic device, such as Fig.11 As shown, it includes a processor 1101, a communication interface 1102, a memory 1103 and a communication bus 1104, wherein the processor 1101, the communication interface 1102, and the memory 1103 communicate with each other through the communication bus 1104.
[0153] Memory 1103, used for storing computer programs;
[0154] The processor 1101 is used to implement the following steps when executing the program stored in the memory 1103:
[0155] Acquire a first sample scene image, where the first sample scene image is an image containing a pre-calibrated calibration object;
[0156] Obtaining a preset calibration depth of the calibration object, calculating the depth value of each pixel in the first sample scene image according to the calibration depth to obtain a first depth map, and inputting the first sample scene image into a depth estimation model to be trained to output a second depth map;
[0157] Calculating a first depth loss according to a depth value of each pixel in the first depth map and a depth value of each pixel in the second depth map;
[0158] The depth estimation model is trained according to the first depth loss and a preset training algorithm.
[0159] Optionally, after acquiring the first sample scene image, the method further includes:
[0160] If the first sample scene image is an image containing an interference area, obtaining a preset ground mask corresponding to the first sample scene image;
[0161] The calculating a first depth loss according to the depth value of each pixel in the first depth map and the depth value of each pixel in the second depth map includes:
[0162] A first depth loss is calculated according to the depth value of each pixel in the first depth map, the depth value of each pixel in the second depth map, and the ground mask.
[0163] Optionally, the method further includes:
[0164] Acquire a second sample scene image, where the second sample scene image is an adjacent frame image in the sample image set where the first sample scene image is located;
[0165] Inputting the first sample scene image and the second sample scene image into a pose estimation model to be trained, and outputting a first pose parameter;
[0166] Generate a first reconstructed image corresponding to the first sample scene image according to the first pose parameter, the first sample scene image and the second depth map;
[0167] Calculating a second depth loss according to a depth value of each pixel in the first reconstructed image and a depth value of each pixel in the first sample scene image;
[0168] Calculating a third depth loss according to the first depth loss and the second depth loss;
[0169] The pose estimation model is trained according to the third depth loss and the preset training algorithm.
[0170] Optionally, the training the depth estimation model according to the first depth loss and a preset training algorithm includes:
[0171] The depth estimation model is trained according to the third depth loss and the preset training algorithm.
[0172] The communication bus mentioned in the above network device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0173] The communication interface is used for communication between the above network devices and other devices.
[0174] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0175] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components.
[0176] Based on the same technical concept, an embodiment of the present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the method steps of the above-mentioned training model are implemented.
[0177] Based on the same technical concept, an embodiment of the present application also provides a computer program product containing instructions, which, when executed on a computer, enables the computer to execute the above-mentioned method steps for training the model.
[0178] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.
[0179] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0180] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0181] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.
Claims
1. A method for training a model, characterized in that: The method comprises: Acquire a first sample scene image, where the first sample scene image is an image containing a pre-calibrated calibration object; If the first sample scene image is an image containing an interference area, the interference area in the first sample scene image is detected through a ground segmentation network, and the first sample scene image is segmented to obtain a ground mask corresponding to the first sample scene image, wherein the interference area is an area in the first sample scene image that is formed during the imaging process and does not conform to the actual scene, the value corresponding to the non-interference area in the ground mask is 1, and the value corresponding to the interference area in the ground mask is 0, and the ground mask is used to multiply the items of the pixel points in the non-interference area by 1 and the items of the pixel points in the interference area by 0 in the process of calculating the depth loss, so as to filter out the pixel values of the pixel points in the interference area in the first sample scene image; Obtaining a preset calibration depth of the calibration object, calculating the depth value of each pixel in the first sample scene image according to the calibration depth to obtain a first depth map, and inputting the first sample scene image into a depth estimation model to be trained to output a second depth map; Calculating a first depth loss according to the depth value of each pixel in the first depth map, the depth value of each pixel in the second depth map, and the ground mask; The depth estimation model is trained according to the first depth loss and a preset training algorithm.
2. The method according to claim 1, characterized in that: The method further comprises: Acquire a second sample scene image, where the second sample scene image is an adjacent frame image in the sample image set where the first sample scene image is located; Inputting the first sample scene image and the second sample scene image into a pose estimation model to be trained, and outputting a first pose parameter; Generate a first reconstructed image corresponding to the first sample scene image according to the first pose parameter, the first sample scene image and the second depth map; Calculating a second depth loss according to a depth value of each pixel in the first reconstructed image and a depth value of each pixel in the first sample scene image; Calculating a third depth loss according to the first depth loss and the second depth loss; The pose estimation model is trained according to the third depth loss and the preset training algorithm.
3. The method according to claim 2, characterized in that The step of training the depth estimation model according to the first depth loss and a preset training algorithm includes: The depth estimation model is trained according to the third depth loss and the preset training algorithm.
4. A device for training a model, characterized in that: The device comprises: A first acquisition module, configured to acquire a first sample scene image, wherein the first sample scene image is an image containing a pre-calibrated calibration object; A second acquisition module is used to detect the interference area in the first sample scene image through a ground segmentation network when the first sample scene image is an image containing an interference area, and to segment the first sample scene image to obtain a ground mask corresponding to the first sample scene image; wherein the interference area is an area in the first sample scene image that is formed during the imaging process and does not conform to the actual scene, the value corresponding to the non-interference area in the ground mask is 1, and the value corresponding to the interference area in the ground mask is 0, and the ground mask is used to multiply the items of the pixel points in the non-interference area by 1 and the items of the pixel points in the interference area by 0 in the process of calculating the depth loss, so as to filter out the pixel values of the pixel points in the interference area in the first sample scene image; A first output module is used to obtain a preset calibration depth of the calibration object, calculate the depth value of each pixel in the first sample scene image according to the calibration depth, obtain a first depth map, input the first sample scene image into the depth estimation model to be trained, and output a second depth map; A first calculation module, configured to calculate a first depth loss according to a depth value of each pixel in the first depth map, a depth value of each pixel in the second depth map, and the ground mask; The first training module is used to train the depth estimation model according to the first depth loss and a preset training algorithm.
5. The device according to claim 4, characterized in that The device also includes: A third acquisition module is used to acquire a second sample scene image, where the second sample scene image is an adjacent frame image in the sample image set where the first sample scene image is located; A second output module, used for inputting the first sample scene image and the second sample scene image into a pose estimation model to be trained, and outputting a first pose parameter; A generating module, configured to generate a first reconstructed image corresponding to the first sample scene image according to the first posture parameter, the first sample scene image and the second depth map; A second calculation module, configured to calculate a second depth loss according to a depth value of each pixel in the first reconstructed image and a depth value of each pixel in the first sample scene image; A third calculation module, configured to calculate a third depth loss according to the first depth loss and the second depth loss; The second training module is used to train the pose estimation model according to the third depth loss and the preset training algorithm.
6. The device according to claim 5, characterized in that The first training module is specifically used for: The depth estimation model is trained according to the third depth loss and the preset training algorithm.
7. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 3 when executing a program stored in a memory.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Automatic extraction method for newly-increased construction land image spots in high-resolution remote sensing images based on NDVI and PanTex index
CN103971115A
Method for correcting geometrical distortion antifact in fMRI based on field map
CN106204475A
Video sequence monocular view depth estimation optimization method through deep learning
CN108765479A
Monocular depth estimation method and device, terminal, and storage medium
CN109003297A
A multi-person pose estimation method based on mask perceptual depth reinforcement learning
CN109190537A
