Inputs and targets have different numbers of samples.
Show older comments
can you explain me why i could get this error ?
if true
Error using network/train (line 272)
Inputs and targets have different numbers of samples.
Error in ayobisa (line 49)
net = train(net,data_latih,target_latih);
end
this is my code:
if true
for loop = 1:5
image_folder = 'E:\23052018 Revisi\data sample2\train\t';
filenames = dir(fullfile(image_folder, '*.jpg'));
total_images = numel(filenames);
% temp = zeros(70,35);
data_latih = zeros(total_images,35);
for n = 1:total_images
jpgFilename = sprintf('%d.jpg', n);
full_name= fullfile(image_folder,jpgFilename);
I = imread(full_name);
%grayscaling
abu = rgb2gray(I);
%thresholding
level = graythresh(I);
im = imfill(I,'holes'); %Inpaint noisy areas
bw = im2bw(im,level);
%cropping
icrop = imgcrop(bw);
%resizing
isize = imgresize(icrop);
[r,c] = size(isize);
%image vector
%plotchar(isize);
%Reshaping
ishape = reshape(isize,[35,1]);
ishapet = ishape';
data_latih(n,:) = ishapet;
end
target_latih = zeros(total_images,1);
target_latih(1:17,:) = 1;
target_latih(18:33,:) = 2;
target_latih(34:40,:) = 3;
target_latih(41:75,:) = 4;
net = newff(data_latih,target_latih,[10 5],{'logsig','logsig'},'trainlm');
net.trainParam.epochs = 1000;
net.trainParam.goal = 1e-6;
net = train(net,data_latih,target_latih);
output = round(sim(net,data_latih));
save net.mat net
[m,n] = find(output==target_latih);
akurasi = sum(m)/total_images*100
end
end
Answers (1)
Greg Heath
on 14 Sep 2018
Edited: Greg Heath
on 23 Sep 2018
In general:
For I-dimensional input vectors and O-dimensional
target/output vectors
size(input) = [ I N ]
size(target) = [ O N ]
Hope this helps,
Thank you for formally accepting my answer
Greg
6 Comments
Annisa Mujahidah
on 14 Sep 2018
Greg Heath
on 16 Sep 2018
1. Find out WHY you have a different number of inputs and targets
2. If additional data is not available remove data so that the numbers are equal.
Hope this helps.
Thank you for formally accepting my answer
Greg
Walter Roberson
on 16 Sep 2018
The most common cause of this problem is that your input needs to be transposed. Each column needs to be a different sample. A lot of data arrives with each row being a different sample.
Desmond Molloy
on 22 Jan 2020
Does not work.
francisco caldeira
on 3 May 2020
for me
transpose()
didn't worked.
Walter Roberson
on 3 May 2020
What is size() of your input? What is size() of your target? What is class() of your input? What is class() of your target?
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!