data=load('matlab_V21_ROI_11_3_2021.mat')
replaceimds=imageDatastore('C:\monika\vse\kratery')
replaceDataSource=groundTruthDataSource(replaceimds)
gTruth.DataSource=replaceDataSource
trainingDataTable=objectDetectorTrainingData(gTruth);
filenamesImages=trainingDataTable.imageFilename
tblBoxes=trainingDataTable(:,'krater')
imds=imageDatastore(filenamesImages, 'LabelSource','foldernames')
blds=boxLabelDatastore(tblBoxes)
numberofImages=length(imds.Files)
inputFileName=imds.Files{k};
fprintf('Checking %s\n', inputFileName);
grayImage=imread(inputFileName);
[rows,columns,numberofColorChannels]=size(grayImage);
if numberofColorChannels == 1
rgbImage=cat(3,grayImage, grayImage, grayImage);
inputImageSize =[224 224 3];
imageAugmenter=imageDataAugmenter(...
'RandRotation',[0 90],...
augmentedImdsTrain=augmentedImageDatastore(inputImageSize,imds,'DataAugmentation',imageAugmenter,'OutputSizeMode','randcrop');
featureLayer = 'activation_40_relu';
[anchorBoxes,meanIoU] = estimateAnchorBoxes(cds,numAnchors);
meanIoU = zeros([maxNumAnchors,1]);
anchorBoxes = cell(maxNumAnchors, 1);
[anchorBoxes{k},meanIoU(k)] = estimateAnchorBoxes(cds,k);
plot(1:maxNumAnchors,meanIoU,'-o')
xlabel("Number of Anchors")
title("Number of Anchors vs. Mean IoU")
anchorBoxes = [72,70; 99,96; 53,51];
lgraph = fasterRCNNLayers(inputImageSize,numClasses,anchorBoxes, ...
options = trainingOptions ( 'sgdm' , ...
'InitialLearnRate' , 1e-3, ...
detector = trainFasterRCNNObjectDetector (cds, lgraph, options, ...
'NegativeOverlapRange' , [0 0.3], ...
'PositiveOverlapRange' , [0.6 1]);