forked from torch/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmnist.lua
51 lines (38 loc) · 1.38 KB
/
mnist.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
----------------------------------------------------------------------
-- This script downloads and loads the MNIST dataset
-- http://yann.lecun.com/exdb/mnist/
----------------------------------------------------------------------
print '==> downloading dataset'
-- Here we download dataset files.
-- Note: files were converted from their original LUSH format
-- to Torch's internal format.
-- The SVHN dataset contains 3 files:
-- + train: training data
-- + test: test data
tar = 'http://torch7.s3-website-us-east-1.amazonaws.com/data/mnist.t7.tgz'
if not paths.dirp('mnist.t7') then
os.execute('wget ' .. tar)
os.execute('tar xvf ' .. paths.basename(tar))
end
train_file = 'mnist.t7/train_32x32.t7'
test_file = 'mnist.t7/test_32x32.t7'
----------------------------------------------------------------------
print '==> loading dataset'
-- We load the dataset from disk, it's straightforward
trainData = torch.load(train_file,'ascii')
testData = torch.load(test_file,'ascii')
print('Training Data:')
print(trainData)
print()
print('Test Data:')
print(testData)
print()
----------------------------------------------------------------------
print '==> visualizing data'
-- Visualization is quite easy, using itorch.image().
if itorch then
print('training data:')
itorch.image(trainData.data[{ {1,256} }])
print('test data:')
itorch.image(testData.data[{ {1,256} }])
end