Splitting Ground Thruth Data

I am training a object detector by following along the following tutorial from MathWorks [1]. Instead of detecting from a video I am using a set of images. Images are labeled using ImageLabeller app. My question is how do i split the images in to train/test datasets. `objectDetectorTrainingData` has sampling factor but I believe thats for sampling from video according to docs sampling factor is 1 for images which loads the whole dataset for training. Once the ground truth data is loaded from the mat file generated from ImageLabeller how do i partion it say 80/20?
[1] https://www.mathworks.com/matlabcentral/fileexchange/69180-using-ground-truth-for-object-detection

回答 (1 件)

Sai Bhargav Avula
Sai Bhargav Avula 2019 年 10 月 31 日

0 投票

Hi,
You can split the data from the mat file generated using Image Labeler by using the imageDatastore function.
The code structure would look like this
DatasetPath = fullfile(matlabroot,'your path');
imds = imageDatastore(DatasetPath,'IncludeSubfolders',true,'FileExtensions','.mat','LabelSource','foldernames','ReadFcn',@loadmydata);
[imdsTrain,imdsTest] = splitEachLabel(imds,0.8,'randomize');
function data = loadmydata(filename)
S = load(filename);
data = S.data;
end
Hope this helps !

3 件のコメント

Hamza Yerlikaya
Hamza Yerlikaya 2019 年 10 月 31 日
Hi,
Thanks for the response. I will try this but in the mean time I have come up with the following solution. Just wanted to make sure if I am on the right track. It seems to to the trick.
PD = 0.20;
cv = cvpartition(size(gTruth.LabelData,1),'HoldOut',PD)
trainGroundTruth = ...
groundTruth(groundTruthDataSource(gTruth.DataSource.Source(cv.training,:)), ...
gTruth.LabelDefinitions, ...
gTruth.LabelData(cv.training,:))
testGroundTruth = ...
groundTruth(groundTruthDataSource(gTruth.DataSource.Source(cv.test,:)), ...
gTruth.LabelDefinitions, ...
gTruth.LabelData(cv.test,:))
Sai Bhargav Avula
Sai Bhargav Avula 2019 年 11 月 1 日
Yes, cvpartition is one way. One thing you need to look is the NumTestSets. I think you might have already looked into this. But just attaching the link as reference.
Nada Selim
Nada Selim 2021 年 2 月 4 日
Thank you for sharing your code. it helps me to split my dataset as well.

サインインしてコメントする。

質問済み:

2019 年 10 月 30 日

コメント済み:

2021 年 2 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by