-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for downloading MNIST data. Reorganize directories
- Loading branch information
Showing
10 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
data/ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#bin/bash | ||
|
||
url="http://yann.lecun.com/exdb/mnist" | ||
files="train-images-idx3-ubyte train-labels-idx1-ubyte t10k-images-idx3-ubyte t10k-labels-idx1-ubyte" | ||
dir="data" | ||
|
||
cd "$(dirname "$0")" | ||
|
||
if [ ! -d $dir ] | ||
then | ||
mkdir -p $dir | ||
fi | ||
|
||
for f in $files; do | ||
|
||
if [ -e $dir/$f ] | ||
then | ||
break | ||
fi | ||
|
||
wget -v -P $dir $url/$f.gz | ||
gunzip $dir/$f.gz | ||
|
||
done | ||
|
||
if [ ! -e $dir/train.bin ] | ||
then | ||
echo "Generating 16x16 data ..." | ||
octave -q generate_mnist_set_16.m | ||
fi | ||
|
||
if [ ! -e $dir/destin_train_32.bin ] | ||
then | ||
echo "Generating 32x32 data ..." | ||
octave -q generate_mnist_set_16.m | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function images = loadMNISTImages(filename) | ||
%loadMNISTImages returns a 28x28x[number of MNIST images] matrix containing | ||
%the raw MNIST images | ||
|
||
fp = fopen(filename, 'rb'); | ||
assert(fp ~= -1, ['Could not open ', filename, '']); | ||
|
||
magic = fread(fp, 1, 'int32', 0, 'ieee-be'); | ||
assert(magic == 2051, ['Bad magic number in ', filename, '']); | ||
|
||
numImages = fread(fp, 1, 'int32', 0, 'ieee-be'); | ||
numRows = fread(fp, 1, 'int32', 0, 'ieee-be'); | ||
numCols = fread(fp, 1, 'int32', 0, 'ieee-be'); | ||
|
||
images = fread(fp, inf, 'unsigned char'); | ||
images = reshape(images, numCols, numRows, numImages); | ||
images = permute(images,[2 1 3]); | ||
|
||
fclose(fp); | ||
|
||
% Reshape to #pixels x #examples | ||
images = reshape(images, size(images, 1) * size(images, 2), size(images, 3)); | ||
% Convert to double and rescale to [0,1] | ||
images = double(images) / 255; | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function labels = loadMNISTLabels(filename) | ||
%loadMNISTLabels returns a [number of MNIST images]x1 matrix containing | ||
%the labels for the MNIST images | ||
|
||
fp = fopen(filename, 'rb'); | ||
assert(fp ~= -1, ['Could not open ', filename, '']); | ||
|
||
magic = fread(fp, 1, 'int32', 0, 'ieee-be'); | ||
assert(magic == 2049, ['Bad magic number in ', filename, '']); | ||
|
||
numLabels = fread(fp, 1, 'int32', 0, 'ieee-be'); | ||
|
||
labels = fread(fp, inf, 'unsigned char'); | ||
|
||
assert(size(labels,1) == numLabels, 'Mismatch in label count'); | ||
|
||
fclose(fp); | ||
|
||
end |