Skip to content

Instantly share code, notes, and snippets.

@guy4261
Last active August 29, 2015 14:21
Show Gist options
  • Save guy4261/3e959fec2c838bcc239a to your computer and use it in GitHub Desktop.
Save guy4261/3e959fec2c838bcc239a to your computer and use it in GitHub Desktop.
Normalize the mnist train data in the Torch tutorial
require('torch')
-- Find the average per image
train = torch.load('mnist.t7/train_32x32.t7', 'ascii')
train.data = train.data:type(torch.getdefaulttensortype())
BOUND = 60000 -- Perform on the full data
-- BOUND = 1 -- You can test on a single image as a beginning
for index = 1, BOUND do
cells = train.data[index][1]
avg = 0
mean = cells:mean()
std = cells:std()
cells = (cells - mean) / std
train.data[index][1] = cells
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment