trainStore = shuffle(trainStore);
bootstrap_factor = 1;
alphabetical_labels = {'happy', 'sad'};
labels = trainStore.Labels;
labelCounts = countEachLabel(trainStore);
labelCounts = labelCounts.Count;
weights = labelCounts/sum(labelCounts);
weights = weights.^(-1);
weightVec = [];
for lab = 1:length(labels)
for labidx = 1:length(alphabetical_labels)
if labels(lab) == alphabetical_labels(labidx)
weightVec(lab) = weights(labidx);
end
end
end
trainFiles = trainStore.Files;
bootstrapSize = round(length(trainFiles) * bootstrap_factor);
Bootstrap = datasample(trainFiles, bootstrapSize, 'Weights', weightVec);
bootStrapTrainStore = imageDatastore(Bootstrap, 'LabelSource', 'foldernames', IncludeSubfolders', true);
augmentedResolution = [128 128];
augmenter = imageDataAugmenter('RandRotation', [-10 10]);
trainStoreAug = augmentedImageDatastore(augmentedResolution, bootStrapTrainStore, 'DataAugmentation', augmenter);