{'fraction_non_alphanumeric': 0.0316622691292876, 'fraction_numerical': 0.008621650748820098, 'mean_word_length': 4.725531914893617, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Deeply Learning the Messages in Message Passing Inference

Deep structured output learning shows great promise in tasks like semantic image segmentation. We proffer a new, efficient deep structured model learning scheme, in which we show how deep Convolutional Neural Networks (CNNs) can be used to estimate the messages in message passing inference for structured prediction with Conditional Random Fields (CRFs). With such CNN message estimators, we obviate the need to learn or evaluate potential functions for message calculation. This confers significant efficiency for learning, since otherwise when performing structured learning for a CRF with CNN potentials it is necessary to undertake expensive inference for every stochastic gradient iteration. The network output dimension for message estimation is the same as the number of classes, in contrast to the network output for general CNN potential functions in CRFs, which is exponential in the order of the potentials. Hence CNN message learning has fewer network parameters and is more scalable for cases that a large number of classes are involved. We apply our method to semantic image segmentation on the PASCAL VOC 2012 dataset. We achieve an intersection-over-union score of 73.4 on its test set, which is the best reported result for methods using the VOC training images alone. This impressive performance demonstrates the effectiveness and usefulness of our CNN message learning method.


Introduction
Learning deep structured models has attracted considerable research attention recently. One popular approach to deep structured model is formulating conditional random fields (CRFs) using deep Convolutional Neural Networks (CNNs) for the potential functions. This combines the power of CNNs for feature representation learning and of the ability for CRFs to model complex relations. The typical approach for joint learning of CRFs and CNNs [1,2,3,4,5], is to learn the CNN potential functions by optimizing the CRF objective, e.g., maximizing the log-likelihood. The CNN and CRF joint learning has shown impressive performance for semantic image segmentation.
For the joint learning of CNNs and CRFs, stochastic gradient descent (SGD) is typically applied for optimizing the conditional likelihood. This approach requires the marginal inference for calculating the gradient. For loopy graphs, marginal inference is generally expensive even when using approximate solutions. Given that learning the CNN potential functions typically requires a large number of gradient iterations, repeated marginal inference would make the training intractably slow. Applying an approximate training objective is a solution to avoid repeat inference; pseudo-likelihood learning [6] and piecewise learning [7,3] are examples of this kind of approach. In this work, we advocate a new direction for efficient deep structured model learning.
In conventional CRF approaches, the final prediction is the result of inference based on the learned potentials. However, our ultimate goal is the final prediction (not the potentials themselves), so we propose to directly optimize the inference procedure for the final prediction. Our focus here is on the extensively studied massage passing based inference algorithms. As discussed in [8], we can directly learn message estimators to output the required messages in the inference procedure, rather than learning the potential functions as in conventional CRF learning approaches. With the learned message estimators, we then obtain the final prediction by performing message passing inference.
Our main contributions are as follows: • We explore a new direction for efficient deep structured learning. We propose to directly learn the messages in message passing inference as training deep CNNs in an end-to-end learning fashion.
Message learning does not require any inference step for the gradient calculation, which allows efficient training. It can be cast into traditional classification problems. The network output dimension for message estimation is the same as the number of classes (K), while the network output for general CNN potential functions in CRFs is K a , which is exponential in the order (a) of the potentials (for example, a = 2 for pairwise potenials, a = 3 for triple-cliques, etc). Hence CNN based message learning has significantly fewer network parameters and thus is more scalable, especially in the cases of a large number of classes involved.
• The number of iterations in message passing inference can be explicitly taken into consideration in the message learning procedure. In this paper, we are particularly interested in learning messages that are able to offer high-quality CRF prediction results with only one message passing iteration, making the message passing inference very fast.
• We apply our method to semantic image segmentation on the PASCAL VOC 2012 dataset. We achieve very impressive performance: an intersection-over-union score of 73.4 on the test set, which is the best reported result for methods using the VOC training images alone.

Related work
Combining the strengths of CNNs and CRFs for segmentation has been explored in several recent methods. Some methods resort to a simple combination of CNN classifiers and CRFs without joint learning. DeepLab-CRF in [9] first train fully CNN for pixel classification and applies a dense CRF [10] method as a post-processing step. Later the method in [2] extends DeepLab by jointly learning the dense CRFs and CNNs. RNN-CRF in [1] also performs joint learning of CNNs and the dense CRFs. They implement the mean-field inference as Recurrent Neural Networks which facilitates the end-to-end learning. These methods usually use CNNs for modelling the unary potentials only. The work in [3] trains CNNs to model both the unary and pairwise potentials in order to capture contextual information. Jointly learning CNNs and CRFs has also been explored for depth estimation [4,11], pose estimation [12] and so on. The work in [5] explores joint training of Markov random fields and deep networks for predicting words from noisy images and image classification.
All these above-mentioned methods that combine CNNs and CRFs are based upon conventional CRF approaches. They aim to joint learn or incorporate pre-trained CNN potential functions, and then perform inference/prediction using the potentials. In contrast, our method here directly learns CNN message estimators for the message passing inference, rather than learning the potentials.
The inference machine proposed in [8] is relevant to our work in that it has discussed the idea of directly learning message estimators instead of learning potential functions for structured prediction. They train traditional logistic regressors with hand-crafted features as message estimators. Motivated by the tremendous success of CNNs, we propose to train deep CNNs based message estimators in an end-to-end learning style without using hand-crafted features. Unlike the approach in [8] which aims to learn variable-to-factor message estimators, our proposed method aims to learn the factor-to-variable message estimators. Thus we are able to naturally formulate the variable marginals, which is the ultimate goal for CRF inference, as the training objective (see Sec. 3.3).

Learning CRF with CNN potentials
Before describing our message learning method, we review the CRF-CNN joint learning approach and discuss limitations. An input image is denoted by x ∈ X and the corresponding labeling mask is denoted by y ∈ Y.
The energy function is denoted by E(y, x), which measures the score of the prediction y given the input image x. We consider the following form of conditional likelihood: Here Z is the partition function. The CRF model is decomposed by a factor graph over a set of factors F. Generally, the energy function is written as a sum of potential functions (factor functions): Here F indexes one factor in the factor graph; y F denotes the variable nodes which are connected to the factor F ; E F is the (log-) potential function (factor function). The potential function can be a unary, pairwise, or high-order potential function. The recent method in [3] describes examples of constructing general CNN based unary and pairwise potentials.
Take sematic image segmentation as an example. To predict the pixel labels of a test image, we can find the mode of the joint label distribution by solving the maximum a posteriori (MAP) inference problem: y = argmax y P (y|x). We can also obtain the final prediction by calculating the label marginal distribution of each variable, which requires to solve a marginal inference problem: ∀p ∈ N : P (y p |x) = y\yp P (y|x).
Here y\y p indicates the output variables y excluding y p . For a general CRF graph with cycles, the above inference problems is known to be NP-hard, thus approximate inference algorithms are applied. Message passing is a type of widely applied algorithms for approximate inference: loopy belief propagation (BP) [13], tree-reweighted message passing [14] and mean-field approximation [13] are examples of the message passing methods.
CRF-CNN joint learning is to learn CNN potential functions by optimizing the CRF objective, typically, the negative conditional log-likelihood, which is: The energy function E(y, x) is constructed by CNNs, for which all the network parameters are denoted by θ.
Adding regularization, minimizing negative log-likelihood for CRF learning is: Here x (i) , y (i) denote the i-th training image and its segmentation mask; N is the number of training images; λ is the weight decay parameter. We can apply stochastic gradient descent (SGD) to optimize the above problem for learning θ. The energy function E(y, x; θ) is constructed from CNNs, and its gradient ∇ θ E(y, x; θ) can be easily computed by applying the chain rule as in conventional CNNs. However, the partition function Z brings difficulties for optimization. Its gradient is: Direct calculation of the above gradients is computationally infeasible for general CRF graphs. Usually it is necessary to perform approximate marginal inference to calculate the gradients at each SGD iteration [13]. However, repeated marginal inference can be extremely expensive, as discussed in [3]. CNN training usually requires a huge number of SGD iterations (hundreds of thousands, or even millions), hence this inference based learning approach is in general not scalable or even infeasible.

Learning CNN message estimators
In conventional CRF approaches, the potential functions are first learned, and then inference is performed based on the learned potential functions in order to generate the final prediction. In contrast, our approach directly optimizes the inference procedure for final prediction. We propose to learn CNN estimators to directly output the required intermediate values in an inference algorithm.
Here we focus on the massage passing based inference algorithm, which has been extensively studied and widely applied. In the CRF prediction procedure, the "message" vectors are recursively calculated based on the learned potentials. We propose to construct and learn CNNs to directly estimate these messages in the message passing procedure, rather than learning the potential functions. In particular, we directly learn factor-to-variable message estimators. Our message learning framework is general and can accommodate all message passing based algorithms such as loopy belief propagation (BP) [13], mean-field approximation [13] and their variants. Here we discuss using loopy BP for calculating variable marginals.
Typically, the message is a K-dimensional vector (K is the number of classes) which encodes the information of the label distribution. For each variable-factor connection, we need to recursively compute the variableto-factor message: β p→F ∈ R K , and the factor-to-variable message: β F →p ∈ R K . For numerical reasons, the log operation is applied to the marginals before deriving message passing algorithms. The unnormalized variable-to-factor message is computed as: Here F p is a set of factors connected to the variable p; F p \F is the set of factors F p excluding the factor F . For loopy graph, the variable-to-factor message is normalized in each iteration: The factor-to-variable message is computed as: Here N F is a set of variables connected to the factor F ; N F \p is the set of variables N F excluding the variable p. Once we get all the factor-to-variable messages of one variable node, we are able to calculate the marginal distribution (beliefs) of that variable: in which Z p is a normalizer:

CNN message estimators
The calculation of factor-to-variable message β F →p depends on the variable-to-factor messages β p→F . Substituting the definition of β p→F in (8), β F →p can be re-written as: Here q denotes the variable node which is connected to the node p by the factor F in the factor graph. We refer to the variable node q as a neighboring node of q. N F \p is a set of variables connected to the factor F excluding the node p. Clearly, for a pairwise factor which only connects to two variables, the set N F \p only contains one variable node. The above equations show that the factor-to-variable message β F →p depends on the potential E F and β F →q . Here β F →q is the factor-to-variable message which is calculated from a neighboring node q and a factor F = F .
Conventional CRF learning approaches learn the potential function then follow the above equations to compute the messages for calculating marginals. As discussed in [8], given that the goal is to estimate the marginals, it is not necessary to exactly follow the above equations, which involve learning potential functions, to calculate messages. We can directly learn message estimators, rather than indirectly learning the potential functions as in conventional methods.
Consider the calculation in (11). The message β F →p depends on the observation x pF and the messages β F →q . Here x pF denotes the observations that correspond to the node p and the factor F . We are able to formulate a factor-to-variable message estimator which takes x pF and β F →q as inputs and outputs the message vector, and we directly learn such estimators. Since one message β F →p depends on a number of previous messages β F →q , we can formulate a sequence of message estimators to model the dependence. Thus the output from a previous message estimator will be the input of the following message estimator.
There are two message passing strategies for loopy BP: synchronous and asynchronous passing. We here focus on the synchronous message passing, for which all messages are computed before passing them to the neighbors. The synchronous passing strategy results in much simpler message dependences than the asynchronous strategy, which simplifies the training procedure. We define one inference iteration as one pass of the graph with the synchronous passing strategy.
We propose to learn CNN based factor-to-variable message estimator. The message estimator models the interaction between neighboring variable nodes. We denote by M a message estimator. The factor-to-variable message is calculated as: We refer to d pF as the dependent message feature vector which encodes all dependent messages from the neighboring nodes that are connected to the node p by F . Note that the dependent messages are the output of message estimators at the previous inference iteration.
We focus on the case that we run only one message passing iteration, for which the inference becomes very fast. In this case, there is no dependent messages for M F , hence we do not need to incorporate d pF . However, in order to have a general exposition, we here describe our learning framework for the general case of running arbitrarily many inference iterations.
We can choose any effective strategy to generate the feature vector d pF from the dependent messages. According to (11), we can simply define the feature vector d pF as a K-dimensional vector which aggregates all dependent messages. Thus d pF is computed as: With the definition of d pF in (13) and β F →p in (12), it clearly shows that the message estimation requires evaluating a sequence of message estimators.
There are different strategies to formulate the message estimators in different iterations. The simple strategy is using the same message estimator across all inference iteration. In this case the message estimator becomes a recursive function, and thus the CNN based estimator becomes a recurrent neural network (RNN). Another strategy is to formulate different estimator for each inference iteration.

Details for message estimator networks
We formulate the estimator M F as a CNN, thus the estimation is the network outputs: Here θ F denotes the network parameter which we need to learn. δ(·) is the indicator function, which equals 1 if the input is true and 0 otherwise. We denote by z pF ∈ R K as the K-dimensional output vector (K is the number of classes) of the message estimator network for the node p and the factor F ; z pF,k is the k-th value in the network output z pF corresponding to the k-th class.
We can consider any possible strategies for implementing z pF with CNNs. For example, we here describe a strategy which is analogous to the network design in [3]. We denote by C (1) as a fully convolutional network (FCNN) [15] for convlutional feature generation, and C (2) as a traditional fully connected network for message estimation.
Given an input image x, the network output C (1) (x) ∈ R N1×N2×r is a convolutional feature map, in which N 1 × N 2 = N is the feature map size and r is the dimension of one feature vector. Each spatial position (each feature vector) in the feature map C (1) (x) correspond to one variable node in the CRF graph. We denote by C (1) (x, p) ∈ R r as the feature vector corresponding to the variable node p. Likewise, C (1) (x, N F \p) ∈ R r is the averaged vector of the feature vectors that correspond to the set of nodes N F \p. Recall that N F \p is a set of nodes connected by the factor F excluding the node p. For pairwise factors, N F \p contains only one node.
We construct the feature vector z C (1) pF ∈ R 2r for the node-factor pair (p, F ) by concatenating C (1) (x, p) and C (1) (x, N F \p). Finally, we concatenate the node-factor feature vector z C (1) pF and the dependent message feature vector d pF as the input for the second network C (2) . Thus the input dimension for C (2) is (2r + K). For running only one inference iteration, the input for C (2) is z C (1) pF alone. The final output from the second network C (2) is the K-dimensional message vector z pF . To sum up, we generate the final message vector z pF as: We can apply a similar network configuration as in [3]. The network C (1) has 6 convolution blocks and C (2) has 2 fully connected layers (with K output units). Please refer to [3] for details.
For a general CNN based potential function in conventional CRFs, the potential network is usually required to have a large number of output units (exponential in the order of the potentials). For example, it requires K 2 (K is the number of classes) outputs for the pairwise potentials [3]. For 100 classes, the network output will have 10000 dimensions. A large number of output units would significantly increase the number of network parameters. It leads to expensive computations and tend to over-fit the training data. In contrast, for learning our CNN message estimator, we only need to formulate K output units for the network. Clearly it is more scalable in the cases of a large number of classes.

Training CNN message estimators
Our goal is to estimate the variable marginals in (3), which can be re-written with the estimators: Here Z p is the normalizer. The ideal variable marginal has the probability of 1 for the ground truth class and 0 for the reminding classes. Here we consider the cross entropy loss between the ideal marginal and the estimated marginal, which is also known as the log soft-max loss for classification: in whichŷ p is the ground truth label for the variable node p. Given a set of N training images and label masks, the optimization problem for learning the message estimator network is: The work in [8] propose to learn the variable-to-factor message (β p→F ). Unlike their approach, we aim to learn the factor-to-variable message (β F →p ), for which we are able to naturally formulate the variable  1 38.6 77.8 61.3 74.3 89.0 83.4 83.3 36.2 80.2 56.4 81.2 81.4 83.1 82.9 59.2 83.4 54.3 80.6 70.8 marginals, which is the ultimate goal for prediction, as the training objective. Moreover, for learning β p→F in their approach, the message estimator will depend on all neighboring nodes (connected by any factors). Given that variable nodes will have different number of neighboring nodes, they only consider a fixed number of neighboring nodes (e.g., 20) and concatenate their features to generate a fixed-length feature vector for classification. In our case for learning β F →p , the message estimator only depends a fixed number of neighboring nodes (connected by one factor), thus we do not have this problem. Most importantly, they learn message estimators by training traditional probabilistic classifiers (e.g., simple logistic regressors) with hand-craft features, and in contrast, we train deep CNNs in an end-to-end learning style without using hand-craft features.

Message learning with inference-time budgets
One advantage of message learning is that we are able to explicitly incorporate the expected number of inference iteration into the learning procedure. The number of inference iteration defines the learning sequence of message estimators. This is particular useful if we aim to learn the estimators which are able to have highquality prediction for only running a few number of inference iterations. In contrast, the conventional potential function learning in CRFs are not able to directly incorporate the expected number of inference iterations.
We are particularly interested in learning message estimators for using only one message passing iteration, for which the inference can be very fast. In this case it might be preferable to have large-range neighborhood connections, for which the large range interaction can be captured by running one inference pass. In the experiment part, our impressive performance for semantic segmentation verifies the effectiveness of using a single inference pass.

Experiments
We evaluate the proposed CNN message learning method for semantic image segmentation. We use the publicly available PASCAL VOC 2012 dataset [16]. There are 20 object categories and one background category in the dataset. Its contains 1464 images in the training set, 1449 images in the "val" set and 1456 images in the test set. Following the common setting in [17,9], the training set is augmented to 10582 images by including the extra annotations provided in [18] for the VOC images. We use intersection-over-union (IoU) score [16] to evaluate the segmentation performance. For the learning and prediction of our method, we only use one message passing iteration.
The recent work in [3] (referred to as ContextDCRF) learns multi-scale fully convolutional CNNs (FCNNs) for unary and pairwise potential functions to capture contextual information. We follow this CRF learning method and replace the potential functions by the proposed message estimators. We consider 2 types of spatial relations for constructing the pairwise connections of variable nodes. One is the "surrounding" spatial relation, for which one node is connected to its surround nodes. The other one is the "above/below" spatial relation, for which one node is connected to the nodes that lie above. For the pairwise connections, the neighborhood size is defined by a range box. We learn one type of unary message estimator and 3 types of pairwise message estimators in total. One type of pairwise message estimator is for the "surrounding" spatial relations, and the other two are for the "above/below" spatial relations. We formulate one network for one type of message estimator.
We formulate our message estimators as multi-scale FCNNs and apply similar network settings as in ContextD-CRF. The output dimension of the estimator network is the number of classes. Our networks are initialized using the VGG-16 model [19]. We train all layers using back-propagation.
We first evaluate our method on the VOC 2012 "val" set. We compare with several recent CNN based methods with available results on the "val" set. Results are shown in Table 2. Our method achieves the best performance. As mentioned, ContextDCRF learns CNN based potential functions in CRFs to capture contextual information. ContextDCRF follows a conventional CRF learning and prediction scheme: They first learn  We further evaluate our method on the VOC 2012 test set. We compare with recent state-of-the-art CNN methods with competitive performance. The results are described in Table 3. Since the ground truth labels are not available for the test set, We evaluate our method through the VOC evaluation server. We achieve excellent performance on the test set: 73.4 IoU score 1 . We has the best performance compared to the methods that use the same augmented VOC dataset [18] (marked as "VOC extra" in the table), which validate the effectiveness of direct message learning with CNNs.
We also include the comparison with the methods which are trained on the much larger COCO dataset (133K training images). Our performance is comparable with these methods, while our method uses much less number of training images.
The results for each category is shown in Table 1. We compare with several recent methods which transfer layers from the same VGG-16 model and use the same training data. Our method perform the best for most categories.

Conclusions
We have proposed a new deep message learning framework for structured CRF prediction. Learning deep message estimators for the message passing inference reveals a new direction for learning deep structured model. Learning CNN message estimators is efficient, which does not involve expensive inference steps for gradient calculation. The network output dimension for message estimation is the same as the number of classes, which does not increase with the order of the potentials, and thus CNN message learning has less network parameters and is more scalable in the number of classes compared to conventional potential function learning. Our excellent performance for semantic segmentation demonstrates the effectiveness and usefulness of the proposed deep message learning. Our framework is general and can be readily applied to other structured prediction applications.

Appendix: Image segmentation examples
We show some semantic image segmentation results using the proposed method.