I’m working with ZCAWhitening
which has been added in the kornia
recently. You can find the implementation here
Mainly, this transform has following methods:

fit:
ZCAWhitening
requires you to first fit it on the data, potentially on whole dataset, but one batch willl do as well.  forward: Applies whitening transform to the data
 inverse_transform: inverse transform to the whitened data
Here’s my implementation:
class ZCAWhitenWrapper(Transform,GetAttr):
"Wrapping kornia implementation"
_default='_zca'
@delegates(kornia.color.ZCAWhitening)
def __init__(self,**kwargs):
self._zca = ZCAWhitening(**kwargs)
def setups(self,dl:DataLoader):
if not self._zca.fitted:
x,*_ = dl.one_batch()
self._zca = self._zca.fit(x)
def encodes(self,x:TensorImage): return self._zca(x)
def decodes(self,x:TensorImage):
if self._zca.compute_inv:
x = self._zca.inverse_transform(x)
return min_max_scale(x)
I would like to know what could have been done better? especially, I want to get rid of self._zca
.
cc: @sgugger
Results
The Cifar10 preprocessing involves GlobalContrastNormalization
and ZCAWhitening
. The results of these steps are as follows:
Before preprocessing:
After preprocessing:
I’ve seen 2% error_rate improvement with GlobalContrastNormalization
. Will update about ZCAWhitening
soon.