How to split imagedatastore and pixellabeldatastore

22 vues (au cours des 30 derniers jours)
Wan Faiz
Wan Faiz le 19 Déc 2021
I am currently doing my project for automated fracture segmentation using deep learning. Currently I have the input images and its skull labels (masks). These are put into imagedatastore(imds) and pixellabeldatastore(pxds). From this two datastore, how can I split it into 80% training set, 10% validation set and 10% test set? I try to use splitEachLabel but didnt work for pixellabeldatastore. I saw some use partition but I am not sure how to apply it for my case

Réponse acceptée

yanqi liu
yanqi liu le 21 Déc 2021
yes,sir,please check the help doc “Semantic Segmentation Using Deep Learning”
we can learn the way to split data and label,such as
imds = imageDatastore(imgDir);
pxds = pixelLabelDatastore(labelDir,classes,labelIDs);
[imdsTrain, imdsVal, imdsTest, pxdsTrain, pxdsVal, pxdsTest] = partitionCamVidData(imds,pxds);
function [imdsTrain, imdsVal, imdsTest, pxdsTrain, pxdsVal, pxdsTest] = partitionCamVidData(imds,pxds)
% Partition CamVid data by randomly selecting 60% of the data for training. The
% rest is used for testing.
% Set initial random state for example reproducibility.
rng(0);
numFiles = numel(imds.Files);
shuffledIndices = randperm(numFiles);
% Use 80% of the images for training.
numTrain = round(0.80 * numFiles);
trainingIdx = shuffledIndices(1:numTrain);
% Use 10% of the images for validation
numVal = round(0.10 * numFiles);
valIdx = shuffledIndices(numTrain+1:numTrain+numVal);
% Use the rest for testing.
testIdx = shuffledIndices(numTrain+numVal+1:end);
% Create image datastores for training and test.
trainingImages = imds.Files(trainingIdx);
valImages = imds.Files(valIdx);
testImages = imds.Files(testIdx);
imdsTrain = imageDatastore(trainingImages);
imdsVal = imageDatastore(valImages);
imdsTest = imageDatastore(testImages);
% Extract class and label IDs info.
classes = pxds.ClassNames;
labelIDs = camvidPixelLabelIDs();
% Create pixel label datastores for training and test.
trainingLabels = pxds.Files(trainingIdx);
valLabels = pxds.Files(valIdx);
testLabels = pxds.Files(testIdx);
pxdsTrain = pixelLabelDatastore(trainingLabels, classes, labelIDs);
pxdsVal = pixelLabelDatastore(valLabels, classes, labelIDs);
pxdsTest = pixelLabelDatastore(testLabels, classes, labelIDs);
end

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by