Image Colorization
Image colorization predicts plausible colors for a grayscale photo. It works in the CIELAB (Lab) color space, which separates lightness from two color channels, (green to red) and (blue to yellow). The grayscale image is the channel, . A network predicts the color channels , and the output image concatenates . Training solves for a chosen loss . Any color photo gives a training pair for free, so no labeling is needed.
The naive loss is per-pixel L2 regression on the values,
where and are the true and predicted at pixel . Its minimizer at each pixel is the conditional mean of the plausible colors. When an object could be several colors, the mean falls between them, often close to gray, and results look desaturated or brownish.Zhang, Isola, Efros (ECCV 2016, “Colorful Image Colorization”) treat colorization as per-pixel classification. They quantize the plane into bins ( in-gamut bins of size in the paper). The network outputs a distribution for every pixel and trains with the cross-entropy loss
where encodes the true color as a distribution over the bins. A colorfulness term reweights each pixel by how rare its true color is (class rebalancing), since most pixels in photos have dull colors. Each predicted distribution becomes one color through an annealed mean, which lies between the distribution’s mean and its mode.The general lesson is loss design. When the correct output is ambiguous, regression averages the possibilities. A classification loss, a loss on CNN features, or a learned loss such as the discriminator in 8.4. Pix2Pix avoids the averaging.
Intuition
Grayscale keeps lightness and drops color. Many colors share the same lightness, so the input does not determine the output. A bird of a given gray could be blue in one training photo and red in another. A network trained with L2 loss sees all of them, and the prediction with the lowest squared error is their average. In the plane the average of a red and a blue lies between them, close to the gray center. The network learns to hedge, and the image comes out dull.
Lab separates the problem cleanly. The channel is given, so the network predicts only two numbers per pixel, and errors in them never change brightness. Classification over color bins lets the network report “red with probability , blue with probability ” without collapsing to a point between them. The figure shows the averaging in the plane, using the numbers from the car example below.
\usepackage{tikz}
\begin{document}
\definecolor{redc}{HTML}{D9483B}
\definecolor{bluec}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[x=1.6cm, y=1.6cm, >=latex]
\draw[->, mid] (-2.2,0) -- (2.2,0) node[right, black] {$b$};
\draw[->, mid] (0,-1.3) -- (0,1.9) node[above, black] {$a$};
\draw[mid, dashed] (0,0) circle (0.707);
\filldraw[mid] (0,0) circle (1.5pt) node[below right, black] at (0.05,-0.12) {\small gray};
\draw[thick, dotted] (0.9,1.2) -- (-1.1,0.2);
\filldraw[redc] (0.9,1.2) circle (2.5pt) node[right] {red, $(a,b) = (60, 45)$};
\filldraw[bluec] (-1.1,0.2) circle (2.5pt) node[left] {blue, $(10, -55)$};
\draw[thick] (-0.17,0.63) -- (-0.03,0.77); \draw[thick] (-0.17,0.77) -- (-0.03,0.63);
\draw[mid] (-0.15,0.75) -- (-0.7,1.3) node[left, black] {L2 prediction $(35, -5)$};
\node[mid, align=left, anchor=west] at (0.75,-0.75) {\small chroma $35.4$: the mean\\ \small sits close to gray};
\foreach \v/\t in {-2/-100, -1/-50, 1/50} \draw[mid] (\v,0.05) -- (\v,-0.05) node[below, black] {\scriptsize $\t$};
\foreach \v/\t in {-1/-50, 1/50} \draw[mid] (0.05,\v) -- (-0.05,\v) node[right, black] at (0.05,\v) {\scriptsize $\t$};
\node[anchor=west] at (-2.2,-1.6) {\small $a$: green ($-$) to red ($+$);\quad $b$: blue ($-$) to yellow ($+$)};
\end{tikzpicture}
\end{document}Properties
(Classification Keeps the Modes) A distribution over color bins can put its mass on two distant colors without predicting anything in between.
Cross-entropy, the loss of logistic regression extended to classes, is minimized when equals the true frequencies of the colors. For the ambiguous bird that is on a red bin and on a blue bin, if those are the training frequencies. The loss has no term that pulls the prediction toward the middle of the plane. The averaging problem moves to the final step, where each pixel must receive one color.
(Annealed Mean) The paper sharpens each predicted distribution with a temperature and then takes its mean.
The plain mean of brings back the desaturation. The mode, the single most likely bin, gives vivid colors but can jump between bins from pixel to pixel and create patchy artifacts. The annealed mean first reweights the distribution as
where is the probability of bin . It then returns the average of the bin centers weighted by . Setting gives the plain mean, and gives the mode. The paper uses .
(Class Rebalancing) Rare, saturated colors get larger loss weights, so the network does not settle on the common dull bins.
Most pixels in natural photos have low saturation: haze, walls, roads, dirt. With plain cross-entropy the network predicts these bins too often. The paper multiplies each pixel’s loss by the weight of its true bin , where
Here is the smoothed frequency of each bin over ImageNet, and mixes it with a uniform distribution. The second condition normalizes the weights to average over the data. The uniform part caps the weight of very rare bins, so a few rare pixels cannot dominate training. The lecture calls this the colorfulness-enhancing term.
(Free Supervision) Colorization trains on any collection of color photos, because the input is computed from the target.
Converting a color photo to Lab and dropping the channels gives the input and the target at once. The lecture’s grayscale-to-color results use ImageNet data (Russakovsky et al. 2015). Training labels that come from the data itself make this a self-supervised task. To color a bird correctly the network must first recognize it, so the paper also uses colorization as pretraining for recognition.
Derivation
We want to show that L2 regression predicts the conditional mean, and that the mean is never more saturated than the plausible colors are on average. Fix one pixel and its input. Let be the random true of that pixel, and let be the prediction. Adding and subtracting inside the square, the cross term has expectation zero, which leaves
The second term does not depend on , and the first is zero at . So the conditional mean minimizes the expected loss. The chroma , the distance from the gray point, measures saturation. The norm is convex, so Jensen’s inequality gives
The chroma of the L2 prediction is therefore at most the average chroma of the plausible colors. Equality holds only when all plausible colors lie on one ray from gray.
Examples
(Easy) Weighting Three Color Bins
A toy dataset has color bins. Gray-brown pixels make up of the data, brown and blue , so . Use .
Compute the rebalancing weights. What share of the total weighted loss does each bin carry, and what would happen with ? Before normalizing, , which gives , and . Their -weighted average is , so dividing by it gives . A blue pixel now counts about times as much as a gray-brown one. The shares of the loss are , against the unweighted shares . Blue's share almost triples.
With the weights are proportional to . Blue would count times as much as gray-brown, and each bin would carry exactly one third of the loss. The uniform part of the mixture keeps rare bins from taking over.
(Medium) A Car That Could Be Red or Blue
In a training set, cars with a certain gray value and shape are either red, , or blue, . Both colors have lightness . Assume a perfect network that knows these two options exactly.
(a) For a 50/50 split, find the L2 prediction, its chroma, and its expected loss compared with always predicting red. (b) For a 60/40 split, compare the plain mean with the annealed mean at . (a) The L2 prediction is the mean, , with chroma . Red has chroma and blue about , so the mean is roughly half as saturated as either car. At it is the dull mauve sRGB color . The cars are apart in , so each is from the mean. The expected loss of the mean is . Predicting red costs half the time and the other half, an expected . L2 training prefers the dull mean by a factor of two.
(b) The plain mean is , with chroma about . Annealing raises each probability to the power and renormalizes. The weights become for red and for blue. The annealed mean is about , with chroma , a clearly reddish color. With an exact 50/50 split, annealing keeps the weights equal and returns the dull mean again. No readout can choose a side when the model itself has no preference.