![](https://csdnimg.cn/release/download_crawler_static/12329199/bg4.jpg)
Feng et al. [18] is able to improve the above loss func-
tions by proposing Wing loss that has constant gradient
when error is large, and large gradient when the error is
small. Thus pixels with small errors will be amplified. The
Wing loss is defined as follows:
W ing(y,ˆy)=
ωln(1+|
y−ˆy
|) if |(y − ˆy)|< ω
|y − ˆy| − C otherwise
(2)
where y and ˆy are the pixel values on ground truth heatmap
and the predicted heatmap respectively, C = ω − ω ln(1 +
ω/) is used to make function continuous at |y − ˆy| = ω.
The Wing loss is, however, still not be able to overcome the
discontinuity of its gradient at y − ˆy = 0, with its large
gradient magnitude around this point, training is even more
difficult to converge compared with L1 loss. This property
makes the Wing loss not applicable for heatmap regression,
since with the Wing loss calculated on all background pix-
els, small errors on background pixels are having out-of-
proportion influence. Training a neural network that outputs
zero or small gradient on these pixels is very difficult. Ac-
cording to our experiment, the training of a heatmap regres-
sion network with the Wing loss is never able to converge.
The above analysis leads us to define the desired prop-
erties of an ideal loss function for heatmap regression. We
expect our loss function to have a constant influence when
error is large, so that it will be robust to inaccurate anno-
tations and occlusions. As the training process continues
and errors getting smaller, there will be two scenarios: i)
For foreground pixels, the influence (as well as the gradi-
ent) should start to increase so that the training is able to
focus on reducing these errors. The influence should then
decrease rapidly as the errors go very close to zero, so that
these ”good enough” pixels will no longer be focused on.
The reduced influence of correct estimations helps the net-
work to stay converged, instead of oscillating like the L1
and the Wing loss. ii) For background pixels, the gradient
should behaves more similar to the MSE loss, that is, it will
gradually decrease to zero as the training error decreases,
so that the influence will be relatively small when the errors
are small. This property reduces the focus of the training on
background pixels, stabilizing the training process.
A fixed loss function cannot achieve both properties
simultaneously. Thus, the loss function should be able
to adapt to different pixel intensities on the ground truth
heatmaps. As the ground truth pixels close to the mode
(have intensities that are close to 1), the influence of small
errors should increase. With ground truth pixel intensities
close to 0, the loss function should behave more similar
to the MSE loss. Since pixel values on the ground truth
heatmap range from 0 to 1, we also expect our loss func-
tion to have a smooth transition according to different pixel
values.
4.2. The Adaptive Wing Loss
Following intuitions above, we propose our Adaptive
Wing (AWing) loss, defined as follows:
AW ing(y,ˆy) =
ωln(1+|
y−ˆy
|
α−y
) if |(y − ˆy)|< θ
A|y − ˆy| − C otherwise
(3)
where y and ˆy are the pixel values on the ground truth
heatmap and the predicted heatmap respectively, ω, θ, and
α are positive values, A = ω(1/(1 + (θ/)
(α−y)
))(α −
y)((θ/)
(α−y− 1)
)(1/) and C = (θA−ω ln(1+ (θ/)
α−y
))
are used to make loss function continuous and smooth at
|y − ˆy| = θ. Unlike Wing loss which uses ω as the thresh-
old, we introduce a new variable θ as a threshold to switch
between linear and nonlinear part. For heatmap regression,
we often regress a value between 0 and 1, so we expect our
threshold lies in this range. When |y − ˆy| < θ, we consider
the error to be small and need stronger influence. More im-
portantly, we adopt an exponential term α−y, which is used
to adapt the shape of the loss function to y and makes loss
function smooth at point zero. Note α has to be slightly
larger than 2 to maintain the ideal properties we discussed
in Sec. 4.1, this is due to the normalization of y in the range
of [0, 1]. For pixels on y with values close to 1 (the land-
marks we want to localize), the power term α − y will be
slightly larger than 1, and the nonlinear part will behave
like Wing loss, which has large influence on smaller errors.
But different from Wing loss, the influence will decrease to
zero rapidly as errors are very close to zero (see Fig. 4). As
y decreases, the loss function will shift to a MSE-like loss
function, which allows the training not to focus on the pix-
els that still have errors but small influence. Figure 5 shows
how the power term α − y facilities the smooth transition
across different values of y, so that the influence of small
errors will gradually increase as the value of y increases.
Larger ω and smaller values will increase the influence on
small errors and vice versa, large ω values are shown to be
effective according to our experiment.
The nonlinear part of our Adaptive Wing loss function
behaves similarly to Lorentzian (aka. Cauchy) loss [3] in
a more generalized fashion. But different from robust loss
functions such as Lorentzian and Geman-McClure [20], we
do not need the gradient to decrease to zero as error in-
creases. This is due to the nature of heatmap regression. In
robust regression, the learner learns to ignore noisy outliers
with large error. In the context of face alignment, all facial
landmarks are annotated with relatively small noises, so we
do not have noisy outliers to ignore. A linear loss is suffi-
cient for the training to converge to a location where predic-
tions will be fairly close to the ground truth heatmap, and
after that the loss function will switch to its nonlinear part
to refine the prediction with increased influence on small er-
rors. In practice, we found the linear form when errors are