index is out of range for deletion - error while training semantic segmentation network

1 view (last 30 days)
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
Mario Malic
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.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!