1

我使用 Matlab 进行 OCR 项目,我发现有一个名为 MNIST 手写数字数据库的字符示例数据库。我下载了一个名为train-images.idx3-ubyte 但我不知道如何使用它的文件,有人知道如何使用这个文件吗?

4

3 回答 3

2

您可以使用斯坦福的mnistHelper 函数

作为如何使用这些功能的示例,您可以使用以下代码检查图像和标签:

% Change the filenames if you have saved the files under different names
% On some platforms, the files might be saved as 
% train-images.idx3-ubyte / train-labels.idx1-ubyte

images = loadMNISTImages('train-images-idx3-ubyte');
labels = loadMNISTLabels('train-labels-idx1-ubyte');

% We are using display_network from the autoencoder code

display_network(images(:,1:100)); % Show the first 100 images
disp(labels(1:10));
于 2014-10-12T12:10:09.893 回答
2

您从 MNIST 数据库下载的那些文件是二进制文件。您可以在 MNIST 网站上找到它们的格式:http: //yann.lecun.com/exdb/mnist/

在 MATLAB 中使用fopenfclosefreadfseek等低级文件 I/O函数按照其格式读取文件。

您也可以尝试使用FileExchange中的 readMNIST 函数。我对它没有任何经验,一些用户似乎对它有一些问题,但你可以看到代码并调试它。

于 2012-08-31T19:36:17.513 回答
0
You Can read MNISTImages like this-

trlblid = fopen('train-labels.idx1-ubyte');    
trimgid = fopen('train-images.idx3-ubyte');    
tslblid = fopen('t10k-labels.idx1-ubyte');    
tsimgid = fopen('t10k-images.idx3-ubyte');    

% read train labels    
fread(trlblid, 4);    
numtrlbls = toint(fread(trlblid, 4));    
trainlabels = fread(trlblid, numtrlbls);    

% read train data    
fread(trimgid, 4);    
numtrimg = toint(fread(trimgid, 4));    
trimgh = toint(fread(trimgid, 4));    
trimgw = toint(fread(trimgid, 4));    
trainimages = permute(reshape(fread(trimgid,trimgh*trimgw*numtrimg),trimgh,trimgw,numtrimg), [2 1 3]);    

% read test labels    
fread(tslblid, 4);    
numtslbls = toint(fread(tslblid, 4));    
testlabels = fread(tslblid, numtslbls);    

% read test data    
fread(tsimgid, 4);    
numtsimg = toint(fread(tsimgid, 4));    
tsimgh = toint(fread(tsimgid, 4));    
tsimgw = toint(fread(tsimgid, 4));    
testimages = permute(reshape(fread(tsimgid, tsimgh*tsimgw*numtsimg),tsimgh,tsimgw,numtsimg), [2 1 3]);    
于 2017-03-01T05:00:40.110 回答