|
a |
|
b/partitionCEData.m |
|
|
1 |
% Developer: Tonmoy Ghosh (tghosh@crimson.ua.edu) |
|
|
2 |
function [imdsTrain, imdsTest, pxdsTrain, pxdsTest] = partitionCEData(imds,pxds) |
|
|
3 |
% Partition CamVid data by randomly selecting 60% of the data for training. The |
|
|
4 |
% rest is used for testing. |
|
|
5 |
|
|
|
6 |
% Set initial random state for example reproducibility. |
|
|
7 |
rng(0); |
|
|
8 |
numFiles = numel(imds.Files); |
|
|
9 |
shuffledIndices = randperm(numFiles); |
|
|
10 |
|
|
|
11 |
% Use 60% of the images for training. |
|
|
12 |
N = round(0.60 * numFiles); |
|
|
13 |
trainingIdx = shuffledIndices(1:N); |
|
|
14 |
|
|
|
15 |
% Use the rest for testing. |
|
|
16 |
testIdx = shuffledIndices(N+1:end); |
|
|
17 |
|
|
|
18 |
% Create image datastores for training and test. |
|
|
19 |
trainingImages = imds.Files(trainingIdx); |
|
|
20 |
testImages = imds.Files(testIdx); |
|
|
21 |
imdsTrain = imageDatastore(trainingImages); |
|
|
22 |
imdsTest = imageDatastore(testImages); |
|
|
23 |
|
|
|
24 |
% Extract class and label IDs info. |
|
|
25 |
classes = pxds.ClassNames; |
|
|
26 |
labelIDs = 1:numel(pxds.ClassNames); |
|
|
27 |
|
|
|
28 |
% Create pixel label datastores for training and test. |
|
|
29 |
trainingLabels = pxds.Files(trainingIdx); |
|
|
30 |
testLabels = pxds.Files(testIdx); |
|
|
31 |
pxdsTrain = pixelLabelDatastore(trainingLabels, classes, labelIDs); |
|
|
32 |
pxdsTest = pixelLabelDatastore(testLabels, classes, labelIDs); |
|
|
33 |
end |