Data Augmentation for images and bounding boxes in Object Detection

10 Ansichten (letzte 30 Tage)
Andrea Daou
Andrea Daou am 19 Mai 2022
Kommentiert: Amanjit Dulai am 8 Nov. 2022
Hello all,
I am trying to apply data augmentation on a object detection dataset created with Image Labeler App in MATLAB. As explained in https://fr.mathworks.com/help/deeplearning/ug/object-detection-using-yolo-v2.html, the trainingData which is a table containing imageFilename and the bouding boxes coordinates of definite object classes is augmented, with a defined augmentation function (augmentData found in the same link), using:
augmentedTrainingData = transform(trainingData,@augmentData);
I am trying to apply the same line of code after labeling my own dataset and creating the trainingData from the gTruth saved with:
trainingData = objectDetectorTrainingData(gTruth,'SamplingFactor',1, 'WriteLocation','TrainingData');
Although I followed the same concept explained, when using transform function, I am getting the error below:
Undefined function 'transform' for input arguments of type 'table'.
augmentedTrainingData = transform(trainingData,@augmentData);
How can I apply data augmentation on trainingData? I am using MATLAB R2019a.
Appreciate any kind of help. Thank you in advance !!

Antworten (1)

Seth Furman
Seth Furman am 23 Mai 2022
objectDetectorTrainingData must be called with 2 outputs in order for the first output to be an image datastore and not a table.
imageDir = fullfile(matlabroot,'toolbox','vision','visiondata','vehicles');
addpath(imageDir);
data = load('vehicleTrainingGroundTruth.mat');
gTruth = data.vehicleTrainingGroundTruth;
vehicleDetector = load('yolov2VehicleDetector.mat');
lgraph = vehicleDetector.lgraph;
% imds is an image datastore.
[imds,~] = objectDetectorTrainingData(gTruth)
imds =
ImageDatastore with properties: Files: { '/MATLAB/toolbox/vision/visiondata/vehicles/image_00123.jpg'; '/MATLAB/toolbox/vision/visiondata/vehicles/image_00099.jpg'; '/MATLAB/toolbox/vision/visiondata/vehicles/image_00174.jpg' ... and 292 more } Folders: { '/MATLAB/toolbox/vision/visiondata/vehicles' } AlternateFileSystemRoots: {} ReadSize: 1 Labels: {} SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage
% trainingDataTable is a table.
trainingDataTable = objectDetectorTrainingData(gTruth)
trainingDataTable = 295×2 table
imageFilename vehicle ______________________________________________________________ ________________ {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00123.jpg'} {2×4 double } {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00099.jpg'} {2×4 double } {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00174.jpg'} {[ 30 27 97 78]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00294.jpg'} {[ 93 74 26 25]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00244.jpg'} {[33 29 103 85]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00281.jpg'} {[ 90 69 22 19]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00032.jpg'} {[ 86 69 25 19]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00040.jpg'} {[ 84 77 38 27]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00022.jpg'} {[ 83 66 27 24]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00261.jpg'} {[ 92 70 21 17]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00175.jpg'} {[56 39 102 78]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00034.jpg'} {[ 96 70 22 18]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00152.jpg'} {[ 32 24 98 88]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00092.jpg'} {2×4 double } {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00170.jpg'} {[74 22 111 84]} {'/MATLAB/toolbox/vision/visiondata/vehicles/image_00091.jpg'} {2×4 double }
  3 Kommentare
David
David am 8 Nov. 2022
Andrea,
Did you ever figure this out? I am at that juncture myself. Any help would be greatly appreciated.
Thanks in advance,
Dave
Amanjit Dulai
Amanjit Dulai am 8 Nov. 2022
You should just be able to call objectDetectorTrainingData directly on an object with the class groundTruth.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by