Error loading MNIST Images

조회 수: 23 (최근 30일)
CHRISTINA
CHRISTINA 2022년 6월 29일
답변: Yatharth 2022년 7월 2일
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!
  댓글 수: 2
Rohit Kulkarni
Rohit Kulkarni 2022년 7월 2일
is nntrain a matlab function?
CHRISTINA
CHRISTINA 2022년 7월 2일
Yes, it’s a deeplearn toolbox function.

댓글을 달려면 로그인하십시오.

답변 (1개)

Yatharth
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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by