Paper Notes: Multi-Task Learning Using Uncertainty to Weigh Losses for Scene Geometry and Semantics
A typical approach to Multi-Task Learning (MTL) is to optimize all the losses jointly, but this often requires assigning them different weights. Traditional methods typically rely on manual analysis of factors such as the scale of each loss, along with experimentation, to set suitable weights. Getting good results, however, often takes a great deal of work. This paper proposes using uncertainty to learn the weights automatically.
The figure below shows a typical Multi-Task Learning setup in which the model learns semantic segmentation, instance segmentation, and depth estimation simultaneously. This setup includes classification, feature learning, and regression tasks, making it a representative example for the paper:

The paper makes three main contributions:
1) A new principle for Multi-Task Learning based on homoscedastic uncertainty
2) A unified framework for learning semantic segmentation, instance segmentation, and depth regression
3) A demonstration that learning the weights is effective
1 Multi Task Learning with Homoscedastic Uncertainty
A straightforward approach to Multi-Task Learning is to optimize all the losses jointly, which typically requires tuning their weights by hand. A typical loss function is:
L_{\text {total}}=\sum_{i} w_{i} L_{i}\tag{1}The problem with this approach is that the model’s final performance is highly sensitive to the weights. Without well-chosen weights, it is difficult to get a model that performs well on several tasks at once. Tuning these weights by hand also takes considerable time and effort. The figure below shows how much the weights can affect the outcome of optimization:

To address this, the paper proposes a method that automatically selects the weights for the different losses in Multi-Task Learning and adjusts them during training. This can improve the accuracy of the individual tasks.
1.1 Homoscedastic uncertainty as task-dependent uncertainty
The authors build their mathematical model using a Bayesian approach. They first distinguish between two types of uncertainty in Bayesian modeling:
-
Epistemic uncertainty: uncertainty caused by a lack of training data
-
Aleatoric uncertainty: uncertainty arising from information that the training data cannot explain
Aleatoric uncertainty can be further divided into two types:
-
Data-dependent (heteroscedastic) uncertainty
-
Task-dependent (homoscedastic) uncertainty
In Multi-Task Learning, task uncertainty captures the relative confidence across tasks and reflects the uncertainty inherent in each regression or classification task.
1.2 Multi-task likelihoods
Using maximum likelihood estimation, assume that \mathbf{f}^{\mathbf{W}} is the network output and thatW is the weight for that output. Then, for a regression task, we have:
p\left(\mathbf{y} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right)=\mathcal{N}\left(\mathbf{f}^{\mathbf{W}}(\mathbf{x}), \sigma^{2}\right)\tag{2}For a classification task, we have:
p\left(\mathbf{y} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right)=\operatorname{Softmax}\left(\mathbf{f}^{\mathbf{W}}(\mathbf{x})\right)\tag{3}Joint probability for multiple tasks:
p\left(\mathbf{y}_{1}, \ldots, \mathbf{y}_{K} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right)=p\left(\mathbf{y}_{1} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right) \ldots p\left(\mathbf{y}_{K} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right)\tag{4}For a regression task, for example, maximum likelihood estimation can be expressed as minimizing the negative log-likelihood:
\log p\left(\mathbf{y} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right) \propto-\frac{1}{2 \sigma^{2}}\left\|\mathbf{y}-\mathbf{f}^{\mathbf{W}}(\mathbf{x})\right\|^{2}-\log \sigma\tag{5}
where \sigma denotes the variance of the measurement noise.
A two-task example
Suppose we have two tasks.
Their joint probability is:
\begin{aligned} p\left(\mathbf{y}_{1}, \mathbf{y}_{2} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right) &=p\left(\mathbf{y}_{1} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right) \cdot p\left(\mathbf{y}_{2} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right) \\ &=\mathcal{N}\left(\mathbf{y}_{1} ; \mathbf{f}^{\mathbf{W}}(\mathbf{x}), \sigma_{1}^{2}\right) \cdot \mathcal{N}\left(\mathbf{y}_{2} ; \mathbf{f}^{\mathbf{W}}(\mathbf{x}), \sigma_{2}^{2}\right) \end{aligned}\tag{6}To optimize our loss function \mathcal{L}\left(\mathbf{W}, \sigma_{1}, \sigma_{2}\right), we minimize the negative log-likelihood:
\begin{array}{l}=-\log p\left(\mathbf{y}_{1}, \mathbf{y}_{2} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right) \\\propto \frac{1}{2 \sigma_{1}^{2}}\left\|\mathbf{y}_{1}-\mathbf{f}^{\mathbf{W}}(\mathbf{x})\right\|^{2}+\frac{1}{2 \sigma_{2}^{2}}\left\|\mathbf{y}_{2}-\mathbf{f}^{\mathbf{W}}(\mathbf{x})\right\|^{2}+\log \sigma_{1} \sigma_{2} \\=\frac{1}{2 \sigma_{1}^{2}} \mathcal{L}_{1}(\mathbf{W})+\frac{1}{2 \sigma_{2}^{2}} \mathcal{L}_{2}(\mathbf{W})+\log \sigma_{1} \sigma_{2}\end{array}\tag{7}Here, we define \mathcal{L}_{1}(\mathbf{W})=\left\|\mathbf{y}_{1}-\mathbf{f}^{\mathbf{W}}(\mathbf{x})\right\|^{2} and \mathcal{L}_{2}(\mathbf{W})=\left\|\mathbf{y}_{2}-\mathbf{f}^{\mathbf{W}}(\mathbf{x})\right\|^{2} as the loss functions for the two tasks, respectively.
As the noise \sigma_1 associated with y_1 increases, the weight on \mathcal{L}_{1}(\mathbf{W}) decreases, and vice versa. The final term, \log \sigma_{1} \sigma_{2}, acts as a regularizer, preventing either \sigma from growing too large and severely unbalancing training.
This formulation extends readily to multiple regression tasks, but we are more interested in how it applies to classification. For classification, we rescale the network output before applying Softmax:
p\left(\mathbf{y} \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x}), \sigma\right)=\operatorname{Softmax}\left(\frac{1}{\sigma^{2}} \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right)\tag{8}This expression can be interpreted as a Boltzmann distribution, where \sigma^2 can be interpreted as kT, the product of the Boltzmann constant k and the thermodynamic temperature T. This quantity can be fixed or learned.
Using the Boltzmann distribution, we obtain the following log-likelihood for the classification task:
\begin{aligned}\log p\left(\mathbf{y}=c \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x}), \sigma\right) &=\frac{1}{\sigma^{2}} f_{c}^{\mathbf{W}}(\mathbf{x}) \\&-\log \sum_{c^{\prime}} \exp \left(\frac{1}{\sigma^{2}} f_{c^{\prime}}^{\mathbf{W}}(\mathbf{x})\right)\end{aligned}\tag{9}Here, \mathbf{f}_{c}^{\mathbf{W}}(\mathbf{x}) is the output for class c in \mathbf{f}^{\mathbf{W}}(\mathbf{x}).
Now suppose y1 is a continuous prediction for a regression task and y2 is a discrete prediction for a classification task. We define their loss functions as follows:
1) Regression: L2 distance \mathcal{L}_{1}(\mathbf{W})=\left\|\mathbf{y}_{1}-\mathbf{f}^{\mathbf{W}}(\mathbf{x})\right\|^{2}
2) Classification: Cross Entropy: \mathcal{L}_{2}(\mathbf{W})=-\log \operatorname{Softmax}\left(\mathbf{y}_{2}, \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right)
We then derive the negative log-likelihood of their joint distribution:
\begin{array}{l}=-\log p\left(\mathbf{y}_{1}, \mathbf{y}_{2}=c \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x})\right) \\=-\log \mathcal{N}\left(\mathbf{y}_{1} ; \mathbf{f}^{\mathbf{W}}(\mathbf{x}), \sigma_{1}^{2}\right) \cdot \operatorname{Softmax}\left(\mathbf{y}_{2}=c ; \mathbf{f}^{\mathbf{W}}(\mathbf{x}), \sigma_{2}\right) \\=\frac{1}{2 \sigma_{1}^{2}}\left\|\mathbf{y}_{1}-\mathbf{f}^{\mathbf{W}}(\mathbf{x})\right\|^{2}+\log \sigma_{1}-\log p\left(\mathbf{y}_{2}=c \mid \mathbf{f}^{\mathbf{W}}(\mathbf{x}), \sigma_{2}\right) \\=\frac{1}{2 \sigma_{1}^{2}} \mathcal{L}_{1}(\mathbf{W})+\frac{1}{\sigma_{2}^{2}} \mathcal{L}_{2}(\mathbf{W})+\log \sigma_{1}+\log \frac{\sum_{c^{\prime}} \exp \left(\frac{1}{\sigma_{2}^{2}} f_{c^{\prime}}^{\mathrm{W}}(\mathrm{x})\right)}{\left(\sum_{c^{\prime}} \exp \left(f_{c^{\prime}}^{\mathrm{W}}(\mathrm{x})\right)\right)^{\frac{1}{\sigma_{2}^{2}}}} \\\approx \frac{1}{2 \sigma_{1}^{2}} \mathcal{L}_{1}(\mathbf{W})+\frac{1}{\sigma_{2}^{2}} \mathcal{L}_{2}(\mathbf{W})+\log \sigma_{1}+\log \sigma_{2}\end{array}\tag{10}The last step uses the following approximation:
\frac{1}{\sigma_{2}} \sum_{c^{\prime}} \exp \left(\frac{1}{\sigma_{2}^{2}} f_{c^{\prime}}^{\mathbf{W}}(\mathbf{x})\right) \approx \left(\sum_{c^{\prime}} \exp \left(f_{c^{\prime}}^{\mathbf{W}}(\mathbf{x})\right)\right)^{\frac{1}{\sigma_{2}^{2}}}\tag{11}The two sides approach equality as \sigma_{2} \to 1.
The final expression above is the joint loss for the Multi-Task Learning problem. The parameters we need to optimize include not only W but also \sigma_{1} and \sigma_{2}.
2 Experimental Validation
The authors tried tackling instance segmentation, semantic segmentation, and depth prediction together in a multi-task learning setup. The experimental results are shown below:

The results show that automatically learning the task weights from uncertainty substantially outperformed manual tuning. With the same model architecture, jointly training on three tasks also performed better than training on two tasks or even on a single task. This result challenges the conventional wisdom that multi-task learning must involve some trade-off compared with single-task learning.
Personal Takeaways
The modeling approach is straightforward: it starts from homoscedasticity and uses the predicted variance to determine the task weights. This makes it suitable for most multi-task learning problems involving regression or classification.
References
https://zhuanlan.zhihu.com/p/34358595
https://blog.csdn.net/cv_family_z/article/details/78749992
Download the Paper
Source Code Links
https://github.com/Hui-Li/multi-task-learning-example-PyTorch (PyTorch)