Filter löschen
Filter löschen

Error using svmtrain (line 253) Y and TRAINING must have the same number of rows. Error in TRAIN>trai​n_push_Cal​lback (line 264) model = svmtrain(label,data,'-c 32 -g 0.03'); Error in gui_mainfcn (line 96) feval(varargin{:}); Error in TRAIN

1 Ansicht (letzte 30 Tage)
WHEN I RUN THE CODE NAMED TRAIN.m THE ABOVE ERRORS OCCURS..pLEASE HELP ME................

Antworten (2)

Sico
Sico am 29 Mär. 2017
Please help me, when I run the following code:
clc;
clear all;
% Load Datasets
Dataset = 'path of the folder';
Testset = 'path of the folder';
% we need to process the images first.
% Convert your images into grayscale
% Resize the images
width=100; height=100;
DataSet = cell([], 1);
for i=1:length(dir(fullfile(Dataset,'*.jpg')))
% Training set process
k = dir(fullfile(Dataset,'*.jpg'));
k = {k(~[k.isdir]).name};
for j=1:length(k)
tempImage = imread(horzcat(Dataset,filesep,k{j}));
imgInfo = imfinfo(horzcat(Dataset,filesep,k{j}));
% Image transformation
if strcmp(imgInfo.ColorType,'grayscale')
DataSet{j} = double(imresize(tempImage,[width height])); % array of images
else
DataSet{j} = double(imresize(rgb2gray(tempImage),[width height])); % array of images
end
end
end
TestSet = cell([], 1);
for i=1:length(dir(fullfile(Testset,'*.jpg')))
% Training set process
k = dir(fullfile(Testset,'*.jpg'));
k = {k(~[k.isdir]).name};
for j=1:length(k)
tempImage = imread(horzcat(Testset,filesep,k{j}));
imgInfo = imfinfo(horzcat(Testset,filesep,k{j}));
% Image transformation
if strcmp(imgInfo.ColorType,'grayscale')
TestSet{j} = double(imresize(tempImage,[width height])); % array of images
else
TestSet{j} = double(imresize(rgb2gray(tempImage),[width height])); % array of images
end
end
end
% Prepare class label for first run of svm
% I have arranged labels 1 & 2 as per my convenience.
% It is always better to label your images numerically
% Please note that for every image in our Dataset we need to provide one label.
% we have 30 images and we divided it into two label groups here.
train_label = zeros(size(30,1),1);
train_label(1:15,1) = 1; % 1 = Glaucoma
train_label(16:30,1) = 2; % 2 = Healthy
% Prepare numeric matrix for svmtrain
Training_Set=[];
for i=1:length(DataSet)
Training_Set_tmp = reshape(DataSet{i},1, 100*100);
Training_Set=[Training_Set;Training_Set_tmp];
end
Test_Set=[];
for j=1:length(TestSet)
Test_set_tmp = reshape(TestSet{j},1, 100*100);
Test_Set=[Test_Set;Test_set_tmp];
end
% Perform first run of svm
SVMStruct = svmtrain(Training_Set , train_label, 'kernel_function', 'linear');
Group = svmclassify(SVMStruct, Test_Set);
I am getting the following errors:
Error using svmtrain (line 254) Y and TRAINING must have the same number of rows.
Error in Test (line 78) SVMStruct = svmtrain(Training_Set , train_label, 'kernel_function', 'linear');
How can I go about them. Thank you in advance

thejas A V
thejas A V am 28 Mär. 2019
use same number of dataset rows equal number labels with row vector example pls refer to attachment

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by