1
votes

I have 300 images in a folder that I'm using as a data set for validation of a neural network.

Each image has a label of 1 or 0. I converted the images to a matrix in MATLAB and the labels to a 300x1 vector of either 1 or 0 that corresponds to each row of images in the matrix.

I noticed that the labels aren't balanced, which affects the network. How can I reorder the labels with keeping the same indication of zero or one for each row of images?

This is what I tried:

I split the ones and zeros each in a vector and now I want to be able to put at least two ones and 10 zeros in 12 rows consecutively, but I didn't know how. I used this to split the ones and zeros:

ones = labels(labels(:,1)==1,:)
zeros = labels(labels(:,1)==0,:)

How can I rearrange the labels to remove the problem of unbalanced labels?

1

1 Answers

0
votes

This will create an index vector that should evenly distribute your two sets of labels so that they are roughly balanced within each successive set of 12 labels (note that this assumes your data divides evenly into sets of 12, which it does in your example):

index = [find(labels(:, 1) == 1); find(labels(:, 1) == 0)];
index = reshape(reshape(index, [25 12]).', [], 1);

You would then use this index to reorder the rows of your label array and any associated data (like an array of image data):

labels = labels(index, :);
otherData = otherData(index, :);