using clear datas as input datas' labels in a cnn dataset in matlab

Assuming you already have a dataset loaded in MATLAB for your convolutional neural network (CNN) and you want to clear or clean up some of the labels for your input data, you can follow these steps:

  1. Identify the labels you want to clear or clean up. You can inspect your dataset to see what labels are available using the following code:
main.m
images = imageDatastore('path/to/images', 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
labels = unique(images.Labels);
132 chars
3 lines

The LabelSource parameter allows you to set the source of the labels. In this case, we are using the folder names to set the labels.

  1. Create a mapping of the labels you want to clear or clean up. If you want to clear some labels completely, you can remove them from the mapping. If you want to modify the labels, you can map them to new labels. For example:
main.m
clear_labels = {'label1', 'label2'};
mapping = containers.Map(clear_labels, {''});
83 chars
3 lines

In this case, we are creating a containers.Map object that maps the labels label1 and label2 to an empty string. This means that these labels will be removed from the dataset.

  1. Apply the mapping to the labels of the input data. You can use the following code to apply the mapping to your input data:
main.m
augmentedImages = augmentedImageDatastore([width height], images, 'DataAugmentation', 'none', 'OutputSizeMode', 'randcrop', 'ColorPreprocessing', 'gray2rgb');
augmentedImages.Labels = values(mapping, augmentedImages.Labels);
225 chars
3 lines

Here, we are creating an augmented image data store that resizes the images to [width height] and applies random cropping as the output size mode. We are also setting the color preprocessing to convert any grayscale images to RGB. Finally, we are applying the mapping to the labels using the values function of the containers.Map object.

  1. Use the augmented data as input to your CNN. Now, you can use the augmentedImages object as input to your CNN. For example:
main.m
layers = [...];
options = trainingOptions(...);
net = trainNetwork(augmentedImages, layers, options);
102 chars
4 lines

Note that the steps above only modify the labels of the input data. If you want to remove or modify entire images from your dataset based on their labels, you will need to use a different approach.

gistlibby LogSnag