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

4 次查看(过去 30 天)
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);

采纳的回答

yanqi liu
yanqi liu 2021-12-1
编辑:yanqi liu 2021-12-1
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by