Invalid training data. For image, sequence-to-label, and feature classification tasks, responses must be categorical.
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Max Walliam
am 30 Nov. 2021
Kommentiert: Walter Roberson
am 2 Dez. 2021
Please help me out with this
Thanks in Advance
Below is the code
clc;
clear all;
imds = imageDatastore('/MATLAB Drive/HGG','IncludeSubfolders',true,'FileExtensions','.nii','LabelSource','foldernames');
imds.ReadFcn = @niftiread;
imds1 = transform(imds,@(x)imgaussfilt(x,2));
patchds = randomPatchExtractionDatastore(imds,imds1,[100 100]);
data = read(patchds);
layers = [
image3dInputLayer([240 240 155 1],"Name","image3dinput")
convolution3dLayer([3 3 3],32,"Name","conv3d_1","Padding","same")
reluLayer("Name","relu1")
batchNormalizationLayer("Name","batchnorm_1")
maxPooling3dLayer([5 5 5],"Name","maxpool3d_1","Padding","same")
convolution3dLayer([3 3 3],32,"Name","conv3d_2","Padding","same")
reluLayer("Name","relu2")
batchNormalizationLayer("Name","batchnorm_2")
maxPooling3dLayer([5 5 5],"Name","maxpool3d_2","Padding","same")
convolution3dLayer([3 3 3],32,"Name","conv3d_3","Padding","same")
reluLayer("Name","relu3")
convolution3dLayer([3 3 3],32,"Name","conv3d_4","Padding","same")
reluLayer("Name","relu4")
convolution3dLayer([3 3 3],32,"Name","conv3d_5","Padding","same")
reluLayer("Name","relu5")
maxPooling3dLayer([5 5 5],"Name","maxpool3d_3","Padding","same")
fullyConnectedLayer(2,"Name","fc_2")
reluLayer("Name","relu6")
dropoutLayer(0.5,"Name","drop6")
fullyConnectedLayer(10,"Name","fc_1")
reluLayer("Name","relu7")
dropoutLayer(0.5,"Name","drop7")
fullyConnectedLayer(2,"Name","fc_3")
softmaxLayer("Name","prob")
classificationLayer("Name","classoutput")];
options = trainingOptions('sgdm','MiniBatchSize',2,'MaxEpochs',2,'InitialLearnRate',1e-4,'Shuffle','every-epoch','Verbose',false,'Plots','training-progress');
net = trainNetwork(patchds,layers,options);
Error is
Error using trainNetwork (line 184)
Invalid training data. For image, sequence-to-label, and feature classification tasks, responses must be categorical.
Error in Ex (line 36)
net = trainNetwork(patchds,layers,options);
0 Kommentare
Akzeptierte Antwort
yanqi liu
am 1 Dez. 2021
Bearbeitet: yanqi liu
am 1 Dez. 2021
yes,sir,please use the follow code to test
imds1 = transform(imds,@(x)imgaussfilt(x,2));
%change to
imds1 = imageDatastore('MerchData','IncludeSubfolders',true,'LabelSource','foldernames','ReadFcn',@myreadfcn);
%and the function is
function J = myreadfcn(filename)
I = niftiread(filename);
J = imgaussfilt(I,2);
end
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!