Understanding the use of data in Object Detection

Hi,
I have a question regarding the 'load data' section in this code, which was taken from the Yolo v3 object detection guide here.
The example uses images of vehicles. It has a Ground Truth file for that, and also a dataset.
I can see the Ground Truth file in the MATLAB folder, but I don't understand where it's taking the dataset from. I'm not sure I understand the difference between a dataset and Ground Truth data.
What I'd like to do is to change the code so that it detects faces instead of vehicles.
I have downloaded a dataset called 'CelebA'. I now have a folder that contains images of faces, they're numbered 000001, 000002, etc...
There's also a text file that contains many lines, each containing an image file name and coordinates for its boundary box (I assume the coordinates mark the location of the face in the image, so it's part of the ground truth data).
I need to somehow load the ground truth data into matlab, as well as the dataset.
I'd appreciate help with implementing this change.
Thank you.
%% download pretrained network (set to 'true' to train the network)
doTraining = false;
if ~doTraining
preTrainedDetector = downloadPretrainedYOLOv3Detector();
end
%% load data (modify to faces dataset)
data = load('vehicleDatasetGroundTruth.mat');
vehicleDataset = data.vehicleDataset;

Answers (1)

To my understanding, you want to learn how the dataset is loaded and used in Yolo v3 object detection MATLAB example. Further, you want to use your own data to train Yolo v3 object detection model.
Part 1:
%% download pretrained network (set to 'true' to train the network)
doTraining = false;
if ~doTraining
preTrainedDetector = downloadPretrainedYOLOv3Detector();
end
This part of code is used to decide whether you want to train the network or use the pretrained network. Set 'doTraining' to 'true' to train the network.
Part 2:
%% load data (modify to faces dataset)
data = load('vehicleDatasetGroundTruth.mat');
vehicleDataset = data.vehicleDataset;
Here, 'data' variable will store mat file which in turn is a 1×1 struct with 1 field i.e. vehicleDataset.
Now, 'vehicleDataset' variable will store main dataset which is a 295*2 table. Column 1 contain location path of image files and column 2 contain bounding box coordinates. This bounding boxes specifies the upper left corner and the size of the bounding box in pixels. The bounding boxes are in the form [x y width height].
Now, if you want to use your data you have to apply following changes.
Step 1: You create a table in which:
  • first column should contain the location paths of your images.
  • second column should contain the bounding box vector as per specified format.
Step 2: Set 'vehicleDataset' variable to this newly created table.

5 Comments

Hi,
Thank you for the detailed explanation. I've been struggling with creating a dataset that works.
I took a .csv file (bbox_list_celeba.csv) that contains two columns: column 1 contains the image file path and column 2 contains the bounding box coordinates.
I have imported the .csv file into MATLAB, set column 1 as 'text' and column 2 as 'categorical'.
I now have a .mat file called faceDatasetGroundTruth.mat that contains this two column table. When I try to run the code with this file, after changing the relevant references in the code of course, I get this error:
Error using boxLabelDatastore (line 234)
Invalid data in column 1 of input table 1.
Error in yolov3_Copy (line 27)
bldsTrain = boxLabelDatastore(trainingDataTbl(:, 2:end));
Caused by:
Error using boxLabelDatastore>iAssertValidBBoxFormat (line 870)
The size of bounding box data must be M-by-4, M-by-5, or M-by-9, where M is the number of boxes in each table element. The column
in the training data table that contains the bounding boxes must be a cell array.
Hi,
Firstly, column 2 i.e. bounding box must not be categorical, rather it should be a vector of 4 elements.
Secondly, You can try to convert the table into an array using table2array function.
Thanks
OK, thank you.
I do have another question. When I use my own dataset, do I need to train the network, that is, to set the doTraining variable to true?
Hi,
If you want to just use the already trained network, then you can directly use it on your data without training the network. But if you want that the network learn for your data then you have to train the network for your data.
Thanks
Does usig the Train function replace the original training that was done on the COCO database, or does it add to it, like transfer training?
By the way, I get this error when I set doTraining to 'true':
'generateTargets' is used in Object Detection Using YOLO v3 Deep Learning.
Error in modelGradients (line 11)
[boxTarget, objectnessTarget, classTarget, objectMaskTarget, boxErrorScale] = generateTargets(gatheredPredictions,...
Error in deep.internal.dlfeval (line 17)
[varargout{1:nargout}] = fun(x{:});
Error in dlfeval (line 40)
[varargout{1:nargout}] = deep.internal.dlfeval(fun,varargin{:});
Error in yolov3_Copy (line 110)
[gradients, state, lossInfo] = dlfeval(@modelGradients, yolov3Detector, XTrain, YTrain, penaltyThreshold);

Sign in to comment.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!