Azzera filtri
Azzera filtri

Error loading MNIST Images

24 visualizzazioni (ultimi 30 giorni)
CHRISTINA
CHRISTINA il 29 Giu 2022
Risposto: Yatharth il 2 Lug 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 Commenti
Rohit Kulkarni
Rohit Kulkarni il 2 Lug 2022
is nntrain a matlab function?
CHRISTINA
CHRISTINA il 2 Lug 2022
Yes, it’s a deeplearn toolbox function.

Accedi per commentare.

Risposte (1)

Yatharth
Yatharth il 2 Lug 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

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by