Skip to content

Commit 2bd3100

Browse files
committed
Initial Project added
1 parent 5196684 commit 2bd3100

File tree

84 files changed

+1104
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1104
-2
lines changed

Deeplearningforobjectdetection.prj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<MATLABProject xmlns="http://www.mathworks.com/MATLABProjectFile" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"/>

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
# deep-learning-for-object-detection-yolov2
2-
Code Files for "Deep Learning for Object Detection" video series
1+
# Deep Learning for Object Detection Series
2+
3+
Copyright 2019-2020 The MathWorks, Inc.
4+
5+
## Introduction
6+
7+
This repository consists of the code files for the following videos;
8+
9+
1. Data Preprocessing for Deep Learning
10+
2. Design and Train a YOLOv2 Network in MATLAB
11+
3. Import Pretrained Deep Learning Networks into MATLAB
12+
4. Deploy YOLOv2 to an NVIDIA Jetson
13+
14+
## SetUp
15+
16+
1. Download all the files and folders from this repository.
17+
2. Run ***addFilestoPath.m*** to add all folders and files to the current path
18+
3. Run ***adjustGroundTruthPaths.m*** to change the ground truth data objects' source path if path issues occur
19+
20+
## Folder Structure
21+
22+
1. **Codefiles** folder consists of matlab code files for each of the videos
23+
2. **Utilities** folder consists of .mat files required for uplaoding pre trained content
24+
25+
26+
for any questions feel free to email at roboticsarena@mathworks.com

Utilities/ACFDetectorTraining.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function [detector] = ACFDetectorTraining(gTruth,labelName)
2+
3+
% Copyright 2019 The MathWorks, Inc
4+
% Inputs:
5+
% gTruth: Ground Truth Data Object
6+
% labelName: name of the label as a string
7+
%
8+
%
9+
% Outputs:
10+
% detector: ACF Object Detector data object
11+
%---------------------------------------------------------------------------------
12+
13+
gTruthSpecificLabel = selectLabels(gTruth,labelName);
14+
15+
if ~isfolder(fullfile('TrainingData'))
16+
mkdir TrainingData
17+
end
18+
19+
trainingData = objectDetectorTrainingData(gTruthSpecificLabel,'SamplingFactor',1,...
20+
'WriteLocation','TrainingData');
21+
22+
detector = trainACFObjectDetector(trainingData,'NumStages',5);
23+
end
24+

Utilities/Readme.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
3+
###### customAutomationClasses
4+
This folder contains the class files for the 4 custom detectors, files form this folder will get copied over to the +vision/+labeler folder when dataPreProcessing.mlx is run
5+
6+
7+
###### detectorsForCustomAutomation
8+
This folder contains trained ACF object detectors for each of the 4 custom automation algorithms
9+
10+
11+
12+
`ACFDetectorTraining.m` : Helper function to train an ACF detector, inputs are the groundTruth object and a labelName as a string
13+
14+
`detectorTinyYolo2.mat` : tiny yolov2 onnx model retrained on the custom objects
15+
16+
`detectorYoloV2.mat` : trained yolo v2 network, designed in MATLAB
17+
18+
`gTruth2XML.m` : Optional MATLAB code file to convert groundTruth object data to an xml file
19+
20+
`gTruthResizedTest.mat` : ground truth exported from the labeler app for the resized images of test data
21+
22+
`gTruthResizedTrain.mat` : ground truth exported from the labeler app for the resized images of train data
23+
24+
`gTruthResizedVald.mat` : ground truth exported from the labeler app for the resized images of validation data
25+
26+
`groundTruthLabelingSessionRoboSubResizedTrain.mat` : Labeled ground truth session for all the data in the trainResized folder to be downloaded from : https://drive.google.com/open?id=1bhohhPoZy03ffbM_rl8ZUPSvJ5py8rM-
27+
28+
`importedTinyYoloLayers.mat` : tinyYOLO network exported from the deep network designer app after redesigning it according to the new image size and objects
29+
30+
`model.onnx` : tinyYOLOV2 onnx model downloaded from onnx model zoo : https://github.com/onnx/models
31+
32+
33+
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
classdef greenBuoyACFDetector < vision.labeler.AutomationAlgorithm
2+
3+
properties(Constant)
4+
5+
% Name: Give a name for your algorithm.
6+
Name = 'Green Buoy ACF Detector';
7+
8+
% Description: Provide a one-line description for your algorithm.
9+
Description = 'Use this algorithm to automatically label Green Buoys for a dataset from RoboSub';
10+
11+
% UserDirections: Provide a set of directions that are displayed
12+
% when this algorithm is invoked. The directions
13+
% are to be provided as a cell array of character
14+
% vectors, with each element of the cell array
15+
% representing a step in the list of directions.
16+
UserDirections = {...
17+
['Automation algorithms are a way to automate manual labeling ' ...
18+
'tasks.'], ...
19+
['ROI Selection: This algorithm will automatically annotate'...
20+
'images with rectuangular labels. Prior to Automation create a for'...
21+
'the Navigation Gate ensure that its type is set to rectangle.'], ...
22+
['Run: Press RUN to run the automation algorithm. '], ...
23+
['Review and Modify: Review automated labels over the interval ', ...
24+
'using playback controls. Modify/delete/add ROIs that were not ' ...
25+
'satisfactorily automated at this stage. If the results are ' ...
26+
'satisfactory, click Accept to accept the automated labels.'], ...
27+
['Change Settings and Rerun: If automated results are not ' ...
28+
'satisfactory, you can try to re-run the algorithm with ' ...
29+
'a different ScoreThreshold value, the defalut is set to 70.'...
30+
'In order to do so, click Undo Run to undo ' ...
31+
'current automation run, click Settings and make changes to ' ...
32+
'Settings, and press Run again.'], ...
33+
['Accept/Cancel: If results of automation are satisfactory, ' ...
34+
'click Accept to accept all automated labels and return to ' ...
35+
'manual labeling. If results of automation are not ' ...
36+
'satisfactory, click Cancel to return to manual labeling ' ...
37+
'without saving automated labels.']};
38+
end
39+
40+
%---------------------------------------------------------------------
41+
% Step 2: Define properties to be used during the algorithm. These are
42+
% user-defined properties that can be defined to manage algorithm
43+
% execution.
44+
properties
45+
%SelectedLabelName Selected label name
46+
% Name of selected label. Vehicles detected by the algorithm will
47+
% be assigned this variable name.
48+
SelectedLabelName
49+
50+
%Detector Detector
51+
% Pre-trained greenBuoy detector, an object of class
52+
% acfObjectDetector.
53+
greenBuoyDetector
54+
55+
%Score Threshold
56+
ScoreThreshold = 70;
57+
58+
59+
end
60+
61+
%----------------------------------------------------------------------
62+
% Setup
63+
%----------------------------------------------------------------------
64+
methods
65+
66+
function flag = supportsReverseAutomation(~)
67+
flag = false;
68+
end
69+
70+
function isValid = checkLabelDefinition(~, labelDef)
71+
72+
% Only Rectangular ROI Label definitions are valid for the
73+
% greenBuoy Detector.
74+
isValid = labelDef.Type==labelType.Rectangle;
75+
end
76+
77+
function isReady = checkSetup(algObj)
78+
79+
% Is there one selected ROI Label definition to automate.
80+
isReady = ~isempty(algObj.SelectedLabelDefinitions);
81+
end
82+
function settingsDialog(algObj)
83+
84+
prompt = {'Set the threshold value from 1-100'};
85+
dlgTitle = 'Threshold';
86+
dims = [1 35];
87+
defInput = {num2str(algObj.ScoreThreshold)};
88+
algObj.ScoreThreshold = str2double(inputdlg(prompt,dlgTitle,dims,defInput));
89+
90+
end
91+
end
92+
%----------------------------------------------------------------------
93+
% Execution
94+
%----------------------------------------------------------------------
95+
96+
methods
97+
function initialize(algObj,~)
98+
99+
% Store the name of the selected label definition. Use this
100+
% name to label the detected vehicles.
101+
algObj.SelectedLabelName = algObj.SelectedLabelDefinitions.Name;
102+
103+
% Initialize the vehicle detector with a pre-trained model.
104+
105+
data = load('greenBuoyDetector.mat');
106+
algObj.greenBuoyDetector = data.greenBuoyDetector;
107+
end
108+
109+
110+
function autoLabels = run(algObj, I)
111+
112+
autoLabels = [];
113+
114+
% Detect vehicles using the initialized vehicle detector.
115+
[bboxes, scores] = detect(algObj.greenBuoyDetector, I,...
116+
'SelectStrongest', true);
117+
118+
[selectedBbox, selectedScore] = selectStrongestBbox(bboxes, scores);
119+
120+
% Reject detections with detection score lower than
121+
% ScoreThreshold.
122+
detectionsToKeepIdx = (selectedScore > algObj.ScoreThreshold);
123+
selectedBbox = selectedBbox(detectionsToKeepIdx,:);
124+
125+
if ~isempty(selectedBbox)
126+
% Add automated labels at bounding box locations detected
127+
% by the vehicle detector, of type Rectangle having name of
128+
% the selected label.
129+
autoLabels.Name = algObj.SelectedLabelName;
130+
autoLabels.Type = labelType.Rectangle;
131+
autoLabels.Position = selectedBbox;
132+
else
133+
autoLabels = [];
134+
end
135+
end
136+
end
137+
138+
139+
end
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
classdef navGateACFDetector < vision.labeler.AutomationAlgorithm
2+
3+
properties(Constant)
4+
5+
% Name: Give a name for your algorithm.
6+
Name = 'Navigation Gate ACF Detector';
7+
8+
% Description: Provide a one-line description for your algorithm.
9+
Description = 'Use this algorithm to automatically label Navigation Gates for a dataset from RoboSub';
10+
11+
% UserDirections: Provide a set of directions that are displayed
12+
% when this algorithm is invoked. The directions
13+
% are to be provided as a cell array of character
14+
% vectors, with each element of the cell array
15+
% representing a step in the list of directions.
16+
UserDirections = {...
17+
['Automation algorithms are a way to automate manual labeling ' ...
18+
'tasks.'], ...
19+
['ROI Selection: This algorithm will automatically annotate'...
20+
'images with rectuangular labels. Prior to Automation create a for'...
21+
'the Navigation Gate ensure that its type is set to rectangle.'], ...
22+
['Run: Press RUN to run the automation algorithm. '], ...
23+
['Review and Modify: Review automated labels over the interval ', ...
24+
'using playback controls. Modify/delete/add ROIs that were not ' ...
25+
'satisfactorily automated at this stage. If the results are ' ...
26+
'satisfactory, click Accept to accept the automated labels.'], ...
27+
['Change Settings and Rerun: If automated results are not ' ...
28+
'satisfactory, you can try to re-run the algorithm with ' ...
29+
'a different ScoreThreshold value, the defalut is set to 70.'...
30+
'In order to do so, click Undo Run to undo ' ...
31+
'current automation run, click Settings and make changes to ' ...
32+
'Settings, and press Run again.'], ...
33+
['Accept/Cancel: If results of automation are satisfactory, ' ...
34+
'click Accept to accept all automated labels and return to ' ...
35+
'manual labeling. If results of automation are not ' ...
36+
'satisfactory, click Cancel to return to manual labeling ' ...
37+
'without saving automated labels.']};
38+
end
39+
40+
%---------------------------------------------------------------------
41+
% Step 2: Define properties to be used during the algorithm. These are
42+
% user-defined properties that can be defined to manage algorithm
43+
% execution.
44+
properties
45+
%SelectedLabelName Selected label name
46+
% Name of selected label. Vehicles detected by the algorithm will
47+
% be assigned this variable name.
48+
SelectedLabelName
49+
50+
%Detector Detector
51+
% Pre-trained navGate detector, an object of class
52+
% acfObjectDetector.
53+
navGateDetector
54+
55+
%Score Threshold
56+
ScoreThreshold = 65;
57+
58+
59+
end
60+
61+
%----------------------------------------------------------------------
62+
% Setup
63+
%----------------------------------------------------------------------
64+
methods
65+
66+
function flag = supportsReverseAutomation(~)
67+
flag = false;
68+
end
69+
70+
function isValid = checkLabelDefinition(~, labelDef)
71+
72+
% Only Rectangular ROI Label definitions are valid for the
73+
% navGate Detector.
74+
isValid = labelDef.Type==labelType.Rectangle;
75+
end
76+
77+
function isReady = checkSetup(algObj)
78+
79+
% Is there one selected ROI Label definition to automate.
80+
isReady = ~isempty(algObj.SelectedLabelDefinitions);
81+
end
82+
function settingsDialog(algObj)
83+
84+
prompt = {'Set the threshold value from 1-100'};
85+
dlgTitle = 'Threshold';
86+
dims = [1 35];
87+
defInput = {num2str(algObj.ScoreThreshold)};
88+
algObj.ScoreThreshold = str2double(inputdlg(prompt,dlgTitle,dims,defInput));
89+
90+
end
91+
end
92+
93+
%----------------------------------------------------------------------
94+
% Execution
95+
%----------------------------------------------------------------------
96+
97+
methods
98+
99+
function initialize(algObj,~)
100+
101+
% Store the name of the selected label definition. Use this
102+
% name to label the detected vehicles.
103+
algObj.SelectedLabelName = algObj.SelectedLabelDefinitions.Name;
104+
105+
% Initialize the vehicle detector with a pre-trained model.
106+
107+
data = load('navGateDetector.mat');
108+
algObj.navGateDetector = data.navGateDetector;
109+
end
110+
111+
112+
function autoLabels = run(algObj, I)
113+
114+
autoLabels = [];
115+
116+
% Detect vehicles using the initialized vehicle detector.
117+
[bboxes, scores] = detect(algObj.navGateDetector, I,...
118+
'SelectStrongest', true);
119+
120+
[selectedBbox, selectedScore] = selectStrongestBbox(bboxes, scores);
121+
122+
% Reject detections with detection score lower than
123+
% ScoreThreshold.
124+
detectionsToKeepIdx = (selectedScore > algObj.ScoreThreshold);
125+
selectedBbox = selectedBbox(detectionsToKeepIdx,:);
126+
127+
if ~isempty(selectedBbox)
128+
% Add automated labels at bounding box locations detected
129+
% by the vehicle detector, of type Rectangle having name of
130+
% the selected label.
131+
autoLabels.Name = algObj.SelectedLabelName;
132+
autoLabels.Type = labelType.Rectangle;
133+
autoLabels.Position = selectedBbox;
134+
else
135+
autoLabels = [];
136+
end
137+
end
138+
end
139+
140+
141+
142+
end

0 commit comments

Comments
 (0)