index is out of range for deletion - error while training semantic segmentation network
Show older comments
Hi,
I'm having an issue while training a UNET network for semantic segmentation on 3D nifti images.
I'm getting the following error:
>> network = trainNetwork(ds,lgraph,options);
Error using trainNetwork (line 165)
Matrix index is out of range for deletion.
Caused by:
Matrix index is out of range for deletion.
I'm not sure whether I built wrongly the network or that I didn't created the datastore for training as needed (I'm trying to load 3D nifti images in order to train a 2D semantic segmentation of each "slice" of the 3D image).
Could you please assist me with this issue?
below is my code:
%% Create U-Net Network with Custom Encoder-Decoder Depth
imageSize = [512 512 1];
numClasses = 2;
encoderDepth = 5;
lgraph = unetLayers(imageSize,numClasses,'EncoderDepth',encoderDepth);
dataSetDir = fullfile('c:\','Users','ya','Desktop','images_for_matlab_training');
imageDir = fullfile(dataSetDir,'images');
labelDir = fullfile(dataSetDir,'gTruth');
% Create an imageDatastore object to store the training images
imds = imageDatastore(imageDir,'FileExtensions','.gz','ReadFcn',@ReadNifti);
% Create an pixelDatastore object to store the training images
classNames = ["liver","background"];
labelIDs = [255 0];
pxds = pixelLabelDatastore(labelDir,classNames,labelIDs,'FileExtensions','.gz','ReadFcn',@ReadNifti);
% Create a datastore for training the network
ds = pixelLabelImageDatastore(imds,pxds);
% Set training options
options = trainingOptions('sgdm', ...
'InitialLearnRate',1e-3, ...
'MaxEpochs',3, ...
'MiniBatchSize',10, ...
'Plots','training-progress',...
'Verbose',1,...
'Shuffle','once');
% Train the network
network = trainNetwork(ds,lgraph,options);
Thanks!!
5 Comments
GABRIELZHU ZHU
on 6 Mar 2021
Hello, have you ever figured this problem out? I met the same problem as you. Could you please help me with this?
Mario Malic
on 6 Mar 2021
@GABRIELZHU ZHU this happens when you try to delete a row or column on a matrix which doesn't exist.
GABRIELZHU ZHU
on 7 Mar 2021
imds = imageDatastore(fullfile(home, 'MAT'),'FileExtensions','.mat','ReadFcn',@matRead);
classnames = 'LowCVR';
pixelLabelID = 1;
pxds = pixelLabelDatastore(fullfile(home, 'Label-3'), classnames, pixelLabelID, 'FileExtensions','.mat',...
'ReadFcn',@matRead);
pximds = pixelLabelImageDatastore(imds, pxds);
layers = [
imageInputLayer([128 128 18],"Name","imageinput")
convolution2dLayer([3 3],32,"Name","conv_1","Padding",[1 1 1 1])
reluLayer("Name","relu_1")
maxPooling2dLayer([2 2],"Name","maxpool_1","Stride",[2 2])
convolution2dLayer([3 3],32,"Name","conv_2","Padding",[1 1 1 1])
reluLayer("Name","relu_2")
maxPooling2dLayer([2 2],"Name","maxpool_2","Stride",[2 2])
transposedConv2dLayer([4 4],32,"Name","transposed-conv_1","Cropping",[1 1 1 1],"Stride",[2 2])
reluLayer("Name","relu_3")
transposedConv2dLayer([4 4],32,"Name","transposed-conv_2","Cropping",[1 1 1 1],"Stride",[2 2])
reluLayer("Name","relu_4")
convolution2dLayer([1 1],8,"Name","conv_3")
softmaxLayer("Name","softmax")
pixelClassificationLayer("Name","classoutput")];
opts = trainingOptions('adam', ...
'InitialLearnRate',1e-3, ...
'MaxEpochs',200, ...
'Plots','training-progress',...
'MiniBatchSize',16);
net = trainNetwork(pximds, layers, opts)
GABRIELZHU ZHU
on 7 Mar 2021
Thank you Mario. But I don't know where the step is.
Mario Malic
on 7 Mar 2021
It looks like it's inside your last line. The full error message should show where is the actual error. If error is somewhere within trainNetwork, then maybe your setup is wrong? I do not know anything about Deep Learning, so I can't help you. Verify that your inputs are correct, use debugging to find out where is the error.
Answers (0)
Categories
Find more on Semantic Segmentation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!