C ONVOLUTIONAL CRF S FOR S EMANTIC S EGMENTATION
Anonymous authors
Paper under double-blind review
A
BSTRACT
For the challenging semantic image segmentation task the best performing models have traditionally combined the structured modelling capabilities of Conditional
Random Fields (CRFs) with the feature extraction power of CNNs.
In more recent works however, CRF post-processing has fallen out of favour.
We argue that this is mainly due to the slow training and inference speeds of CRFs, as well as the difﬁculty of learning the internal CRF parameters.
To overcome both issues we propose to add the assumption of conditional independence to the framework of fully-connected CRFs.
This allows us to reformulate the inference in terms of convolutions, which can be implemented highly efﬁciently on GPUs .Doing so speeds up inference and training by two orders of magnitude.
All parameters of the convolutional CRFs can easily be optimized using backpropagation.
Towards the goal of facilitating further CRF research we have made our implementations publicly available.
I NTRODUCTION
Semantic image segmentation, which aims to produce a categorical label for each pixel in an image, is a very import task for visual perception.
Convolutional Neural Networks have been proven to be very strong in tackling semantic segmentation tasks (Long et al., 2015; Chen et al., 2018; 2017; Zhao et al., 2017).
While deep neural networks are extremely powerful in extracting local features and performing good predictions utilizing a small ﬁeld of view, they lack the capability to utilize context information and cannot model interactions between predictions directly.
Thus it has been suggested that simple feed-forward CNNs may not be the perfect model for structured predictions tasks such as semantic segmentation (Zhao et al., 2017;
Lin et al., 2016; Zheng et al., 2015).
Several authors have successfully combined the effectiveness of CNNs to extract powerful features, with the modelling power of CRFs in order to address the discussed issues (Lin et al., 2016; Chandra & Kokkinos, 2016;
Zheng et al., 2015).
Despite their indisputable success, structured models have fallen out of favour in more recent approaches (Wu et al., 2016; Chen et al., 2017; Zhao et al., 2017).
We believe that the main reasons for this development are that CRFs are notoriously slow and hard to optimize.
Learning the features for the structured component of the CRF is an open research problem (Vemulapalli et al., 2016; Lin et al., 2016) and many approaches rely on entirely hand-crafted
Gaussian features (Krähenbühl & Koltun, 2011; Zheng et al., 2015; Schwing & Urtasun, 2015; Chen et al., 2018).
In addition, CRF inference is two orders of magnitude slower than CNN inference.
This makes CRF based approaches too slow for many practical applications.
The long training times of the current generation of CRFs also make more in-depth research and experiments with such structured models impractical.
To solve both of these issues we propose to add the strong and valid assumption of conditional independence to the existing framework of fully-connected CRFs (FullCRFs) introduced by Krähenbühl & Koltun (2011).
This allows us to reformulate a large proportion of the inference as convolutions, which can be implemented highly efﬁciently on GPUs.
We call our method convolutional CRFs (ConvCRFs).
Backpropagation (Rumelhart et al., 1986) can be used to train all parameters of the
ConvCRF.
Inference in ConvCRFs can be performed in less then 10 ms.
This is a speed increase of two-orders of magnitude compared to FullCRFs.
We believe that those fast train and inference speeds will greatly beneﬁt future research and hope that our results help to revive CRFs as a popular method to solve structured tasks.
R ELATED W ORK
Recent advances in semantic segmentation are mainly driven by powerful deep neural network architectures (Krizhevsky et al., 2012; Simonyan & Zisserman, 2015;
He et al., 2016; Wu et al., 2016).
Following the ideas introduced by Long et al.
, transposed convolution layers are applied at the end of the prediction pipeline to produce high-resolution output.
Atrous (dilated) convolutions (Chen et al., 2015a; Yu & Koltun, 2015) are commonly applied to preserve spatial information in feature space.
Many architectures have been proposed (Noh et al., 2015; Ronneberger et al., 2015; Badrinarayanan et al., 2017;
Paszke et al., 2016; Teichmann et al., 2016; Wu et al., 2016), based on the ideas above.
All of those approaches have in common that they primarily rely on the powerful feature extraction provided by CNNs.
Predictions are pixel-wise and conditionally independent (given the common feature base of nearby pixels).
Structured knowledge and background context is ignored in these models.
One popular way to integrate structured predictions into CNN pipelines is to apply a fully-connected
CRF (FullCRF) (Krähenbühl & Koltun, 2011) on top of the CNN prediction (Chen et al., 2015a;
Zheng et al., 2015; Schwing & Urtasun, 2015; Lin et al., 2016; Chandra & Kokkinos, 2016).
Utilizing the edge-awareness of CRFs, FullCRFs have been successfully utilized to solve weakly- and semisupervised segmentation tasks (Li et al., 2018; Triggs & Verbeek, 2008; He & Zemel, 2009; Tang et al., 2018).
Tang et al.
(2018) propose to use a CRF based loss function.
All of those approaches can beneﬁt from our contributions.
Parameter Learning in CRFs FullCRFs rely on hand-crafted features for the pairwise (Gaussian) kernels.
In their ﬁrst publication Krähenbühl & Koltun (2011) optimized the remaining parameters with a combination of expectation maximization and grid-search.
In a follow-up work Krähenbühl & Koltun (2013) proposed to use gradient descent.
The idea utilizes, that for the message passing the equation ( k G ∗ Q ) (cid:48) =
k G ∗ Q (cid:48) holds.
This allows them to train all internal CRF parameters, using backpropagation, without being required to compute gradients with respect to the Gaussian kernel k G .
However the features of the Gaussian kernel cannot be learned with such an approach.
CRFasRNN (Zheng et al., 2015) uses the same ideas to implement joint CRF and CNN training.
Like
Krähenbühl and Koltuns (2013) approach this requires hand-crafted pairwise (Gaussian) features.
Quadratic optimization (Chandra & Kokkinos, 2016; Vemulapalli et al., 2016) has been proposed to learn the Gaussian features of FullCRFs.
These approaches however do not ﬁt well into many deep learning pipelines.
Another way of learning the pairwise features is piecewise training (Lin et al., 2016).
An additional advantage of this method is that it avoids repeated CRF inference, speeding up the training considerably.
This approach is however of an approximate nature and inference speed is still very slow.
Inference speed of CRFs In order to circumvent the issue of very long training and inference times, some CRF based pipelines produce an output which is down-sampled by a factor of 8 × 8 (Chandra & Kokkinos, 2016; Lin et al., 2016).
This speeds up the inference considerably.
However this harms their predictive capabilities.
Deep learning based semantic segmentation pipelines perform best when they are challenged to produce a full-resolution prediction (Long et al., 2015; Yu & Koltun, 2015;
Chen et al., 2017).
To the best of our knowledge, no signiﬁcant progress in inference speed has been made since the introduction of FullCRFs (Krähenbühl & Koltun, 2011).
F ULLY C ONNECTED CRF S
In the context of semantic segmentation most recent CRF based approaches are based on the Fully
Connected CRF (FullCRF) model introduced by Krähenbühl & Koltun (2011).
Consider an input image I consisting of n pixels and a segmentation task with k classes.
A segmentation of I is then modelled as a random ﬁeld X
= { X 1 , . . .
, X n } , where each random variable X i takes values in { 1 , . . .
, k } , i.e. the label of pixel i .
Solving argmax X P ( X | I ) then leads to a segmentation X of the input image I .
P ( X | I ) is modelled as a CRF over the Gibbs distribution:
[Equation]
where the energy function E (ˆ x | I ) is given by
[Equation]
The function ψ u ( x i | I ) is called unary potential.
The unary itself can be considered a segmentation of the image and any segmentation pipeline can be used to predict the unary.
In practise most newer approaches (Chen et al., 2018; Schwing & Urtasun, 2015; Zheng et al., 2015) utilize CNNs to compute the unary.
The function ψ p ( x i , x j | I ) is the pairwise potential.
It accounts for the joint distribution of pixels i, j .
It allows us to explicitly model interactions between pixels, such as pixels with similar colour are likely the same class.
In FullCRFs ψ p is deﬁned as weighted sum of Gaussian kernels k (1) g . . . k [Equation]
m [Equation] g
[Equation]
where w ( m ) are learnable parameters.
The feature vectors f Ii can be chosen arbitrarily and may depend on the input Image I .
The function µ ( x i , x j ) is the compatibility transformation, which only depends on the labels x i and x j , but not on the image I .
A very widely used compatibility function (Krähenbühl & Koltun, 2011; Chen et al., 2018; Zheng et al., 2015) is the Potts model µ ( x i , x j )
= 1 [ xi (cid:54) = xj ] .
This model tries to assign pixels with similar features the same prediction.
Zheng et al.
(2015) propose to use 1 × 1 convolutions as compatibility transformation.
Such a function allows the model to learn more structured interactions between predictions.
FullCRFs utilize two Gaussian kernels with hand-crafted features.
The appearance kernel uses the raw colour values I j and I i as features.
The smoothness kernel is based on the spatial coordinates p i and p j .
The entire pairwise potential is then given as:
[Equation]
where w (1) , w (2) , as well as θ α , θ β and θ γ are the only learnable parameters of the model.
Most
CRF based segmentation approaches (Chen et al., 2018; Zheng et al., 2015; Schwing & Urtasun, 2015) utilize the very same handcrafted pairwise potentials proposed by Krähenbühl & Koltun (2011).
CRFs are notoriously hard to optimize and utilizing hand-crafted features circumvents this problem.
3. M EAN F IELD I NFERENCE
Inference in FullCRFs is achieved using the mean ﬁeld algorithm (see Algorithm 1).
All steps of algorithm 1, other then the message passing, are highly parallelized and can be implemented easily and efﬁciently on GPUs using standard deep learning libraries.
(For details see (Zheng et al., 2015)).
The message passing however is the bottleneck of the CRF computation.
Exact computation is quadratic in the number of pixels and therefore infeasible.
Krähenbühl & Koltun (2011) instead proposed to utilize the permutohedral lattice (Adams et al., 2010) approximation, a high-dimensional ﬁltering algorithm.
The permutohedral lattice however is based on a complex data structure.
While there is a very sophisticated and fast CPU implementation, the permutohedral lattice does not follow the SIMD (Nickolls et al., 2008) paradigm of efﬁcient GPU computation.
In addition, efﬁcient gradient computation of the permutohedral lattice approximation, is also a non-trivial problem.
This is the underlying reason why FullCRF based approaches use hand-crafted features.
1: Initialize: (cid:46)
˜ Q i ← 1 Z i exp ( − ψ u ( x i | I )) "softmax" 2: do 3:
Q
= k g (
Q
(cid:46)
Passing 4:
(cid:46) Compatibility Transformation 5: 7: end while
C ONVOLUTIONAL CRF S
The convolutional CRFs (ConvCRFs) supplement FullCRFs with a conditional independence assumption.
We assume that the label distribution of two pixels i, j are conditionally independent, if for the
Manhattan distance d holds d ( i, j ) > k .
We call the hyperparameter k ﬁlter-size.
This locality assumption is a very strong assumption.
It implies that the pairwise potential is zero, for all pixels whose distance exceed k .
This reduces the complexity of the pairwise potential greatly.
The assumption can also be considered valid, given that CNNs are based on local feature processing and are highly successful.
This makes the theoretical foundation of ConvCRFs very promising, strong and valid assumptions are the powerhouse of machine learning modelling.
4. E FFICIENT M ESSAGE P ASSING IN C ONV CRF S
One of the key contribution of this paper is to show that exact message passing is efﬁcient in
ConvCRFs.
This eliminates the need to use the permutohedral lattice approximation, making highly efﬁcient GPU computation and complete feature learning possible.
Towards this goal we reformulate the message passing step to be a convolution with truncated Gaussian kernel and observe that this can be implemented very similar to regular convolutions in CNNs.
Consider an input P with shape [ bs, c, h, w ] where bs, c, h, w denote batch size, number of classes, input height and width respectively.
For a Gaussian kernel g deﬁned by feature vectors f 1 . . .
f d , each of shape [ bs, h, w ] we deﬁne its kernel matrix by
[Equation]
where θ i is a learnable parameter.
For a set of Gaussian kernels g 1 . . .
g s we deﬁne the merged kernel matrix K as K := (cid:80) si =1 w i · g i .
The result Q of the combined message passing of all s kernels is now given as:
[Equation]
This message passing operation is similar to standard 2d-convolutions of CNNs.
In our case however, the ﬁlter values depend on the spatial dimensions x and y .
This is similar to locally connected layers (Chen et al., 2015b).
Unlike locally connected layers (and unlike 2d-convolutions), our ﬁlters are however constant in the channel dimension c .
One can view our operation as convolution over the dimension c 1 .
It is possible to implement our convolution operation by using standard CNN operations only.
This however requires the data to be reorganized in GPU memory several times, which is a very slow process.
Proﬁling shows that 90 % of GPU time is spend for the reorganization of data.
We therefore opted to build a native low-level implementation, to gain an additional 10 -fold speed up.
Efﬁcient computation of our convolution can be implemented analogously to 2d-convolution (and locally connected layers).
The ﬁrst step is to tile the input P in order to obtain data with shape [ bs, c, k, k, h, w ] .
This process is usually referred to as im2col and the same as in 2dconvolutions (Chetlur et al., 2014).
2d-convolutions proceed by applying a batched matrix multiplication over the spatial dimension.
We replace this step with a batched dot-product over the channel dimension.
All other steps are the same.
4. A DDITIONAL IMPLEMENTATION DETAILS
For the sake of comparability we use the same design choices as FullCRFs in our baseline ConvCRF implementation.
In particular, we use softmax normalization, the Potts model as well as the same handcrafted gaussian features as proposed by Krähenbühl & Koltun (2011).
Analogous to Krähenbühl &
Koltun (2011) we also apply gaussian blur to the pairwise kernels.
This leads to an increase of the effective ﬁlter size by a factor of 4 .
In additional experiments we investigate the capability of our CRFs to learn Gaussian features.
Towards this goal we replace the input features p i of the smoothness kernel with learnable variables.
Those variables are initialized to the same values as the hand-crafted version, but are adjusted as part of the training process.
We also implement a learnable compatibility transformation using 1 ×convolution, following the ideas of Zheng et al.
E XPERIMENTAL E VALUATION
Dataset: We evaluate our method on the challenging PASCAL VOC 2012 (Everingham et al.)
image dataset.
Following the literature (Long et al., 2015;
Wu et al., 2016; Chen et al., 2018; Zhao et al., 2017) we use the additional annotation provided by (Hariharan et al., 2011) resulting in 10labelled images for training.
Out of those images we hold back 200 images to ﬁne-tune the internal
CRF parameters and use the remaining 10 382 to train the unary CNN.
We report our results on the 1464 images of the ofﬁcial validation set.
Unary: We train a ResNet101 (He et al., 2016) to compute the unary potentials.
We use the
ResNet101 implementation provided by the PyTorch (Paszke et al., 2017) repository.
A simple
FCN (Long et al., 2015) is added on top of the ResNet to decode the CNN features and obtain valid segmentation predictions.
The network is initialized using ImageNet Classiﬁcation weights (Deng et al., 2009) and then trained on Pascal VOC data directly.
Unlike many other projects, we do not train the network on large segmentation datasets such as MS COCO (Lin et al., 2014), but only use the images provided by the PASCAL VOC 2012 benchmark.
The CNN is trained for 200 epochs using a batch size of 16 and the adam optimizer (Kingma & Ba, 2014).
The initial learning rate is set to 5 × 10 − 5 and polynomially decreased (Liu et al., 2015; Chen et al., 2018) by multiplying the initial learning rate with ((1 − step max _ steps ) 0 . 9 ) 2 .
An L 2 weight decay with factor 5 × 10 − 4 is applied to all kernel weights and 2d-Dropout (Tompson et al., 2015) with rate 0 .
5 is used on top of the ﬁnal convolutional layer.
The same hyperparamters are also used for the end-to-end training.
The following data augmentation methods are applied: Random horizontal ﬂip, random rotation ( ± 10 °) and random resize with a factor in (0.5, 2).
In addition the image colours are jittered using random brightness, random contrast, random saturation and random hue.
All random numbers are generated using a truncated normal distribution.
The trained model achieves validation mIoU of 71 .
23 % and a train mIoU of 91 .
CRF:
Following the literature (Krähenbühl & Koltun, 2011; Chen et al., 2018; Zheng et al., 2015;
Lin et al., 2016), the mean-ﬁeld inference of the CRF is computed for 5 iterations in all experiments.
5. C ONV CRF S ON SYNTHETIC DATA
To show the capabilities of Convolutional CRFs we ﬁrst evaluate their performance on a synthetic task.
We use the PASCAL VOC (Everingham et al.)
dataset as a basis, but augment the ground-truth towards the goal to simulate prediction errors.
The noised labels are used as unary potentials for the
[Figure]
[Table]
CRF, the CRF is then challenged to denoise the predictions.
The output of the CRF is then compared to the original label of the Pascal VOC dataset.
Towards the goal of creating a relevant task, the following augmentation procedure is used: First the ground-truth is down-sampled by a factor of 8.
Then, in low-resolution space random noise is added to the predictions and the result is up-sampled to the original resolution again.
This process simulates inaccuracies as a result of the low-resolution feature processing of CNNs as well as prediction errors similar to the checkerboard issue found in deconvolution based segmentation networks (Gao et al., 2017; Odena et al., 2016).
Some examples of the augmented ground-truth are shown in Figure 1.
In our ﬁrst experiment we compare FullCRFs and ConvCRFs using the exact same parameters.
To do this we utilize the hand-crafted Gaussian features.
The remaining ﬁve parameters (namely w (1) , w (2) , as well as θ α , θ β and θ γ ) are initialized to the default values proposed by Krähenbühl & Koltun (2011).
Note that this gives FullCRFs a natural advantage.
The performance of CRFs however is very robust with respect to these ﬁve parameters (Krähenbühl & Koltun, 2011).
The results of our ﬁrst experiment are given in Table 1.
It can be seen that ConvCRFs outperform
FullCRFs signiﬁcantly.
This shows that ConvCRFs are structurally superior to FullCRFs.
The better
[Figure]
Method
Unary
DeepLab
ConvCRF
Conv+T
Conv+C
Conv+CT mIoU [%] 71.
Accuracy [%] 91.
train mIoU [%] 68.
as compatibility transformation and +T learns the Gaussian features.
The same unaries were used for all approaches, only the CRF code from DeepLab was utilized.
performance of ConvCRFs with the same parameters can be explained by our exact message passing, which avoids the approximation errors compared of the permutohedral lattice approximation.
We provide a visual comparison in Figure 1 where ConvCRF clearly provide higher quality output.
The
FullCRF output shows approximation artefacts at the boundary of objects.
In addition we note that
ConvCRFs are faster by two orders of magnitude, making them favourable in almost every use case.
5. D ECOUPLED TRAINING OF C ONV CRF S
In this section we discuss our experiments on Pascal VOC data using a two stage training strategy.
First the unary CNN model is trained to perform semantic segmentation on the Pascal VOC data.
Those parameters are then ﬁxed and in the second stage the internal CRF parameters are optimized with respect to the CNN predictions.
The same unary predictions are used across all experiments, to reduce variants between runs.
Decoupled training has various merits compared to an end-to-end pipeline.
Firstly it is very ﬂexible.
A standalone CRF training can be applied on top of any segmentation approach.
The unary predictions are treated as a black-box input for the CRF training.
In practice this means that the two training stages do not need to interface at all, making fast prototyping very easy.
Additionally decoupled training keeps the system interpretable.
Lastly, piecewise training effectively tackles the vanishing gradient problem (Bengio et al., 1994), which is still an issue in CNN based segmentation approaches (Wu et al., 2016).
This leads to overall faster, more robust and reliable training.
For our experiments we train the CRF models on the 200 held-out images from the training set and evaluate the CRF performance on the 1464 images of the ofﬁcial Pascal VOC dataset.
We compare the performance of the ConvCRF with ﬁlter size 11 to the unary baseline results as well as a FullCRF trained following the methodology of DeepLab (Chen et al., 2018).
We report our results in Table 2, the training curves are visualized in Figure 2.
In all experiments, applying CRFs boost the performance considerably.
The experiments also conﬁrm the observation of
Section 5.1, that ConvCRF perform slightly better than FullCRFs.
We also observe that the ConvCRF [Table] implementation utilizing a learnable compatibility transformation as well as learnable Gaussian features performs best.
Model output is visualized in Figure 3.
5. E ND - TO -E ND LEARNING WITH C ONV CRF S
In this section we discuss our experiments using an end-to-end learning strategy for ConvCRFs.
In end-to-end training the gradients are propagated through the entire pipeline.
This allows the CNN and
CRF model to co-adapt and therefore to produce the optimum output w.r.t the entire network.
The down-side of end-to-end training is that the gradients need to be propagated through ﬁve iterations of the mean-ﬁeld inference, resulting in vanishing gradients (Zheng et al., 2015).
We train our network for 250 epochs using a training protocol similar to CRFasRNN (Zheng et al., 2015).
Zheng et al.
propose to ﬁrst train the unary potential until convergence and then optimizing the CRF and CNN jointly.
Like Zheng et al.
we greatly reduce the learning rate to 10 −during the second training stage. We use a batch size of 16 for the ﬁrst and 8 for the second training stage.
In this regard we differ from Zheng et al.
(2015), who proposes to reduce the batch size tofor the second training stage.
The entire training process takes about 30 hours using four 1080 Ti GPUs in parallel.
We believe that the fast training and inference speeds will greatly beneﬁt and ease future research using CRFs.
We compare our ConvCRF to the approach proposed in CRFasRNN (Zheng et al., 2015) and report the results in Table 3.
Overall we see that ConvCRF slightly outperforms CRFasRNN at a much higher speed.
C ONCLUSION
In this work we proposed Convolutional CRFs, a novel CRF design.
Adding the strong and valid assumption of conditional independence enables us to remove the permutohedral lattice approximation.
This allows us to implement the message passing highly efﬁciently on GPUs as convolution operations.
This increases training and inference speed by two orders of magnitude.
In addition we observe a modest accuracy improvement when computing the message passing exactly.
Our method also enables us to easily train the Gaussian features of the CRF using backpropagation.
In future work we will investigate the potential of learning Gaussian features further.
We are also going to examine more sophisticated CRF architectures, towards the goal of capturing context information even better.
Lastly we are particularly interested in exploring the potential of ConvCRFs in other structured applications such as instance segmentation, landmark recognition and weakly supervised learning.