instance segmentation based on polygon labeling?
4 views (last 30 days)
Show older comments
i am trying to train a mocel for instance segementation using mask Rcnn and i have labelled 1128 image using imqage labeller polygon labelling.
% % Load the ground truth labels using gTruth
load gTruth_1128.mat; % Load your gTruth data
data = gTruth;
classnames = gTruth.LabelDefinitions.Name
% Define the directory where your bounding box data is located and RGB
% image located
RGBDir = 'I:\PROJECTS\PhD Year 2\comparision of Image segmentation models\Data1\Dataset_2';
maskDir = 'I:\PROJECTS\PhD Year 2\comparision of Image segmentation models\Data1\Training\dataset'; % Replace with the directory where you want to save the files
numClasses = 4; % Number of classes
% load the groudtruth
A = 'traning_data.mat';
loadedData = load(A);
% Access the cell array data from the loaded data
cellArrayData = loadedData.combinedCellArray;% Replace 'yourVariableName' with the correct variable name
cellArrayData =cell2table(cellArrayData);
% % % Create a Image source for the dataset
imds = imageDatastore(RGBDir);
% Create a boxLabelDatastore
blds = boxLabelDatastore(cellArrayData(:,(2:3)));
% Create a custom ReadFcn for the maskimageDatastore
readFcn = @(filename) customReadFcn(filename);
% Create the imageDatastore with the custom ReadFcn
imds_mask = imageDatastore(maskDir, 'FileExtensions', {'.mat'}, 'ReadFcn', readFcn);
ds = combine(imds,blds);
ds = combine(ds,imds_mask);
preview(ds)
net = maskrcnn("resnet50-coco",classnames,InputSize=imageSize)
options = trainingOptions("sgdm", ...
InitialLearnRate=0.001, ...
LearnRateSchedule="piecewise", ...
LearnRateDropPeriod=1, ...
LearnRateDropFactor=0.95, ...
Plot="none", ...
Momentum=0.9, ...
MaxEpochs=10, ...
MiniBatchSize=20, ...
BatchNormalizationStatistics="moving", ...
ResetInputNormalization=false, ...
ExecutionEnvironment="gpu", ...
VerboseFrequency=50);
% TT = trainMaskRCNN(ds,net,options);
doTraining = true;
if doTraining
[net,info] = trainMaskRCNN(ds,net,options,FreezeSubNetwork="backbone");
modelDateTime = string(datetime("now",Format="yyyy-MM-dd-HH-mm-ss"));
save("trainedMaskRCNN-"+modelDateTime+".mat","net");
end
But i am iaving this error
Error using minibatchqueue
Invalid transform function defined on datastore.
mbqTrain = minibatchqueue(preprocessDS,4, ...
Caused by:
Index in position 3 exceeds array bounds. Index must not exceed 3.
can you help???
1 Comment
Joss Knight
on 25 Sep 2023
I'm not sure, it's possible there's a bug in your custom ReadFcn. Can you put a breakpoint in it and see if it's erroring?
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!