Skip to content

Robustness, label quality, and active data acquisition · Robustness, label quality, and active data acquisition · ROB005 · Training method

Deep CORAL

Adapt deep features by penalizing a difference between source and target feature covariances while preserving a supervised source task objective.

Runs as a notebook Complete calculation CodeSplash's run and the reference's record

In CodeSplash

No method yet, but the reference's example runs here as a notebook.

Do it in CodeSplash Open the reference's example as a Python or R notebook.

Availability
Runs as a notebook
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Adapt deep features by penalizing a difference between source and target feature covariances while preserving a supervised source task objective.

Question / hypotheses

Can second-order feature alignment improve performance on an unlabeled target domain? Matching covariance is an optimization criterion, not proof of equal distributions.

Architecture / computational structure

Source and target batches pass through a shared encoder. An unbiased sample covariance is calculated for each feature matrix. A Frobenius discrepancy is added to source classification loss and differentiated through the encoder.

Assumptions

Feature coordinates have shared meaning, each covariance batch has at least two observations, and source labels are useful for the target task. The declared adaptation protocol permits target inputs but not target labels. Class-prior and conditional shifts can make marginal alignment harmful.

Formula / computational definition

LCORAL=∥CS−CT∥F24d2,L=Lsource+λLCORAL.\mathcal L_{\rm CORAL}=\frac{\|C_S-C_T\|_F^2}{4d^2},\qquad \mathcal L=\mathcal L_{\rm source}+\lambda\mathcal L_{\rm CORAL}.

Parameters and notation

Learned: encoder and task head. Derived batch quantities: d-dimensional covariance matrices. Hyperparameters: layer(s) aligned, λ, batch composition/size, feature scaling, learning rate, and frozen layers. Covariance formation costs grow with feature dimension and can dominate small models.

Fitting, fine-tuning, and adaptation

Start from source pretraining, then fine-tune with the combined loss. A frozen encoder cannot be altered by the covariance term. Choose target-aware validation rules without using final target test labels. Preserve an unadapted source baseline to detect negative transfer.

How to use and calibrate

Track source loss, alignment loss, target proxy diagnostics, and any allowed independent target validation. Examine class-conditioned behavior when labels become available. Reproduce the same unbiased covariance denominator in both languages.

Example application

Adapt a feature extractor from one camera domain to another using unlabeled target images and source annotations.

Interpretation / pitfalls

Watch out

An encoder can shrink or collapse features to reduce covariance discrepancy. Source task loss and held-out performance are essential. Covariance equality ignores higher moments, label meaning, and multimodal class structure.

Python and R code examples

Scope: Exact covariance discrepancy on supplied feature matrices; no encoder training. Python: NumPy; R: stats.

Validation: Python executed successfully on the supplied fixture; R reviewed but not executed.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Exact covariance discrepancy on supplied feature matrices; no encoder training. Python: NumPy; R: stats. · needs numpy

import numpy as np
S=np.array([[0.,1.],[1.,2.],[2.,1.],[3.,4.]])
T=np.array([[0.,0.],[1.,1.],[2.,3.],[3.,2.]])
d=S.shape[1]; cs=np.cov(S,rowvar=False); ct=np.cov(T,rowvar=False)
value=np.sum((cs-ct)**2)/(4*d*d)
assert value>=0 and np.allclose(np.cov(S+10,rowvar=False),cs)
print(value)
R

Complete calculation — Exact covariance discrepancy on supplied feature matrices; no encoder training. Python: NumPy; R: stats.

S <- rbind(c(0,1),c(1,2),c(2,1),c(3,4))
T <- rbind(c(0,0),c(1,1),c(2,3),c(3,2)); d <- ncol(S)
value <- sum((cov(S)-cov(T))^2)/(4*d^2)
stopifnot(value>=0,isTRUE(all.equal(cov(S+10),cov(S))))
print(value)

Sources

From the CodeSplash reference, entry ROB005.