{'fraction_non_alphanumeric': 0.02980335927898402, 'fraction_numerical': 0.010241704219582138, 'mean_word_length': 4.7709810874704495, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Learning-Based Depth and Pose Estimation for Monocular Endoscope with Loss Generalization

Gastroendoscopy has been a clinical standard for diagnosing and treating conditions that affect a part of a patient's digestive system, such as the stomach. Despite the fact that gastroendoscopy has a lot of advantages for patients, there exist some challenges for practitioners, such as the lack of 3D perception, including the depth and the endoscope pose information. Such challenges make navigating the endoscope and localizing any found lesion in a digestive tract difficult. To tackle these problems, deep learning-based approaches have been proposed to provide monocular gastroendoscopy with additional yet important depth and pose information. In this paper, we propose a novel supervised approach to train depth and pose estimation networks using consecutive endoscopy images to assist the endoscope navigation in the stomach. We firstly generate real depth and pose training data using our previously proposed whole stomach 3D reconstruction pipeline to avoid poor generalization ability between computer-generated (CG) models and real data for the stomach. In addition, we propose a novel generalized photometric loss function to avoid the complicated process of finding proper weights for balancing the depth and the pose loss terms, which is required for existing direct depth and pose supervision approaches. We then experimentally show that our proposed generalized loss performs better than existing direct supervision losses.


I. INTRODUCTION
Gastroendoscopy is one of the golden standards for finding and treating abnormalities inside a patient's digestive tract, including the stomach. Even though gastroendoscopy gives enormous advantages for the patient, such as no need for invasive surgeries, it is known that there exist some challenges for medical practitioners, such as the loss of depth perception and the difficulty in assessing the endoscope pose. These challenges lead to difficulties in navigating and understanding the scene captured by the endoscope system, making the localization of a found lesion hard for the practitioners.
Previous studies have proposed to reconstruct the 3D model of a whole stomach with its texture [1]- [3] to provide a global view of the stomach and the estimated endoscope trajectory. It enables medical practitioners to perform a second inspection with more degree of freedom after an initial gastroendoscopy procedure. While the whole stomach 3D reconstruction provides the depth and the endoscope trajectory, the methods [1], [2] cannot be done alongside the gastroendoscopy procedure in real-time.
Recent developments in endoscopy systems introduce a stereo camera to provide real-time depth information [4]- [7]. While the stereo endoscope solves the lack of depth perception, a monocular endoscope is still the mainstream system in clinical practice. As an alternative to the stereo endoscope, deep learning-based approaches have been proposed to provide depth information for monocular endoscopy [8]- [10].
To effectively tackle the endoscope navigation and the lesion localization challenges, only providing depth information is not enough. Both continuous depth and pose information are needed to address these challenges appropriately. Both supervised and self-supervised deep-learningbased approaches are heavily adopted to address simultaneous depth and pose estimation [11]- [15]. A commonly used supervision approach is to take the direct Euclidean distance losses for the predicted depth and pose in comparison with the respective ground truths or references [11], [13]. In this approach, computer-generated (CG) and/or phantom models are commonly used for the training of depth and pose estimation networks, affecting the network generalization between CG and real data. In addition, the direct supervision approach needs balancing weights for depth and pose loss terms, which are difficult to search [16].
As a self-supervised approach, the study [12] uses consecutive frames as the inputs to train the network to simultaneously predict depth and pose by minimizing the photometric error of a view synthesis problem (image warping between consecutive frames based on the predicted depth and pose). Using the same principle, the study [14] trains a recurrent neural network to predict the depth and the pose and uses them as the inputs for standard SLAM [17] for further refinement. Since it needs an additional hand-crafted method bootstrapped to the network architecture, this approach is not trainable in an end-to-end manner. Even though a selfsupervised training approach does not need labeled data for training and thus it is generally more convenient to train, its performance is yet to beat the supervised approach.
In this paper, we propose a supervised approach to simultaneously train depth and pose networks using consecutive images for monocular endoscopy of the stomach. To avoid the generalization problem between CG and real data, we (a) Network structure [18].
(b) Self-supervised photometric loss [18].  In both (c) and (d), the loss in the purple-colored box is used for training the depth estimation network and the loss in the pink-colored box is used for training the pose estimation network. The existing depth and pose supervision approach trains the depth and the pose estimation networks by directly taking the Euclidean distance between the predicted depth and its reference and also between the predicted pose and its reference, respectively. This direct supervision approach needs balancing the weights for each loss term, which are difficult to search, because their physical meanings are different. In our proposed generalize loss, we adjusted our loss terms so that each of them has the same physical meaning, i.e., the photometric error. This generalization eliminates the need for the balancing weight search.
apply the whole stomach 3D reconstruction pipeline [2] to generate reference depth and pose from real endoscope data for network training. Additionally, we propose a novel loss generalization by unifying the depth and the pose losses into a photometric error loss for our supervised training to avoid the necessity of delicate weight balancing between the depth and the pose losses. Finally, we show that our supervised training with a novel generalized loss function has better performance than the existing direct depth and pose supervision. Our method achieves up to 60fps at test time for depth and pose predictions. Figure 1(a) overviews the network structures used in our experiment and Figure 1(b)-(d) show how we train them using three different methods, i.e., an existing selfsupervised photometric loss [18], an existing direct depth and pose losses [10], [11] combined with the photometric loss, and our proposed generalized photometric loss. In this section, we firstly explain the endoscope dataset (Section II-A). We then review the existing self-supervision and direct supervision methods (Section II-B, II-C). Finally, we explain our proposed loss generalization (Section II-D).

A. Training data generation
In this work, we used the same endoscope video dataset from our previous work [2]. We used six subjects' endoscope videos undergone general gastroendoscopy procedure. We then extracted all the image frames from all the videos and used them as training and testing data. The experimental protocol was approved by the research ethics committee of Tokyo Institute of Technology and Nihon University Hospital. Fig. 2: Some examples of the generated reference depth based on the estimated camera poses and the obtained whole stomach 3D model using [2]. We can see that the generated reference depth images reflect the structures seen in the color images.
For the direct supervision (Section II-C) and the proposed loss generalization (Section II-D) methods, we used the previously extracted real endoscope image frames to generate the reference depth and pose. For this purpose, we firstly applied the whole stomach 3D reconstruction pipeline [2] and then extracted the reference depth and pose from the generated whole stomach 3D model and the estimated endoscope poses. Figure 2 shows some of the RGB images and the generated reference depths. We used the generated reference depth and pose for both training and testing. B. Self-supervised depth and pose estimation Our depth and pose estimation networks are inspired by monodepth2 architecture [18] shown in Figure 1(a). It consists of two separate networks, each for depth and pose estimation purpose. Both networks are trained together to learn a view-synthesis problem, i.e., to predict the appearance of a target image given a view point of another image by minimizing its photometric error.
Let I t be a target frame and I t be a source frame. The objective of the network is to minimize a photometric error pe between a target frame and a warped source frame. In general, a photometric error pe between two images A and B can be defined using pixel value difference (L1) and structural similarity index measure (SSIM) [19] such that where α is the balancing term between the L1 and the SSIM terms. LetD t be the predicted depth of the target frame I t , T t→t be the predicted relative pose from the target frame I t to the source frame I t , and K be a calibrated camera intrinsic parameters. We then define the view synthesis (image warping) problem as where π is a function to project the pixel coordinate of target image I t in source image I t and is a pixel sampling function based on the projected pixel coordinate given by π.
In our implementation, we used two consecutive frames as our source frames, i.e., I t+1 and I t−1 . Instead of averaging the photometric error pe for each warped source frame, we simply take the minimum such that the final pixel-wise photometric error can be expressed as To ensure that only the reliable pixels are optimized, we masked out the non-reliable pixel using the automask [18] defined by a logical operation as (4) We also used edge-aware smoothness so that there is no discontinuities in the predicted depth [20] that can be expressed as where ∂ x and ∂ y is the partial derivative on each x and y direction andd * t is the mean-normalized predicted inverse depth [21]. The final self-supervised loss function consists of the masked photometric error and the smoothness term as where i represents a pixel index, N is the total number of the pixels, and λ is the balancing weight between the photometric error and the depth smoothness loss.

C. Supervised depth and pose estimation
To supervise the depth estimation network, we followed the method [22] and used inverse depth d instead of depth D. We followed a standard inverse depth error loss function which compares the inverse depth predictiond t and its reference inverse depth d t . It consists of three sub-components which can be formulated as follows The total loss for depth supervision can finally be expressed as For the pose estimation supervision, the common practice is to directly supervise the pose estimation network by measuring Euclidean distance between the predicted relative pose and its reference pose [11], [16], [23], i.e., where x is the translation vector component and r is the rotation vector components in the axis-angle representation from the relative pose T t→t . The translation and rotation terms are balanced by ζ and θ as weights. To tie L d and L pose together, a photometric loss L p is added to the direct supervision loss. Finally, the total supervised loss can be expressed as where ψ and γ are balancing weights for depth and pose losses.

D. Loss generalization
Since each of the components in (10) in the commonly used supervised loss has different physical meaning, the weight of each component has to be carefully selected, which is very difficult and usually performed in an empirical manner. It is also common that different weight balancing is needed for different kinds of environment such as outdoor and indoor scenes [16]. To address this limitation, we propose a novel depth and pose supervision loss function by generalizing the depth and the pose errors into the same physical meaning, i.e, a photometric error.
As illustrated in Figure 1(d), in order to generalize the loss into a photometric error, we use the reference relative pose T t→t to train the depth estimation network by optimizing the predicted depthD t such that pe(I t , (I t , π(D t , T t→t , K))) (11) Input image Reference depth Self-supervised [18] Direct supervision [10], [11] Generalized loss (Ours) Fig. 3: Some examples of depth estimation results. Here we show the RGB images for better visualization, though we actually used red channel images as the input of the network according to the finding in [2]. We compare the depth prediction results of the self-supervision [18], the direct supervision [11], [16], and our proposed generalized loss supervision. As we can see, our proposed method not only estimates closer depth to the reference, but also better estimates the structures and the boundaries, including the endoscope rod. In some cases, the direct supervision results are too smooth.
Conversely, we use the reference depth D t to train the pose estimation network by optimizing the predicted relative posê T t→t such that pe(I t , (I t , π(D t ,T t→t , K))) (12) The term described in (11) can be defined as depth loss w.r.t reference pose as photometric loss while the term described in (12) as pose loss w.r.t reference depth as photometric loss. We also calculate the reliable pixel masks, µ d→p and µ r→p , for each L d→p and L r→p respectively using the same principle as (4). Combining (11) and (12) with (3) to tie the depth and the pose network training together, we can write the final loss function as which eliminates the intricate search of balancing weights for the depth and the pose loss terms.

A. Implementation details
Following [18], we used ResNet-18 architecture [24] for our depth and pose estimation networks. We simultaneously trained our depth and pose estimation networks using a single NVIDIA GeForce GTX 1080Ti GPU. Our networks were trained for 100 epochs with the learning rate of 10 −4 with the decay factor of 10 −1 after 50 epochs. We set the term weights for the self-supervised and the generalized loss training as α = 0.85 and λ = 0.001. Additionally, we set the extra balancing weights for the direct supervision as γ = 30, ζ = ψ = 15, and θ = 160.
We divided six subjects into four subjects for training (Subjects 3-6, 9000 images) and two subject for testing (Subjects 1-2, 2350 images). The image resolution is 288 × 256 pixels. Following the finding of our previous research to tackle the color channel misalignment problem [2], we used only red channel images to train the networks.  where D t is the reference depth andD t is the predicted depth. For the relative error, we calculated the errors for all the pixels of all the frames and evaluated the mean, the maximum, and the median values. For the depth accuracy evaluation, we measured the ratio between the number of pixels that have a lower error than a threshold controlled by k (i.e., δ < 1.25 k ) and the total number of the pixels. Table I shows the objective evaluation results. Since the predicted depth is only up to scale, we scaled the predicted depth by minimizing the average RMSE for the entire sequence. From Table I, we can see that our proposed method has better performance compared to the self-supervised method by a fair margin. In addition, our proposed method generally shows better performance compared to the direct supervision method. Even though our proposed method comes seconds in the median relative error, the values are very close. In addition to the testing on the test data (Subject 1 and 2), we also tested each of the trained networks on the training data. As we can see, the direct supervision has the best results for this evaluation. However, it can be noticed that the performance of the direct supervision on the test data falls sharply compared to its performance on the training data. It shows that the depth estimation network trained with the direct supervision has poor generalization to the data that have never been seen during the training. Figure 4 shows the resulting color point clouds by fusing a single image with its predicted depth. As we can see, the resulting point cloud from our predicted depth is very close to the point cloud from the reference depth.

C. Pose estimation evaluation
For pose estimation evaluation, we first split the full sequences of Subject 1 and 2 into the groups of 150 consecutive frames. The predicted poses were then aligned with the reference poses using Umeyama transform [25]. We then used absolute pose error (APE) to evaluate the translation and rotation components of the predicted posesP ∈ SE(3) against the reference poses P ∈ SE(3). Given the absolute relative pose between a pair of predicted pose and its ground truth E = P −1P , the translation and the rotation errors can be defined as AP E trans = trans(E) 2 where . F is Frobenius norm. We then averaged all the obtained APEs over all of the evaluation points. The objective evaluation results can be seen in Table II. From Table II, we can see that, based on the evaluation on the test data, our proposed generalized loss has better performance compared to the self-supervised and the direct supervision methods. Even though it is evident that the direct supervision has the best result when tested on the training data, its performance drops sharply when tested on the test data. This characteristic is consistent with the results previously shown in the depth estimation evaluation. This is because that the direct supervision losses induce poor generalization performance. In addition, even without the intricate search of the term-balancing weights, our method could achieve the best result for the test data.
Finally, we show the trajectory prediction results in Figure 5, including the trajectory prediction result from ORB- Fig. 5: The predicted trajectory for a sample sequence. As we can see, our prediction result is the closest to the reference. ORB-SLAM [26] could only predict the poses of 16 frames among 150 input frames. SLAM [26]. As we can see, our prediction result is the closest to the reference, while ORB-SLAM could only predict the poses of 16 frames among the 150 input frames.

IV. CONCLUSIONS
In this paper, we have presented a novel generalized photometric loss for learning-based depth and pose estimation with monocular endoscopy. Compared to commonly used direct depth and pose supervision losses, which have different physical meanings for each loss term, we have proposed the generalized loss so that each of the loss terms has the same physical meaning, which is a photometric error. We have experimentally shown that our generalized loss supervision performs better than the direct depth and pose supervision without the need for an intricate search of term-balancing weights. We have also found that the generalization performance from train to test data of our proposed method is better than that of the direct supervision. In future work, we plan to fuse both depth and pose predictions from multiple frames for real-time 3D reconstruction and use the light source information to improve the depth and pose estimation. Additional related results be accessed from (http://www.ok.sc.e.titech.ac.jp/res/Stomach3D/).