-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathprepare_minist_GAN.m
56 lines (47 loc) · 1.7 KB
/
prepare_minist_GAN.m
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
52
53
54
55
56
%im_retrieval
opts.dataDir = './minist_data'; %define where to save data
files = {'train-images-idx3-ubyte', ...
'train-labels-idx1-ubyte', ...
't10k-images-idx3-ubyte', ...
't10k-labels-idx1-ubyte'} ;
if ~exist(opts.dataDir, 'dir')
mkdir(opts.dataDir) ;
end
for i=1:4
if ~exist(fullfile(opts.dataDir, files{i}), 'file')
url = sprintf('http://yann.lecun.com/exdb/mnist/%s.gz',files{i}) ;
fprintf('downloading %s\n', url) ;
gunzip(url, opts.dataDir) ;
end
end
f=fopen(fullfile(opts.dataDir, 'train-images-idx3-ubyte'),'r') ;
data1=fread(f,inf,'uint8');
fclose(f) ;
data1=permute(reshape(data1(17:end),28,28,60e3),[2 1 3]) ;
f=fopen(fullfile(opts.dataDir, 't10k-images-idx3-ubyte'),'r') ;
data2=fread(f,inf,'uint8');
fclose(f) ;
data2=permute(reshape(data2(17:end),28,28,10e3),[2 1 3]) ;
f=fopen(fullfile(opts.dataDir, 'train-labels-idx1-ubyte'),'r') ;
label1=fread(f,inf,'uint8');
fclose(f) ;
label1=double(label1(9:end)')+1 ;
f=fopen(fullfile(opts.dataDir, 't10k-labels-idx1-ubyte'),'r') ;
label2=fread(f,inf,'uint8');
fclose(f) ;
label2=double(label2(9:end)')+1 ;
data = cat(3,data1,data2);
data = reshape(data,28,28,1,[]);
label = cat(2,label1,label2);
imdb.images.set = [ones(1,60000),2*ones(1,10000)];
dataMean = mean(data(:,:,:,imdb.images.set == 1), 4);
imdb.images.data = data;
imdb.images.label = label;
imdb.meta.sets = {'train', 'val', 'test'} ;
imdb.images.data_mean = dataMean;
save('minist_data.mat','imdb','-v7.3');
%only 2
imdb.images.data = reshape(data(:,:,find(imdb.images.label ==3)),28,28,1,[]);
imdb.images.set = ones(1,numel(find(imdb.images.label ==3)));
imdb.images.label = ones(1,numel(find(imdb.images.label ==3)));
save('minist_data_only2.mat','imdb','-v7.3');