How to split training, validation and testing from ground truth file generated by ground truth label application
20 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi guys
i want to know how to split training, validation and testing from ground truth file generated by ground truth labeler application i need for example 70% for training 20% for validation and 10% for testing
And then how can i evaluate the created detector with validation data and testing data using evaluateDetectionPrecision
Herein the code
load('gTruth.mat')
fruits = selectLabels(gTruth,{'apple','orange'});
if isfolder(fullfile('TrainingData'))
cd TrainingData
else
mkdir TrainingData
end
addpath('TrainingData');
options = trainingOptions('sgdm', ...
'MiniBatchSize', 32, ...
'InitialLearnRate', 1e-3, ...
'MaxEpochs', 250, ...
'CheckpointPath', tempdir);
classes = {'first', 'second'};
outputs = 1+numel(classes); % +1 for background class
layers = [
imageInputLayer([32 32 3],"Name","imageinput")
convolution2dLayer([3 3],32,"Name","conv_1","Padding",[1 1 1 1],"WeightsInitializer","narrow-normal")
reluLayer("Name","relu_1")
convolution2dLayer([3 3],32,"Name","conv_2","Padding",[1 1 1 1],"WeightsInitializer","narrow-normal")
reluLayer("Name","relu_2")
maxPooling2dLayer([2 2],"Name","maxpool","Stride",[2 2])
fullyConnectedLayer(64,"Name","fc_1","WeightsInitializer","narrow-normal")
reluLayer("Name","relu_3")
fullyConnectedLayer(outputs)
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")];
trainingData = objectDetectorTrainingData(fruits,'SamplingFactor',1,...
'WriteLocation','TrainingData');
detector = trainFastRCNNObjectDetector(trainingData, layers, options, ...
'NegativeOverlapRange', [0 0.1], ...
'PositiveOverlapRange', [0.7 1]);
save('Detector.mat','detector');
0 commentaires
Réponses (1)
Uttiya Ghosh
le 18 Juin 2020
Hi Abdussalam,
From my understanding, you would like to know the function that can be used to split a dataset into training, validation and testing sub datasets. I am assuming a random dataset of size 1000*10 and providing you the solution below.
% Define the datasize
dataSize=1000;
featureDim=10;
% Create the dataset
data=rand(dataSize,featureDim);
% Define the split sizes
trainSize=0.7*dataSize;
valSize=0.2*dataSize;
testSize=0.1*dataSize;
% Create the training data
cv=cvpartition(dataSize,'HoldOut',valSize+testSize);
idx=cv.test;
dataTrain = data(~idx,:);
dataValTest = data(idx,:);
% Create validation and test data
cv=cvpartition(valSize+testSize,'HoldOut',testSize);
idx=cv.test;
dataVal = data(~idx,:);
dataTest = data(idx,:);
For the second part of your question, from my undersanding you want to know the usage of usage of evaluateDetectionPrecision. I have used 'vehicleTrainingData.mat' file to explain the usage, This file is available in MATLAB.
% Load vehicleTrainingData
vehicleData = load('vehicleTrainingData.mat');
trainingData = data.vehicleTrainingData;
% Add fullpath to the local vehicle data folder.
dataDir = fullfile(toolboxdir('vision'), 'visiondata');
trainingData.imageFilename = fullfile(dataDir, trainingData.imageFilename);
% Create an imageDatastore using the files from the table
imds = imageDatastore(trainingData.imageFilename);
% Create a boxLabelDatastore using the label columns from the table
blds = boxLabelDatastore(trainingData(:,2:end));
% Load YOLOv2 Detector
vehicleDetector = load('yolov2VehicleDetector.mat');
detector = vehicleDetector.detector;
% Run the detector with imageDatastore.
results = detect(detector, imds);
% Evaluate the results against the ground truth data.
[ap, recall, precision] = evaluateDetectionPrecision(results, blds);
For more information, refer to the links given below:
4 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!