フィルターのクリア

How to split imagedatastore and pixellabeldatastore

19 ビュー (過去 30 日間)
Wan Faiz
Wan Faiz 2021 年 12 月 19 日
回答済み: yanqi liu 2021 年 12 月 21 日
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

採用された回答

yanqi liu
yanqi liu 2021 年 12 月 21 日
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

その他の回答 (0 件)

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by