Invalid training data. For image, sequence-to-label, and feature classification tasks, responses must be categorical.

19 vues (au cours des 30 derniers jours)
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);

Réponse acceptée

yanqi liu
yanqi liu le 1 Déc 2021
Modifié(e) : yanqi liu le 1 Déc 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 commentaires
Max Walliam
Max Walliam le 1 Déc 2021
Files must be a valid string scalar, character vector, cell array of character vectors, string array, or a
matlab.io.datastore.FileSet.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by