Having a problem training & Testing the Neural network
3 views (last 30 days)
Show older comments
Lameck Amugongo
on 15 Jun 2014
Commented: Lameck Amugongo
on 16 Jun 2014
I have a group of images in a folder and i would like to train the neural network using the features extracted using the gray co-occurrence matrix.
function neuralNetwork(img)
%NN Summary of this function goes here
% Detailed explanation goes here
files = dir('*.png');
hist = [];
net = lvqnet(10);
for n = 1 : length(files)
file = imread(files(n).name);
[rows columns numberOfColorChannels] = size(file);
%%Check if the im loaded is a grayscale image
if numberOfColorChannels > 1
%%Coverting to grayscale & get the co-occurrence matrix
F = graycomatrix(rgb2gray(file));
else
F= graycomatrix(file); %get co-occurrence matrix
end
hist = [hist, imhist(F)]; %#ok
end
% Create a Self-Organizing Map
dimension1 = 10;
dimension2 = 10;
net = selforgmap([dimension1 dimension2]);
% Train the Network
[net,tr] = train(net,hist); % The error is here
% Test the Network
outputs = net(hist);
% View the Network
view(net)
I am getting the following error:
>> neuralNetwork('C:\Users\Lameck\Documents\MATLAB\Project\TrainingSet\0001.png');
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> learnsomb>apply at 122
a2 = neighborhood * a + a;
Error in ==> trainbu>train_network at 206
[dw,IWLS{i,j}] = fcn.apply(net.IW{i,j}, ...
Error in ==> trainbu at 103
[net,tr] = train_network(net,tr,data,fcns,param);
Error in ==> network.train at 107
[net,tr] = feval(net.trainFcn,net,X,T,Xi,Ai,EW,net.trainParam);
Error in ==> neuralNetwork at 26
som = train(som, hist);
0 Comments
Accepted Answer
Greg Heath
on 16 Jun 2014
train takes 3 inputs, not 2.
help train
doc train
Hope this helps.
Thank you for formally accepting my answer
Greg
More Answers (0)
See Also
Categories
Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!