Effacer les filtres
Effacer les filtres

Error loading MNIST Images

23 vues (au cours des 30 derniers jours)
CHRISTINA
CHRISTINA le 29 Juin 2022
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 commentaires
Rohit Kulkarni
Rohit Kulkarni le 2 Juil 2022
is nntrain a matlab function?
CHRISTINA
CHRISTINA le 2 Juil 2022
Yes, it’s a deeplearn toolbox function.

Connectez-vous pour commenter.

Réponses (1)

Yatharth
Yatharth le 2 Juil 2022
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

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by