TL;DR
Deep CORAL trains a deep network on labeled pictures from a source domain and, at the same time, makes its internal features look statistically alike on unlabeled pictures from a target domain. It does this by adding a loss that measures the gap between the source and target feature covariance matrices, a gap that gradient descent can shrink. On the Office benchmark of 31 object classes it reached 72.1 percent average accuracy over six domain shifts, the highest of the methods the authors compared.
Builds on: Domain Adaptation, Covariance Matrix, Matrix Norm, Convolutional Neural Network, Fine-Tuning · Leads to: the feature-alignment methods in the wider Domain Adaptation family
Why it mattered
Most deployed vision systems meet images that look different from their training images: a new camera, a new store, new lighting. Labeling every new setting is slow and expensive, so the useful question is how to reuse labels from one setting. Deep CORAL gives a clear answer for the common case where the target images have no labels at all.
Its central idea is that matching the second-order statistics of the features, meaning their spreads and co-variations, is enough to make a classifier transfer. The authors call CORAL simple yet effective, and note that applying the loss to other layers or architectures should be straightforward. Its gain is modest but consistent: on the Office benchmark its average accuracy was 72.1, against 70.1 for the same network with no adaptation, and it beat that network on all six shifts.
History
Before 2016, domain adaptation was mostly shallow. Reweighting methods and subspace methods such as the geodesic flow kernel and subspace alignment worked on hand-built features. Deep networks trained on ImageNet gave strong features, and Donahue and colleagues showed that those features were still sensitive to domain shift.
The CORAL method, by Sun, Feng and Saenko, appeared at AAAI in 2016 under the title "Return of frustratingly easy domain adaptation". Deep CORAL, by Sun and Saenko, was posted to arXiv in July 2016. It sat among the deep adaptation methods of 2014 and 2015: DDC, DAN and ReverseGrad. It was easy to add to an existing training loop, and the paper compared it directly with those methods on the Office benchmark.
The problem
A classifier learns the statistics of its training data. When the data it meets later comes from a different distribution, its accuracy falls. This is domain shift. The paper notes that deep convolutional features are invariant to low-level cues to some degree, yet Donahue and colleagues showed that they are still susceptible to domain shift. In the unsupervised case the learner has labeled source data and unlabeled target data, and must build a model that works on the target.
Earlier fixes came in three families. Reweighting the training points to look like the test distribution, the idea behind Covariate Shift corrections, works only for narrow kinds of shift. Subspace and manifold methods such as GFK, SA and TCA align the two domains with a linear map in a lower-dimensional space, but they are not trained end to end with a deep network. CORAL, the authors' earlier method, aligns second-order statistics with a linear transformation and then trains a support vector machine in a separate step, so the features are never learned for the task.
Deep methods existed as well. DDC adds a loss that aligns only the means of one layer. DAN matches distributions with several kernels across several layers. ReverseGrad adds a binary domain classifier that the network learns to confuse. Deep CORAL's aim was to match covariances inside the network, with one differentiable loss that can sit at any layer.
How it works
Take one tiny instance. Suppose the network's last layer gives two numbers per image, so the feature width is . The paper's real experiments use a last layer of width 31, one output per object class. The loop below runs on every batch.
flowchart LR A[Labeled source images] --> C[Shared network] B[Unlabeled target images] --> C C --> D[Source features] C --> E[Target features] D --> F[Classification loss] D --> G[Source covariance C_S] E --> H[Target covariance C_T] G --> I[CORAL loss] H --> I F --> J[Total loss] I --> J J --> K[Backprop updates shared weights]
-
Stack the source features. Three labeled source images give three feature vectors, which become the rows of a matrix with rows , and . Check: three rows, one per image, and two columns, one per feature.
-
Compute the source covariance . The column means are 3 and 4. Subtract them from every row to get , and . Multiply the columns pairwise across the rows, then divide by . The result is . Check: the diagonal holds each feature's variance (4 and 12), and the off-diagonal 6 is positive, so the two features tend to rise together.
-
Compute the target covariance . Suppose the three unlabeled target feature vectors, processed the same way, give . Check: it is symmetric and has the same shape as . No labels were needed to compute it.
-
Measure the gap. Subtract: has entries 0, 0, 0 and 2. Square each entry and add: 4. Divide by . The CORAL loss is . Check: the loss would be zero only if the two covariance matrices were identical.
-
Add the classification loss. Say the classification loss on the labeled batch is 0.5. With weight the total is . Check: the alignment term contributes half of the total, so it has real influence on training.
-
Backpropagate. The gradient of the CORAL loss is proportional to the gap . The update lowers the source's spread along the second feature (12 moves toward 10) and raises the target's (10 moves toward 12). Check: the squared gap shrinks whenever those two entries move toward each other.
-
Repeat for many batches. The classification term pushes the features to separate the labeled classes, and the CORAL term pushes source and target to share their covariance. The paper sets the weight so that the two losses are roughly equal at the end of training.
The math
Let hold the source feature vectors as rows, and the target ones. Let and be their covariance matrices. The CORAL loss is the squared Frobenius norm of the difference, scaled by :
The squared Frobenius norm of a matrix is the sum of its squared entries. The factor is a normalising constant that depends only on the feature width .
Step 2 in symbols
Here is a column vector of ones. The term is the uncentred sum of products. The row holds the column sums, so dividing its outer product by removes the mean. Check with the numbers: and . The subtracted term is . The difference is , and dividing by gives .
Step 4 in symbols
For and a gap equal to times the identity matrix, the squared Frobenius norm is , so the loss is . The plot shows this curve.
- loss when C_S - C_T = x I
Step 5 in symbols
Here is the number of layers that carry a CORAL loss, and each trades alignment against classification accuracy on the source domain. The paper sets so that the two losses are roughly equal at the end of training. In the walkthrough and .
Step 6 in symbols
The paper gives the gradients with respect to each source and target entry:
Both gradients are multiplied by the same matrix . The sign is opposite for source and target, so one update pushes the source features and the target features toward each other.
Worked examples
- Let , and .
- The difference is , with entries 1, 0, 0 and 1.
- The squared Frobenius norm is .
- The normalising constant is .
- The loss is .
- Interpretation: the source features have twice the variance of the target features in each direction. The loss is small but not zero, so training still asks for a small change.
Use the numbers from How it works: classification loss 0.5 and CORAL loss 0.25.
- With , the weighted CORAL term is .
- The total loss is .
- The two terms are now equal, which is the rough balance the paper aims for at the end of training.
- With the total would be 0.5, and nothing would pull the target features toward the source. The paper's Figure 2(c) reports that without the CORAL loss the domain distance becomes at least 100 times larger.
- Interpretation: is a dial. Equal terms are a sensible starting point, not a law, and the right value is found by training.
The comparison is on the A to D shift (Amazon to DSLR images). Values are accuracies from the paper's Table 1.
- The no-adaptation network (CNN) reaches 63.8 on A to D.
- D-CORAL reaches 66.8, so the gain is points.
- DAN reaches 65.8, so D-CORAL leads DAN by point.
- On the A to W shift, the same comparison gives points over CNN.
- The average over all six shifts is 70.1 for CNN and 72.1 for D-CORAL, a gain of 2.0 points.
- Interpretation: the gain depends on the shift, and the average gain is about 2 points.
Try it: average the six D-CORAL entries and compare with its AVG column. Answer: , and , which rounds to the reported 72.1.
Results
Accuracy in percent on the six Office shifts, from the paper's Table 1 (selected rows).
| Method | A→D | A→W | D→A | D→W | W→A | W→D | Avg |
|---|---|---|---|---|---|---|---|
| CNN (no adaptation) | 63.8 | 61.6 | 51.1 | 95.4 | 49.8 | 99.0 | 70.1 |
| DDC | 64.4 | 61.8 | 52.1 | 95.0 | 52.2 | 98.5 | 70.6 |
| DAN | 65.8 | 63.8 | 52.8 | 94.6 | 51.9 | 98.8 | 71.3 |
| CORAL | 65.7 | 64.3 | 48.5 | 96.1 | 48.2 | 99.8 | 70.4 |
| D-CORAL | 66.8 | 66.4 | 52.8 | 95.7 | 51.5 | 99.2 | 72.1 |
- Deep CORAL has the best average, 72.1, ahead of DAN at 71.3 and the no-adaptation network at 70.1. The older subspace methods, GFK, SA and TCA, averaged 63.4, 59.7 and 56.9.
- It is highest on three of the six shifts. The paper says its margins on the other three are at most 0.7 points.
- Figure 2 tracks the A to W shift. With the CORAL loss, target accuracy is much higher while source accuracy stays strong. Without it, the paper reports the domain distance is at least 100 times larger.
- Limits: one benchmark with 31 classes and six shifts, one adapted layer (fc8), and differences of about one point between the deep methods. These are small margins for a single benchmark, and the paper does not test other datasets.
Common mistakes and tradeoffs
It is tempting to think the CORAL loss alone can do the job. In fact, minimising it alone lets the network send every source and target image to one point. The loss is then zero, but no classifier can separate the classes. That is why the CORAL term is added to the classification loss rather than used by itself.
It is tempting to think the covariance is between images. In fact it is a matrix over feature dimensions, estimated from a batch. Its size depends on the width of the layer, not on the number of images.
It is tempting to think is a detail. In fact it sets the trade-off. A small value ignores the target, and a large value can hurt source accuracy.
Use Deep CORAL when the target images are unlabeled, both domains share one label set (the paper's setting), and the layer is narrow enough for a batch to estimate its covariance well. The paper uses batches of 128 with a 31-wide layer. A 4096-wide layer has covariance entries, and a small batch estimates them poorly. Do not use it when the target has labels, since fine-tuning on those labels is simpler, or when the label sets differ. When the shift changes more than second-order statistics, other tools fit better: DDC and DAN for means and kernels, ReverseGrad for adversarial matching, and reweighting when only the input distribution changes.
Reading guide
- Introduction needs Domain Adaptation and Transfer Learning. Read it for the setting: labeled source, unlabeled target.
- Related work needs Covariate Shift and Kernel Function, which underlie the reweighting and kernel-matching ideas.
- 3.1 CORAL loss needs Covariance Matrix, Matrix Norm and Backpropagation for the gradient formulas.
- 3.2 End-to-end training needs Cross-Entropy Loss and Linear Classifier, plus the idea of weighting two losses with .
- 4 Experiments needs Fine-Tuning, Convolutional Neural Network, Stochastic Gradient Descent, Momentum, L2 Regularization and Learning Rate for the training settings.
- 5 Conclusion adds no new ideas.
Recap
- Domain shift: a model trained on one distribution loses accuracy on another, and unsupervised adaptation has no target labels to fix it.
- A covariance matrix records how each feature spreads and how pairs of features co-vary, estimated from a batch.
- The CORAL loss is the squared Frobenius gap between the source and target covariance matrices, divided by .
- Training minimises the classification loss plus times the CORAL loss, so the features stay discriminative and become aligned.
- Read next: Domain Adaptation for the full problem, and Transfer Learning for reusing networks across tasks.
Check yourself
QuestionWhich two quantities does the CORAL loss compare, and how is each computed?Show answer
QuestionFor d = 2, let C_S have rows (4, 1) and (1, 4), and let C_T have rows (2, 1) and (1, 2). What is the CORAL loss?Show answer
QuestionWhy is the CORAL loss added to the classification loss instead of being used alone?Show answer
QuestionA team trains a defect detector on labeled images from one factory line and must deploy it on a second line with different lighting and no labels. They add Deep CORAL at the last hidden layer. Name two things they should check.Show answer
Sources
- Sun, B. and Saenko, K. (2016). Deep CORAL: Correlation Alignment for Deep Domain Adaptation. arXiv:1607.01719. https://arxiv.org/abs/1607.01719
- Tzeng, E., Hoffman, J., Zhang, N., Saenko, K. and Darrell, T. (2014). Deep Domain Confusion: Maximizing for Domain Invariance. arXiv:1412.3474. https://arxiv.org/abs/1412.3474