Unable to use a value of type DAGNetwork as an index.

3 views (last 30 days)
I have build the UNET model, the training was interrupted,Now I am trying to resume the training from the last checkpoint, but i got the Error "Unable to use a value of type DAGNetwork as an index."
Here is my code, can someone tell me why i got this error.
clear all
close all
load('net_checkpoint__226644__2021_07_08__16_18_25.mat','net')
matlabpath = 'E:\My project';
data = fullfile(matlabpath,'ImageDatasetforPixelLabelDataSeries6-21');
data1 = fullfile(matlabpath,'PixelLabelDataSeries6-21');
imds = imageDatastore(data,'IncludeSubfolders',true,'LabelSource','foldernames');
classes = ["CatheterMarkerVessel" "Background"];
pixelLabelIDs = [0 1];
pxds = pixelLabelDatastore(data1, classes ,pixelLabelIDs);
trainingdata = pixelLabelImageSource(imds,pxds);
tbl = countEachLabel(trainingdata);
imageSize = [1024 1024 1];
numClasses = numel(classes);
lgraph = unetLayers(imageSize,numClasses,'EncoderDepth',5);
%% Data Augmentation
augmenter = imageDataAugmenter('RandXReflection',true,'RandYReflection',true);
pximds = pixelLabelImageDatastore(imds,pxds,'DataAugmentation', augmenter);
%% Training
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.0001, ...
'Momentum',0.99, ...
'MiniBatchSize',1, ...
'MaxEpochs',300, ...
'Plots','training-progress', ...
'CheckpointPath','E:\My Project');
training = trainNetwork(pximds,lgraph(net),options);

Answers (1)

Yomna Genina
Yomna Genina on 19 Aug 2021
There is no need to create a new layer graph as you already saved the last checkpoint network in the net variable which could be used directly to resume training.
Instead of the last line of code, you could do the following:
training = trainNetwork(pximds,layerGraph(net),options); % convert DAGNetwork to layer graph and resume training

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!