From bc52bd699bfc22a7e56dbd6266c1116a5b7f0105 Mon Sep 17 00:00:00 2001 From: v-h Date: Mon, 16 Jan 2023 17:52:55 +0100 Subject: [PATCH] remove mirror from augmentation for step three --- RCNN_for_traficsigns.m | 29 +------------- RCNN_for_traficsigns_stepthree.m | 47 ++--------------------- augmentData_stepthree.m | 13 +------ test_stepthree_for.m | 66 ++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 83 deletions(-) create mode 100644 test_stepthree_for.m diff --git a/RCNN_for_traficsigns.m b/RCNN_for_traficsigns.m index 69043b5..eedc041 100644 --- a/RCNN_for_traficsigns.m +++ b/RCNN_for_traficsigns.m @@ -207,31 +207,4 @@ grid on title(sprintf('Average Precision = %.2f', ap)) -% ----- Helper functions - -% function data = augmentData(data) -% % Randomly flip images and bounding boxes horizontally. -% tform = randomAffine2d('XReflection',true); -% sz = size(data{1}); -% rout = affineOutputView(sz,tform); -% data{1} = imwarp(data{1},tform,'OutputView',rout); -% -% % Sanitize box data, if needed. -% data{2} = helperSanitizeBoxes(data{2}, sz); -% -% % Warp boxes. -% data{2} = bboxwarp(data{2},tform,rout); -% end -% -% function data = preprocessData(data,targetSize) -% % Resize image and bounding boxes to targetSize. -% sz = size(data{1},[1 2]); -% scale = targetSize(1:2)./sz; -% data{1} = imresize(data{1},targetSize(1:2)); -% -% % Sanitize box data, if needed. -% data{2} = helperSanitizeBoxes(data{2}, sz); -% -% % Resize boxes. -% data{2} = bboxresize(data{2},scale); -% end + diff --git a/RCNN_for_traficsigns_stepthree.m b/RCNN_for_traficsigns_stepthree.m index f6c71c7..be1cfab 100644 --- a/RCNN_for_traficsigns_stepthree.m +++ b/RCNN_for_traficsigns_stepthree.m @@ -33,13 +33,12 @@ % adjustable parameters % - if there is no trained net, it can be trained with this script: % set doTraining to true -% - the training can use augmentation or not: -% set doAugmentation accordingly + close all; clear; -doTraining = false; +doTraining = true; % first we need the data... dataDir = 'Picturedata'; % Destination-Folder for provided (img) Data @@ -103,17 +102,6 @@ inputSize = [224 224 3]; preprocessedTrainingData = transform(trainingData, @(data)preprocessData(data,inputSize)); % Achtung: dieser DS wird nur zur Ermittlung der BoundingBoxes verwendet -% display one of the training images and box labels. -while 1==0 %hasdata(preprocessedTrainingData) - data = read(preprocessedTrainingData); - I = data{1}; - bbox = data{2}; - annotatedImage = insertShape(I,'Rectangle',bbox); - annotatedImage = imresize(annotatedImage,4); % nur fuer Darstellung - figure(1) - imshow(annotatedImage) - pause(0.100) -end % Auswahl der anchor boxes % Infos dazu: https://de.mathworks.com/help/vision/ug/estimate-anchor-boxes-from-training-data.html @@ -164,7 +152,7 @@ I = imresize(I,inputSize(1:2)); [bboxes,scores] = detect(detector,I); % Display the results. -sfigTitle = "" +sfigTitle = ""; if height(bboxes) > 0 I = insertObjectAnnotation(I,'rectangle',bboxes,scores); sfigTitle = "Detected"; @@ -198,31 +186,4 @@ grid on title(sprintf('Average Precision = %.2f', ap)) -% ----- Helper functions - -% function data = augmentData(data) -% % Randomly flip images and bounding boxes horizontally. -% tform = randomAffine2d('XReflection',true); -% sz = size(data{1}); -% rout = affineOutputView(sz,tform); -% data{1} = imwarp(data{1},tform,'OutputView',rout); -% -% % Sanitize box data, if needed. -% data{2} = helperSanitizeBoxes(data{2}, sz); -% -% % Warp boxes. -% data{2} = bboxwarp(data{2},tform,rout); -% end -% -% function data = preprocessData(data,targetSize) -% % Resize image and bounding boxes to targetSize. -% sz = size(data{1},[1 2]); -% scale = targetSize(1:2)./sz; -% data{1} = imresize(data{1},targetSize(1:2)); -% -% % Sanitize box data, if needed. -% data{2} = helperSanitizeBoxes(data{2}, sz); -% -% % Resize boxes. -% data{2} = bboxresize(data{2},scale); -% end + diff --git a/augmentData_stepthree.m b/augmentData_stepthree.m index fcfdd49..e530499 100644 --- a/augmentData_stepthree.m +++ b/augmentData_stepthree.m @@ -1,8 +1,4 @@ function data = augmentData_stepthree(data) -% Randomly flip images and bounding boxes horizontally. -tform = randomAffine2d('XReflection',true); -sz = size(data{1}); -rout = affineOutputView(sz,tform); % jitter data{1} = jitterColorHSV(data{1},... @@ -11,11 +7,4 @@ data{1} = jitterColorHSV(data{1},... Saturation=0.1,... Brightness=0.2); -data{1} = imwarp(data{1},tform,'OutputView',rout); - -% Sanitize box data, if needed. -data{2} = helperSanitizeBoxes(data{2}, sz); - -% Warp boxes. -data{2} = bboxwarp(data{2},tform,rout); -end \ No newline at end of file +end diff --git a/test_stepthree_for.m b/test_stepthree_for.m new file mode 100644 index 0000000..34a3dda --- /dev/null +++ b/test_stepthree_for.m @@ -0,0 +1,66 @@ +% Testscript um ein Bild aus den Daten durch das RCCN_NET mit direkter +% klassifizierung laufen zu lassen + +close all; +clear; + +%die netze mit besserer Erkennung _2 +RCCN_NET = 'netDetectorResNet50_stepthree.mat'; +inputSize = [224 224 3]; + +% first we need the data... +dataDir = 'Picturedata'; % Destination-Folder for provided (img) Data +zippedDataFile = 'PicturesResizedLabelsResizedSignsCutted.zip'; %Data provided by TA +grDataFile = 'signDatasetGroundTruth.mat'; +func_setupData(dataDir, zippedDataFile, grDataFile); + +%load data +grdata = load(grDataFile); +traficSignDataset = grdata.DataSet; + +%Random Index +%shuffledIndices = randperm(height(traficSignDataset)); +%testindx = shuffledIndices(1) +for testindx = 126:200 +%testindx = 125; + +% Bild einlesen +imgname = traficSignDataset.imageFilename{testindx} +I = imresize(imread(imgname),inputSize(1:2)); + +%RCCN-Detector laden +pretrained = load(RCCN_NET); +detector = pretrained.detector; + +[bbox, score, label] = detect(detector, I); + + +sfigTitle = ""; +bdetected = height(bbox) > 0; +if bdetected + I = insertObjectAnnotation(I,'rectangle',bbox,score); + sfigTitle = "Detected" + string(label); + return; +else + sfigTitle = "Not Detected"; +end + +end %end forschleife testindex + +figure; +imshow(I); +annotation('textbox', [0.5, 0.2, 0.1, 0.1], 'String', sfigTitle) + +%ggf. bild zuschneiden +if bdetected + icrop = imcrop(I , bbox); + figure; + imshow(icrop); + +end + + + + + + \ No newline at end of file