Inputs and targets have different numbers of samples.

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

Respuestas (1)

Greg Heath
Greg Heath el 14 de Sept. de 2018
Editada: Greg Heath el 23 de Sept. de 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 comentarios

so can you please tell me what should i do to fix this problem ? im sorry im a matlab newbie ><
Greg Heath
Greg Heath el 16 de Sept. de 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
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.
Does not work.
for me
transpose()
didn't worked.
What is size() of your input? What is size() of your target? What is class() of your input? What is class() of your target?

Iniciar sesión para comentar.

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 13 de Sept. de 2018

Comentada:

el 3 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by