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);
댓글 수: 0
채택된 답변
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
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!