{'fraction_non_alphanumeric': 0.025724195516731968, 'fraction_numerical': 0.008093005331106686, 'mean_word_length': 5.07590243902439, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
FCNs in the Wild: Pixel-level Adversarial and Constraint-based Adaptation

Fully convolutional models for dense prediction have proven successful for a wide range of visual tasks. Such models perform well in a supervised setting, but performance can be surprisingly poor under domain shifts that appear mild to a human observer. For example, training on one city and testing on another in a different geographic region and/or weather condition may result in significantly degraded performance due to pixel-level distribution shift. In this paper, we introduce the first domain adaptive semantic segmentation method, proposing an unsupervised adversarial approach to pixel prediction problems. Our method consists of both global and category specific adaptation techniques. Global domain alignment is performed using a novel semantic segmentation network with fully convolutional domain adversarial learning. This initially adapted space then enables category specific adaptation through a generalization of constrained weak learning, with explicit transfer of the spatial layout from the source to the target domains. Our approach outperforms baselines across different settings on multiple large-scale datasets, including adapting across various real city environments, different synthetic sub-domains, from simulated to real environments, and on a novel large-scale dash-cam dataset.


Introduction
Semantic segmentation is a critical visual recognition task for a variety of applications ranging from autonomous agent tasks, such as robotic navigation and self-driving cars, to mapping and categorizing the natural world. As such, a significant amount of recent work has been introduced to tackle the supervised semantic segmentation problem using pixel-wise annotated images to train convolutional networks [20,1,23,34,19,4,33].
While performance is improving for segmentation models trained and evaluated on the same data source, there has yet been limited research exploring the applicability of these models to new related domains. Many of the chal- lenges faced when considering adapting between visual domains for classification, such as changes in appearance, lighting, and pose, are also present when considering adapting for semantic segmentation. In addition, some new factors take on more prominence when considering recognition with localization tasks. In both classification and segmentation, the prevalence of classes may vary between different domains, but this variance can be more exaggerated with semantic segmentation applications as an individual object class may now appear many times within a single scene. For instance, semantic segmentation for self-driving applications will focus on outdoor street scenes with objects of varying sizes, whose distribution may vary between cities or driving routes; in addition appearance statistics can vary considerably when, e.g., adapting a person recognition model trained only using indoor scene images. Moreover, pixel-wise annotations are expensive and tedious to collect, making it particularly appealing to learn to share and transfer information between related settings.
In this work, we propose the first unsupervised domain adaptation method for transferring semantic segmentation FCNs across image domains. A second contribution of our approach is the combination of global and local alignment methods, using global and category specific adaptation techniques that are themselves individually innovative contributions. We align the global statistics of our source and target data using a convolutional domain adversarial training technique, using a novel extension of previous image-level classification approaches [32,6,7]. Given a domain aligned representation space, we introduce a generalizable constrained multiple instance loss function, which expands on weak label learning [26,25,27,24,14], but can be applied to the target domain without any extra annotations and explicitly transfers category layout information from a labeled source dataset.
We evaluate our approach using multiple large scale datasets. We first make use of recently released synthetic drive-cam data from both the GTA5 [28] and SYN-THIA [29] datasets, in order to examine a large adaptation shift from simulated to the real images available in CityScapes [3]. Next, we explore the domain shift of cross season adaptation within the SYNTHIA dataset. We then focus on adaptation across cities in the real world. We perform a detailed quantitative analysis of cross-city adaptation within the CityScapes dataset.
A final contribution of our paper is the introduction of a new unconstrained drive-cam dataset for semantic segmentation, Berkeley Deep Driving Segmentation (BDDS). Below we demonstrate initial qualitative adaptation results from Cityscapes cities to the cities in BDDS. Across all of these studies, we show that our adaptation algorithm improves the target semantic segmentation performance without any target annotations.

Related Work
Semantic Segmentation Semantic segmentation is a key computer vision task and has been studied in a plethora of publications. Following the success of large-scale image classification, most current semantic segmentation models use some convolutional network architecture [5,10] with many recent approaches using fully convolutional networks (FCNs) [20] to map the input RGB space to a semantic pixel space. These models are compelling because they al-low a direct end-to-end function that can be trained using back propagation. The original FCN formulation has since been improved using dilated convolution [33] and postprocessing techniques, such as Markov/conditional random fields [1,19,34].
Motivated by the high cost of collecting pixel level supervision, a related body of work has explored using weak labels (typically image-level tags defining presence / absence of each class), to improve semantic segmentation performance. Pathak et al. [26] and Pinheiro et al. [27] modeled this problem as multiple instance learning (MIL) and reinforce confident predictions during the learning process. An improved method was suggested by [24] who use an EM algorithm to better model global properties of the image segments. This work was in turn generalized by Pathak et al. who proposed a Constrained CNN which is able to model any linear constraints on the label space (i.e. presence / absence, percent cover) [25]. In another recent paper [15], Hong et al. used auxiliary segmentation to generalize semantic segmentations to categories where only weak label information was available.
From a domain adaptation perspective, these methods all assume that weak labels are present during training time for both source domain and target domain. In this work, we consider a related, but different learning scenario: strong supervision is available in the source domain, but that no supervision is available in the target domain.
Domain Adaptation Domain adaptation in computer vision has focused largely on image classification, with much work dedicated to generalizing across the domain shift between stock photographs of objects and the same objects photographed in the world [30,17,8]. Recent work includes [32,6,7] which all learn a feature representation which encourages maximal confusion between the two domains. Other work aims to align the features [21,22] by minimizing the distance between their distributions in the two domains. Based on Generative Adversarial Network [9], Liu et al. proposed coupled generative adversarial network to learn a joint distribution of images from both source and target datasets [18].
Much less attention has been given to other important computer vision tasks such as detection and segmentation. In detection, Hoffman et al. proposed a domain adaptation system by explicitly modeling the representation shift between classification and detection models [11] along with a follow-up work which incorporated per-category adaptation using multiple instance learning [12]. The detection models were later converted into FCNs for evaluating semantic segmentation performance [13], but this work did not propose any segmentation specific adaptation approach. So far as we know, our method is the first to introduce domain adaptation techniques for semantic segmentation models.

Fully Convolutional Adaptation Models
In this section, we describe our adaptation algorithm for semantic segmentation using fully convolutional networks (FCNs) across domains which share a common label space. Without loss of generality, our method can be applied to other segmentation models, though we focus here on FCNs due to their broad impact. We consider having access to a source domain, S, with both images, I S , and labels, L S . We train a source only model for semantic segmentation which produces a pixel-wise per-category score map φ S (I S ).
Our goal is to learn a semantic segmentation model which is adapted for use on the unlabeled target domain, T , with images, I T , but no annotations. We denote the parameters of such as network as φ T (·). If there is no domain shift between the source and target domains then one could simply apply the source model directly to the target with no need for an adaptive approach. However, there is commonly a difference between the distribution of the source labeled domain and the target test domain.
Therefore, we present an unsupervised adaptation approach. We begin by noting that there are two main opportunities for domain shift. First, global changes may occur between the two domains resulting in a marginal distribution shift of corresponding feature space. This may occur between any two different domains, but will be most distinct in large shifts between very distinct domains, such as adapting between simulated and real domains. The second main shift occurs due to category specific parameter changes. This may result from individual categories having specific biases in the two domains. For example, when adapting between two different cities the distribution of cars and the appearance of signs may change.
We propose an unsupervised domain adaptation framework for adapting semantic segmentation models which di-rectly tackles both the need for minimizing the global and the category specific shifts. For our model, we first make the necessary assumption that the source and target domains share the same label space and that the source model achieves performance greater than chance on the target domain. Then, we introduce two new semantic segmentation loss objectives, one to minimize the global distribution distance, which operates over both source and target images, L da (I S , I T ). Another to adapt the category specific parameters using target images and transferring label statistics from the source domain P L S , L mi (I T , P L S ). Finally, to ensure that we do not diverge too far from the source solution, which is known to be effective for the final semantic segmentation task, we continue to optimize the standard supervised segmentation objective on the source domain, L seg (I S , L S ). Together, our adaptive learning approach is to optimize the following joint objective: We illustrate overall adaptation framework in Figure 2. Source domain data is used to update the standard supervised loss objective, trained using the source pixel-wise annotations. Both source and target data are used without any category annotations within fully-convolutional domain adversarial training to minimize the global distance of feature space between the two domains. Finally, category specific updates using a constrained pixel-wise multiple instance learning objective is performed on the target images, with source category statistics used to determine the constraints.
Note, our approach may be generally applied to any FCN-based semantic segmentation framework. For our experiments, we use the recently proposed front-end dilated fully convolutional network [33], based on 16 layers VG-GNet [31], as our base model. There are 16 convolutional layers, where the last three convolutional layer converted from fully connected layers, called f c 6 , f c 7 , f c 8 , followed by 8 times bilinear up-sample layer to produce segmentation in the same resolution as input image.

Global Domain Alignment
We begin by describing in more detail our global domain alignment objective, L da (I S , I T ). Recall, that we seek to minimize the domain shift between representations of the source and target data. A recent line of research has shown that the domain discrepancy distance may be minimized through an adversarial learning procedure, whereby simultaneously a domain classifier is trained to best distinguish the source and target distributions and the representation space is updated according to the inverse objective [32,2,7]. The approaches heretofore have been introduced for classification models where each individual instance in the domain corresponds exactly to an image.
Here, we propose a new domain adversarial learning objective which may be applied for pixel-wise approaches to aid in learning domain invariant representations for semantic segmentation models. The first question to answer is what should comprise an instance within the dense prediction framework. Since recognition is sought at the pixel level alignment of full image representations will marginalize out too much distribution information limiting the alignment capability of the adversarial learning approach.
Instead, we consider the region corresponding to the natural receptive field of each spatial unit in the final representation layer (e.g. f c 7 ), as individual instances. In doing so, we directly supply our adversarial training procedure with the same information which is used to do final pixel prediction. Therefore, this provides a more meaningful view of the overall source and target pixel-space representation distribution distance which needs to be minimize.
Let φ −1 (θ, I) denote the output of the last layer before pixel prediction according to network parameters, θ. Then, our domain adversarial loss, L da (I S , I T ) consists of alternating minimization objectives. One concerning the parameters of the representation space, θ, under which we would like to minimize the observed source and target distance, , for a given distance function, d(·). The second concerning estimating the distance function through training a domain classifier to distinguish instances of the source and target domains. Let us denote the domain classifier parameters as θ D . We then seek to learn a domain classifier to recognize the difference between source and target regions and use that classifier to guide the distance minimization of the source and target representations.
Let σ(·) denote the softmax function and let the domain classifier predictions be indicated as p θ D (x) = σ(φ(θ D , x))). Assuming the output of layer −1 has H×W spatial units, then we can define the domain classifier loss, L D , as follows: where R S hw = φ −1 (θ, I S ) hw and R T hw = φ −1 (θ, I T ) hw denote the source and target representation of each units, respectively.
For convenience let us also define the inverse domain loss, L Dinv as follows: Finally, with these definitions, we may now describe the alternating minimization procedure.
Optimizing these two objectives iteratively amounts to learning the best possible domain classifier for relevant image regions (Eq (6)) and then using the loss of that domain classifier to inform the training of the image representations so as to minimize the distance between the source and target domains (Eq (7)).

Category Specific Adaptation
Given our representation which has minimized the global domain distribution distance through our fully convolutional adversarial training objective, the next step is to further adapt our source model through modifying the category specific network parameters. In order to do this, we draw upon recent weak learning literature [25,26], which introduced a fully convolutional constrained multiple instance learning objective. This work used size and existence constraints to produce a predicted target labeling to use for further training. We present the novel application of such approaches for domain adaptation and generalize the technique for use in our unlabeled setting.
First, we consider new constraints which are useful for our pixel-wise unsupervised adaptation problem. In particular, we begin by computing per image labeling statistics in the source domain, P L S . Specifically, for each source image which contains class c, we compute the percentage of image pixels which have a ground truth label corresponding to this class. We can then compute a histogram over these percentages and denote the lower 10% boundary as, α c , the average value as δ c , and the upper 10% as γ c . We may then use this distribution to inform our target domain size constraints, thereby explicitly transferring scene layout information from the source to the target domain. For example, in a driving scenario, often the road occupies a large portion of the image while street signs occupy relatively little image real estate. This information is critical to the constrained multiple instance learning procedure. In contrast, prior work used a single size threshold across classes known to be in the image.
We begin by presenting our constrained multiple instance loss for the case where image-level labels are known. Thus, for a given target image for which a certain class c is present, we impose the following constraints on the output prediction map, p = arg max φ(θ, I T ).
Thus, our constraint encourages pixels to be assigned to class c such that the percentage of the image labeled with class c is within the expected range observed in the source domain. Practically, we optimize this objective with lower bound slack to allow for outlier cases where c simply occupies less of the image than is average in the source domain. However, we do not allow slack on the upper bound constraint as it is important that no single class occupies too much of any given image. Notice that our updated constraint is general and can be equivalently applied to all classes regardless if they correspond with traditional object notion (e.g. bikes or people) or stuff notion (e.g. sky or vegetation).
Given this constraint we may now optimize for a new class prediction space to use for future learning. For the specific optimization details we refer the reader to Pathak et al. [25]. We provide one important modification. As we seek to optimize over both object and stuff categories, we note that the relative number of pixels devoted to each may vary significantly which could cause the model to diverge, over-fitting to those classes which are highly represented in the images. Instead, we use a simple size constraint that if the lower 10% of the source class distribution, α c , is greater than 0.1, then we down-weight the gradients due to these classes by a factor of 0.1. This is re-weighting approach can be viewed as a re-sampling of the classes so as to come closer to a balanced set, allowing the relatively small classes potential to inform the learning objective.
While the approach described above describes a generalized constrained multiple instance objective, it relies on known image-level labels. Since we lack such information in our unsupervised adaptation setting, we now describe our procedure for predicting image level labels. Thus, our complete approach can be described as first predicting imagelevel labels and then optimizing for pixel predictions which satisfy the source transferred class size constraints.
In contrast to weakly-supervised settings, we do not learn a segmentation model from scratch with known image-level annotations. Instead, we have access to a fully supervised source dataset and use domain transferred constraints to facilitate transfer to an unsupervised target domain. Thus we both have a stronger initial model with a fully supervised using pixel-level annotations from source domain and are additionally able to regularize the learning procedure by training with weak label loss on target domain. Again, given a target image, I T , we compute the current output class prediction map, p = arg max φ(θ, I T ). For each class we compute the percentage of pixels assigned to that class in our current prediction, d c = 1 H·W h∈H w∈W (p hw = c). Finally, we assign an image-level label to class c if d c > 0.1 * α c , meaning if we currently label at least as many pixels as 10% of the expected number for a true class appearing in the image.

Experiments
In this section, we report our experimental results on three different domain adaptation tasks: cities → cities, season → season, and synthetic → real, studied across four different datasets. We analyze both our overall adaptation approach as well as the sub-components to verify that both our global and category specific alignment offer meaningful contributions.
For all experiments we use the front-end dilated fully convolutional network [33] as both the initialization for our method and as the baseline model for comparison. All code and models are trained and evaluated in the Caffe [16] framework and will be made available before camera-ready.
For fair comparison, we use the Intersection over Union (IoU) evaluation metric for all experiments. For cities → cities and synthetic → real tasks, we followed the evaluation protocol of [3] and train our models with 19 semantic labels of Cityscapes. For season → season task, we use 13 semantic labels of SYNTHIA instead.

Datasets
Cityscapes contains 34 categories in high resolution, 2048 × 1024. The whole dataset is divided into three parts: 2, 975 training samples, 500 validation samples and 1, 525 test samples. The split of this dataset is city-level, which covers individual European cities in different geographic and population distribution.
SYNTHIA contains 13 classes with different scenarios and sub-conditions. As for season → season task, we regard SYNTHIA-VIDEO-SEQUENCES as play ground. There are 7 sequences, covering different scenarios (highway, roundabout, mountain path, New York City, Old European Town) with several sub-sequences, such as seasons(Spring, Summer, Fall, Winter), weathers(Rain, Soft-Rain, Fog), and illuminations(Sunset, Dawn, Night). These frames are captured by 8 RGB cameras forming a binocular 360 • visual field. In order to minimize the impact of viewpoint, we only pick up the dashcam-like frames for all the time. As for synthetic → real task, we take SYNTHIA-RAND-CITYSCAPES, providing 9, 000 random images from all the sequences with Cityscape-compatible annotations, as source domain data.
GTA5 contains 24, 966 high quality labeled frames from realistic open-world computer games, Grand Theft Auto V (GTA5). Each frame, with high resolution 1914 × 1052, is generated from fictional city of Los Santos, based on Los Angeles in Southern California. We take the whole dataset with labels compatible to Cityscapes categories for synthetic → real adaptation.
BDDS contains thousands of dense annotated dashcam video frames and hundreds of thousands of unlabeled frames. Each sample, with high resolution 1280 × 720, provides 34 categories compatible to Cityscapes label space.  Table 1: Adaptation from synthetic to real. We study the performance using GTA5 and SYNTHIA as source labeled training data adapted and Cityscapes train as an unlabeled target domain, while evaluating our adaptation algorithm on Cityscapes val. Meanwhile, we show an ablation of the components of our method and how each contributes to the overall performance of our approach. Here GA represents global domain alignment and CA indicates category specific adaptation.
The majority of our data comes from New York and San Francisco, which are the representative of eastern and western coasts. Different from the other existing driving datasets, this dataset covers diverse driving scenarios under different conditions, such as urban street view at night, highway scene in rain and so on, providing challenging domain adaptation settings.

Quantitative and Qualitative Results
We broadly study three types of shifts. First we study a large distribution shift, as seen when adapting from simulated to real imagery. Next, we study a medium sized shift, through adaptation across season patterns observed within the SYNTHIA dataset. Finally, we explore situations of relatively smaller domain shift, though exploring adaptation between different cities within the CityScapes dataset.

Large Shift: Synthetic to Real Adaptation
We begin the evaluation of our method by studying the large domain shift of adapting between simulated driving data and real world drive-cam data. Table 1 shows semantic segmentation performance for the shift between GTA5 to CityScapes and between SYNTHIA to CityScapes. This illustrates that even with this large domain difference our unsupervised adaptation solution is capable of improving the performance of the source dilation model. Notice that for this larger shift setting, such as GTA5→Cityscapes, the domain adversarial training contributes 4.4% raw and ∼20% relative percentage mIoU improvement and multiple instance loss contributes yet another 1.6% raw and ∼6% relative percentage mIoU improvement. As for SYNTHIA→Cityscapes, our method also offers a measurable improvement.

Medium Shift: Cross Seasons Adaptation
As our next experiment, we seek to analyze adaptation across season patterns. To this end, we use the SYNTHIA dataset which has synthetic images available along with season annotations. We first produce one domain per each of the season labels available: Summer, Fall and Winter. We then perform adaptation across each of the 6 shifts and report the performance of our method in comparison to the source dilation model in Table 2. On average we get ∼3 percentage mIoU improvement for season → season adaptation and find that for 12/13 object categories our adaptation method provides higher mIoU. The one class we saw no improvement after adaptation is for car. We presume this results from the fact that cars have little or no appearance difference across seasons in this synthetic dataset. For example, consider the qualitative results shown in Figure 3 for the shift of fall to winter. While the roads and side-walks have been rendered in a white to simulate snow in winter, the cars are rendered in the same appearance as in fall. In fact some of the largest performance improvements we saw from our method we in categories like road in the shift of fall to winter, and our method is able to overcome this large appearance shift.

Small Shift: Cross City Adaptation
For our third quantitative experiment we move towards studying cross city adaptation within the CityScapes dataset. In Table 3 we report performance on the task of adapting between the labeled cities in the CityScapes train to the unlabeled cities in either the Cityscapes val. The top row shows the performance of the dilation frontend model [33]. We report performance after only global alignment through domain adversarial training (indicated   Table 2: Adaptation across seasons. We study the cross season performance using sub-sequences of SYNTHIA dataset. We report quantitative comparisons of performance before and after adaptation for training on one season and evaluating on another unannotated novel season. (Avg: the average performance of adaptation from one to another.) as Our method (GA only)) and after the category specific alignment with the constrained multiple instance loss (indicated as Our method (GA+CA)). We note that for this adaptation experiment the majority of the improvement from our method is as a result of the domain adversarial training (3.6 percentage mIoU) whereas after category specific alignment only offers a noticeable improvement on the categories of traffic light, rider and train. One reason could be that the domain shift between train and val mainly results from a change in the global appearance, due to the difference in city, whereas the specific category appearance may not change that significantly. Since per-formance on this within dataset adaptation is already quite high, the primary improvements arise from producing more consistent within object segmentations.

BDDS Adaptation
Finally, we analyze another real world cities → cities adaptation using our new large scale driving image dataset BDDS. To understand this difficulty and evaluate our methods more extensively, we create a new image dataset based on dash cam videos. Although CityScapes covers various cities in Germany and neighboring countries, we observe that the cities in the other places have different visual ap-  Table 3: Adaptation across cities. We study the performance using Cityscapes train cities as source labeled training data adapted and evaluate our adaptation algorithm on Cityscapes val as unlabeled target domains. Meanwhile, we show an ablation of the components of our method and how each contributes to the overall performance of our approach. Here GA indicates global domain alignment in section 3.1 and CA represents category specific adaptation in section 3.2. pearance and street layout. They may post serious challenges to the models learned from CityScapes. Up to now, we have collected more than 100, 000 images covering outdoor scenes at different time and places. Based on the current annotation progress, there would 5, 000∼10, 000 images with fine segmentation annotation before CVPR 2017. We aim for 10, 000∼20, 000 finely segmented street scene images eventually. We take ∼60, 000 images in area of San Francisco from BDDS and study how well we can adapt the model learned on Cityscapes to San Francisco. Because our methods don't require labels in the target domain, we can use all the new images in our training the adaptation. Some results are shown in Figure 4. From these qualitative results, we observe that there is a significant segmentation quality drop when a model trained on Cityscapes is used in BDDS directly. It usually appears as noisy segmentation or wrong context. After adaptation, the segmentation results usually become much cleaner. We expect to conduct extensive quantitative evaluation when annotations are ready.

Conclusion
In this paper, we present an unsupervised domain adaptation framework with fully convolutional networks for semantic segmentation. We propose fully convolutional networks with domain adversarial training for global domain alignment, while leveraging class-aware constrained multiple instance loss for transferring spatial layout. We demonstrate the effectiveness of our method on domain shifts between different cities, seasons and from synthetic to real, and we offer a new large-scale real-city driving image dataset. While the task of image classification has seen the bulk of the effort in developing domain adaptation methods, our experiments demonstrate the importance of adaptation in pixel-level dense prediction as well. Our approach is the first step in this direction.