create a semantic segmentation algorithm using net = inceptionresnetv2 with imdstest = imagedatastore() and pxdstest = pixellabeldatastore() in matlab

To create a semantic segmentation algorithm using InceptionResNetv2 in MATLAB, you can follow these steps:

  1. Load the pre-trained InceptionResNetv2 network using the "inceptionresnetv2" function in MATLAB.
main.m
net = inceptionresnetv2;
25 chars
2 lines
  1. Load your image dataset and pixel label dataset using the "imagedatastore" and "pixelLabelDatastore" functions respectively.
main.m
imdsTest = imageDatastore(testImageDir);
pxdsTest = pixelLabelDatastore(testLabelDir, classNames, pixelLabelID);
113 chars
3 lines
  1. Create the semantic segmentation network using the "deeplabv3plusLayers" function. Pass the loaded network and the number of output classes as arguments.
main.m
numClasses = numel(classNames);
lgraph = deeplabv3plusLayers(size(inputSize),numClasses,"inceptionresnetv2");
110 chars
3 lines
  1. Create a test dataset using the "pixelLabelImageDatastore" function. This function combines the image and pixel label datastores into a single datastore.
main.m
pximdsTest = pixelLabelImageDatastore(imdsTest,pxdsTest);
58 chars
2 lines
  1. Create a test function to evaluate the trained network on the test dataset.
main.m
function [metrics,confmat] = evaluateNetwork(net,ds,classNames)
threshold = 0.5; % Change this value to the desired threshold
pxdsResults = semanticseg(ds,net,"Threshold",threshold,"MiniBatchSize",4);
metrics = evaluateSemanticSegmentation(pxdsResults,ds,"Verbose",false);
confmat = metrics.ConfusionMatrix;
plotConfusionMatrix(confmat,classNames);
end
353 chars
8 lines
  1. Train the network using the "trainNetwork" function. Pass the input, output, and training options arguments.
main.m
options = trainingOptions("sgdm","ExecutionEnvironment","auto","LearnRateSchedule","piecewise","LearnRateDropFactor",0.1,"LearnRateDropPeriod",10,"MaxEpochs",20,"MiniBatchSize",4,"Shuffle","every-epoch","VerboseFrequency",1,"Plots","training-progress");

net = trainNetwork(pximdsTrain,lgraph,options);
303 chars
4 lines
  1. Evaluate the trained network on the test dataset using the test function created earlier.
main.m
[metrics,confmat] = evaluateNetwork(net,pximdsTest,classNames);
64 chars
2 lines

This should result in a semantic segmentation algorithm created using InceptionResNetv2 in MATLAB.

gistlibby LogSnag