# A LiDAR Multi-Object Detection Algorithm for Autonomous Driving
## 2 Methods
### PointPillars Algorithm
#### 2.1.4 Loss Function  
The output of the PointPillars network mainly includes the object class and the 3D bounding box parameters. The total loss function mainly contains the 3D bounding box positioning loss, classification loss, and orientation loss, as shown in Equation (1).  
\[L=\frac{1}{N_{pos}}(\beta_{loc}L_{loc}+\beta_{cls}L_{cls}+\beta_{dir}L_{dir}) \tag{1}\]  
\(N_{pos}\) denotes the number of positive probability anchors, i.e., the number of generated boxes greater than the specified IoU threshold; \(L_{loc}\) represents the regression loss function of the 3D bounding box; \(L_{cls}\) represents the classification loss function; \(L_{dir}\) represents the object orientation loss function. \(\beta_{loc}=2\); \(\beta_{cls}=1\); \(\beta_{dir}=0.2\), which are the corresponding weight coefficients of the three types of loss functions, respectively.  
The positioning loss function of the 3D bounding box mainly contains the position regression loss function, the size regression loss function, and the orientation loss function of the 3D bounding box.  
\[L_{loc}=\sum_{b\in(x,y,z,w,l,h,\theta)}\text{Smooth}_{\text{L1}}(\Delta b) \tag{2}\]  
\[\Delta x=\frac{x_{gt}-x_{p}}{d_{p}},\ \Delta y=\frac{y_{gt}-y_{p}}{d_{p}},\ \Delta z =\frac{z_{gt}-z_{p}}{d_{p}} \tag{3}\]  
\[\Delta w=\log\frac{w_{gt}}{w_{p}},\ \Delta l=\log\frac{l_{gt}}{l_{p}},\ \Delta h=\log\frac{h_{gt}}{l_{p}} \tag{4}\]  
\[\Delta\theta=\sin\bigl{(}\theta_{gt}-\theta_{p}\bigr{)} \tag{5}\]  
where \((x,y,z,w,l,h,\theta)\) are used to characterize the 3D bounding box, where \((x,y,z)\) denotes the coordinates of the center position of the 3D frame in the LiDAR coordinate system; \((w,l,h)\) denotes the width, length, and height of the 3D frame, respectively; \(\theta\) denotes the yaw rotation angle of the 3D frame around the \(z\)-axis. \(\Delta b\) denotes the difference between the predicted 3D bounding box and the true bounding box, i.e., the coordinate deviation of the predicted bounding box. \(\text{Smooth}_{\text{L1}}\) is the L1 smoothing function, which is mainly used to reduce the effect of the coordinate error of the prediction bounding box on the loss function to minimize the effect of extreme values. The subscript gt is the variable that is the true value of the object; the scalar in the following table is the predicted or anchor value of the object for \(p\); \(d_{p}=\sqrt{{w_{p}}^{2}+{l_{p}}^{2}}\).  
The classification loss function of the 3D bounding box uses the focal loss function [28], as shown in Equation (6).  
\[L_{cls}=-\alpha_{a}(1-P^{a})^{\gamma}\text{log}P^{a} \tag{6}\]  
where \(P^{a}\) is the probability value of a category, i.e., the anchor point; \(\alpha=0.25\); \(\gamma=2\).  
The localization loss cannot distinguish whether the 3D frame is flipped or not, so the \(L_{dir}\) uses the softmax function to learn the orientation of the 3D frame in the discrete direction.  
The loss function is optimized using the Adam optimizer, which updates the parameters using an exponentially weighted average of the gradient, along with a momentum mechanism that can effectively handle non-smooth objective functions and large-scale datasets. The initial learning rate is \(2\times 10^{-4}\) and the learning rate decay strategy is adopted to decay to 0.8 times of the current learning rate every 15 cycles.