Reading MNIST : Error using fread Invalid file identifier. Use fopen to generate a valid file identifier.

1 次查看(过去 30 天)
Hello, l'm using MATLAB R2017b. l get error while reading MNIST dataset
Here is my function to read MNIST data
function [X_tr, X_te] = read_mnist(path_to_mnist)
D=10;
maxclasses=(0:D-1)';
[labels] = readidx(fullfile(path_to_mnist,'mnist','train-labels-idx1-ubyte'),60000,60000);
[xifres] = readidx(fullfile(path_to_mnist,'mnist','train-images-idx3-ubyte'),60000,60000);
X_tr = cell(D,1);
tmp32=zeros(32);
for d=1:D
sli=find(labels==maxclasses(d));
X_tr{d} = zeros(1024,length(sli));
for s=1:length(sli)
tmp=xifres(:,sli(s));
tmp32(3:30,3:30)=reshape(tmp,28,28);
X_tr{d}(:,s) = tmp32(:);
end
end
clear labels;
clear xifres;
[xifres] = readidx(fullfile(path_to_mnist,'mnist','t10k-images-idx3-ubyte'),10000,10000);
[labels] = readidx(fullfile(path_to_mnist,'mnist','t10k-labels-idx1-ubyte'),10000,10000);
X_te = cell(D,1);
for d=1:D
sli=find(labels==maxclasses(d));
X_te{d} = zeros(1024,length(sli));
for s=1:length(sli)
ind = 1+floor(rand(1)*length(sli)) ;
tmp=xifres(:,sli(ind)) ;
tmp32(3:30,3:30)=reshape(tmp,28,28);
X_te{d}(:,s) = tmp32(:);
end
end
end
l get error when calling this function :
path_to_mnist = '/home/mazari/Téléchargements/mnist';
[X_tr, X_te] = read_mnist(path_to_mnist);
error is :
Error using fread
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in readidx (line 6)
magic = fread(fid, 1, 'int32');
Error in read_mnist (line 6)
[labels] = readidx(fullfile(path_to_mnist,'mnist','train-labels-idx1-ubyte'),60000,60000);

回答(1 个)

Hamza Mehboob
Hamza Mehboob 2018-10-22
Usually when you unzip MNIST files they use a dot '.' instead of '-' for example t10k-images.idx3-ubyte, rename it manually to t10k-images-idx3-ubyte. It resolved my error.

类别

Help CenterFile Exchange 中查找有关 FPGA, ASIC, and SoC Development 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by