Skip to content
class

FancyPCA

extendsPhotometricTransform[Empty]
FancyPCA(alpha: float = 0.1, p: float = 0.5)

AlexNet-style PCA colour augmentation (Krizhevsky 2012, Albumentations FancyPCA).

Computes the per-image RGB covariance matrix, takes its eigendecomposition, and adds a random linear combination of the eigenvectors weighted by their eigenvalues to every pixel. The weights are i.i.d. samples from alpha * U(-1, 1) per channel — same recipe used in the original AlexNet training pipeline.

Parameters

alphafloat= 0.1
Standard deviation scale on the eigenvalue-weighted perturbation; larger values give more colour jitter.
pfloat= 0.5
Probability of applying the transform.

Raises

ValueError
If the input image does not have exactly 3 channels.

Examples

>>> import lucid
>>> import lucid.utils.transforms as T
>>> tf = T.FancyPCA(alpha=0.1, p=1.0)
>>> out = tf(T.Image(lucid.rand(3, 32, 32))).data
>>> tuple(out.shape)
(3, 32, 32)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(alpha: float = 0.1, p: float = 0.5)

Instance methods

1
fn

make_params

→Empty
make_params(img: Tensor)

Return the no-op parameter sentinel for FancyPCA.

Parameters

Image tensor; not inspected here.

Returns

Empty

The shared NO_PARAMS sentinel — the random eigenvector weights are drawn inline in the apply step because they depend on the per-image covariance decomposition.

Dunder methods

1