Is there a way to apply random noise to 'imageInputLayer' during CNN training?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello~
I checked that there are options, like random crop or random flip in imageInputLayer function. But, i'd like to add additive Gaussian random noise to my each input image for CNN to be invariant to noise.
Is there any way for this? Thank you for reading!
댓글 수: 0
답변 (2개)
Carl
2017년 4월 3일
Hi Jonghyun, there is no option built into the 'imageInputLayer' function for doing that, but you can manually edit the images before training your network. Images can be passed in via the 'imds' argument to the 'trainNetwork' function, where 'imds' is an ImageDatastore object with categorical labels.
Before training your network, you can add Gaussian noise to your images specified in the ImageDatastore. The 'imnoise' function may be helpful for this.
https://www.mathworks.com/help/images/ref/imnoise.html
댓글 수: 0
Javier Pinzón
2017년 10월 20일
Hello Kim,
(Hope it is not reaaally late and might help others)
If you want to add some Noise during the training, you can do that in the @readFunction of the images, i mean:
- First the normal definition of the dataset:
location = 'train';
imds = imageDatastore(location,'IncludeSubfolders',1,'LabelSource','foldernames');
tbl = countEachLabel(imds);
minSetCount = min(tbl{:,2}); % determine the smallest amount of images in a category
% Use splitEachLabel method to trim the set.
imds = splitEachLabel(imds, minSetCount);
% Notice that each set now has exactly the same number of images.
countEachLabel(imds)
trainingDS = imds;
% Convert labels to categoricals
trainingDS.Labels = categorical(trainingDS.Labels);
trainingDS.ReadFcn = @readFunctionTrain;
When you have defined it, with the @ReadFunctionTrain, in this function you might defined the reading of the image as follows:
function I = readFunctionTrain(filename)
I = imread(filename);
% Defines a random number to add the noise
k = randi([0, 100])
%
if k > 50
% Resize images to the size required by the network.
I = imresize(I, [64 64]);
else
% NOISE ADDITION TO THE IMAGE AS YOU WANT, then, resize the img, or if you want to
% resize and the add the noise, the order is your up to you
I = imresize(I, [64 64]);
end
You can add the noise function that you want in the image, so with the random number, the noise will be added dynamicly over the training, without affect the original image.
Best Regards,
Javier
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!