Error loading MNIST Images
18 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm new to Matlab in general, and I'm trying to setup a multilayer perceptron, for the images of the MNIST Database classification. (Handwriting Recognition)
I'm using the loadMNISTImages function, to load the images to my network, but I get an error in nntrain function that my train_set must be a float.
How can I make it work? Here is my code:
clear;clc; format compact;
train_set = loadMNISTImages('train-images.idx3-ubyte', 10000);
train_label = loadMNISTLabels('train-labels.idx1-ubyte', 10000);
test_set = loadMNISTImages('t10k-images.idx3-ubyte', 1000);
test_label = loadMNISTLabels('t10k-labels.idx1-ubyte', 1000);
%train_set = train_set.reshape(train_set.shape[0], 28 ,28 ,1);
train_label = double(train_label);
%test_set = double(test_set)'/255;
test_label = double(test_label);
%%%%%%%%%%%%%%
% Train MLP %
%%%%%%%%%%%%%%
nhid = 40; %Nr. of hidden nodes
nn = nnsetup([784 14 10]); %Specify MLP architecture
nn.activation_function = 'tanh_opt'; %Set hidden neuron activstion function
nn.learningRate = 0.15; %set learning rate
%nn.learningRate = 1;
%nn.learningRate = 1.5;
nn.momentum = 0.9; %set momentum
nn.weightPenaltyL2 = 1e-4; %set regularization parameter λ
nn.dropoutFraction = 0.5;
nn.output = 'softmax';
opts.batchsize = 100; %specifies version of batch backpropagation
opts.numepochs = 100; %set number of epochs
opts.plot = 1; %Show plot of training error vs epochs
[nn, L] = nntrain(nn, train_set, train_label, opts);
[er1, bad] = nntest(nn, test_set, test_label);
[er2, bad] = nntest(nn, train_set, train_label);
disp(['Classification accuracy on training set: ',num2str((1-er1)*100),'%']);
disp(['Classification accuracy on test set: ',num2str((1-er2)*100),'%']);
Thank you in advance!
回答(1 个)
Yatharth
2022-7-2
Hey I am not sure about your approch of creating a Neural Network, you can follow up this approch mentioned in the documentation for the MNIST Data Set . Alternatively if you want to build your own neural network you can follow this tutorial
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!