koraykv / unsup

Some unsupervised learning modules using Torch
86 stars 36 forks source link

Memory boom when using `unsup.zca_whiten` #21

Closed russellfei closed 9 years ago

russellfei commented 9 years ago

Very excited that unsup module has zca_whitening function ( I used torch since May 2014, but never thought that whitening function is accessible 0_o)

Just leave out happy installation

Test code

requrie 'image'
require 'unsup'
-- actually I used these lines before
-- im.image.lena()
-- im = image.scale(image.lena(),128,128)
im = image.scale(image.lena(),32,32)
out = unsup.zca_whitening(im)
image.display(out)

Error

soumith commented 9 years ago

@russellfei maybe you can contribute your "better" whitening function to unsup :)

russellfei commented 9 years ago

@soumith I'm NOT SURE about my implementation, but what I wrote is guided by the formula on UFLDL.

In addition, I came across memory boom when wrote my script, the key point is the view of input data structure, i.e., the dimension you want to remove correlations: take a tensor bxdxhxw as an example: if we remove the correlations between h dim, then even there's a large number of hxw; if we want to remove the correlations between hxw (flatten tensor), the output is devastating.

Could you spare a minute to check my code? just ~20 short lines. I can mail it to you. ( sorry, I have no access to gist currently, otherwise that will be perfect share of scripts)

nagadomi commented 9 years ago

ZCA/PCA allocates NxN matrix for variance-covariance matrix. When input is 512x512 = 262144px, torch requires 262144262144sizeof(float) = 256GB memory.

russellfei commented 9 years ago

@nagadomi, According to what you said, PCA/ZCA_whitening removes correlation between pixels?

russellfei commented 9 years ago

All right, it seems that this zca_whitening is limited to small patches or gray scale images, and my explanation above is quite specific about input format, i.e., 4-D tensors. The general zca_whiten function is correct but limited to small image patches and gray scale images. Thanks @nagadomi I figured out this memory boom.

This issue should be over. Thanks all!