フィルターのクリア

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 Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by