# MS3D: A Multi-Scale Feature Fusion 3D Object Detection Method for Autonomous Driving Applications
## 3 Proposed Method
### Loss Function  
The loss function comprised three components: localization loss \(\mathrm{L_{loc}}\), orientation classification loss \(\mathrm{L_{dir}}\), and classification loss \(\mathrm{L_{cls}}\). Each 3D bounding box was represented by a seven-dimensional vector \((\mathrm{x},\mathrm{y},\mathrm{z},\mathrm{w},\mathrm{l},\mathrm{h},\mathrm{ \theta})\), where \((\mathrm{x},\mathrm{y},\mathrm{z})\) are the center coordinates, \((\mathrm{w},\mathrm{l},\mathrm{h})\) are the dimensions, and \(\mathrm{\theta}\) is the orientation angle.  
Localization Loss \(\mathrm{L_{loc}}\): The localization loss used the Smooth L1 loss function [37], combining L1 and L2 loss characteristics to measure the discrepancy between predicted and ground truth bounding boxes. It balanced smoothness for small errors with robustness for larger deviations.  
\[\mathrm{L_{loc}}=\sum_{\mathrm{b}\in(\mathrm{x},\mathrm{y},\mathrm{z}, \mathrm{w},\mathrm{l},\mathrm{h},\mathrm{\theta})}\mathrm{SmoothL1}(\mathrm{ \Delta b}) \tag{6}\]  
where \(\mathrm{\Delta b}\) represents the residual between predicted \(\mathrm{\hat{b}}\) and ground truth \(\mathrm{b}\).  
The Smooth L1 loss function [37], as depicted in Figure 3, is defined as  
\[\mathrm{SmoothL1}(\mathrm{\Delta b})=\begin{cases}0.5(\mathrm{\Delta b})^{2}& \mathrm{if}|\mathrm{\Delta b}|<1\\ |\mathrm{\Delta b}|-0.5&\mathrm{otherwise}\end{cases} \tag{7}\]  
Orientation Classification Loss \(\mathrm{L_{dir}}\): The orientation classification loss employed the Softmax function to optimize the model's orientation predictions and minimize classification errors as follows:  
\[\mathrm{L_{dir}}=-\sum_{\mathrm{i=1}}^{\mathrm{N}}\sum_{\mathrm{c=1}}^{ \mathrm{C}}\mathrm{y_{i,c}}\mathrm{log}(\mathrm{P_{i,c}}) \tag{8}\]  
where N is the number of instances in a batch, C is the number of orientation classes, \(\mathrm{y_{i,c}}\) is an indicator variable (1 if the true orientation of object \(\mathrm{i}\) is c, otherwise 0), and \(\mathrm{P_{i,c}}\) is the predicted probability for orientation class c.  
Figure 3: A graph of the Smooth L1 loss function.  
Classification Loss Lcls: The classification loss, using Focal Loss [37], addressed class imbalance by focusing on hard-to-classify examples while down-weighting easy ones as follows:  
\[\text{L}_{\text{cls}}=-\sum_{\text{a}}\alpha_{\text{a}}(1-\text{p}^{\text{a}})^ {\gamma}\text{log}\,\text{p}^{\text{a}} \tag{9}\]  
where p\({}^{\text{a}}\) is the predicted probability for class a, \(\alpha_{\text{a}}\) is a balancing factor, and \(\gamma\) is a modulation term used to reduce the emphasis on well-classified examples.  
The total loss L was a weighted sum of these components:  
\[\text{L}=\frac{1}{\text{N}_{\text{pos}}}(\beta_{\text{loc}}\text{L}_{\text{ loc}}+\beta_{\text{cls}}\text{L}_{\text{cls}}+\beta_{\text{dir}}\text{L}_{\text{dir}}) \tag{10}\]  
where Npos is the number of positive anchors. The optimal balancing factors were determined through cross-validation and a comparative analysis of performance metrics across various parameter settings. For example, the alpha_a parameter was optimally set at 0.25 following a stringent experimental protocol. Initially, the dataset underwent categorical distribution scrutiny to detect under-represented classes. Subsequently, a five-fold cross-validation scheme was implemented, adjusting alpha_a incrementally from 0.1 to 0.5 in steps of 0.05. Analysis of F1 scores and precision-recall curves across different alpha_a settings confirmed that the model reached its optimal classification equilibrium at alpha_a = 0.25, characterized by a significant boost in recall for minority classes without compromising precision. Moreover, the incorporation of an early stopping criterion averted overfitting, ensuring the model's robust generalization capabilities. In practice, the balancing factors were set to \(\alpha_{\text{a}}\) = 0.25, \(\gamma\) = 2, \(\beta_{\text{loc}}\) = 2, \(\beta_{\text{cls}}\) = 1, and \(\beta_{\text{dir}}\) = 0.1 to optimize model performance.