2.3.2. CCE Loss Function

The characteristics of the foreground extraction task in this paper are summarized as follows:


To restrain the FP areas of the results from the foreground branch, a cross entropy loss function with connectivity-based weights was proposed to increase the penalization of FP domains according to their area and distance from center of the image.

The proposed loss function works when the model is "nearly converged", i.e., *N* < *threshold* connected domains exist in the output image. In this condition, a connectivity analysis algorithm is applied to split output foreground into *N* sorted domains according to their area, and the domain with the largest area is regarded as the main body of the vehicle.

$$\mathcal{D} = \{\mathcal{D}\_1, \mathcal{D}\_2, \dots, \mathcal{D}\_N\} \tag{1}$$

The weighted binary cross entropy loss function for 2-class segmentation task could be described as below:

$$L = -\frac{1}{N} \sum\_{i=1}^{N} (y\_i \log p\_i + w(1 - y\_i) \log(1 - p\_i))\tag{2}$$

In the equation above, *w* is the weight value. When *w* < 1, the function concentrates more on FNs; on the contrary, the function pays more attention on FPs when *w* > 1. Moreover, the function degenerates into normal cross entropy loss if *w* tends to 1. When one pixel belongs to the domain D*k*, *w* is calculated as follows:

$$w = 1 + \log\left(1 + \frac{d\_k}{\gamma}\sqrt{\frac{A\_k}{A\_1}}\right) \tag{3}$$

In the equation above, *dk* stands for the distance between the centroid of the minimum bounding rectangle of D*<sup>k</sup>* and the center of image, *Ak* is the area of D*k*, and *A*<sup>1</sup> is the domain that possesses the largest area, i.e., the main body of the EV. *γ* is a hyperparameter for controlling the value of the weight.
