Image Normalization before Fine-Tuning a pretrained CNN for image classification

6 ビュー (過去 30 日間)
Hello,
Is it possible to directly add an image normalization step, to this training code below, to normalize all the dataset images before training the CNN pretrained model ? I need to train my model with pixel values ranging between 0 and 1 instead of 0 and 255.
imds = imageDatastore(dataset, 'IncludeSubfolders',true,'LabelSource','foldernames')
tbl = countEachLabel(imds);
numClasses = height(tbl);
[trainingSet, testSet] = splitEachLabel(imds, 0.7,'randomize');
I tried to modify the image input layer (Normalization 'rescale-zero-one') of the model but it did not work because this option does not exist effectively ( previous question asked related: https://fr.mathworks.com/matlabcentral/answers/1441834-imageinputlayer-normalization-data-normalization-options?s_tid=srchtitle )
Is there any way to normalize directly images in augmentedImageDatastore ?
augmentedTrainingSet = augmentedImageDatastore(imageSize, ...
trainingSet, 'ColorPreprocessing', 'gray2rgb');
augmentedTestSet = augmentedImageDatastore(imageSize, ...
testSet, 'ColorPreprocessing', 'gray2rgb');
Thank you in advance !! Appreciate any kind of help !

採用された回答

yanqi liu
yanqi liu 2021 年 9 月 26 日
sir, may be you shoud use function handle to define your read image style, pleaes read the follow code
clc; clear all; close all;
dataset = fullfile(matlabroot,'toolbox','matlab');
imds = imageDatastore(dataset,'IncludeSubfolders',true,...
'FileExtensions','.tif',...
'LabelSource','foldernames',....
'ReadFcn',@data_preporcess);
tbl = countEachLabel(imds);
numClasses = height(tbl);
[trainingSet, testSet] = splitEachLabel(imds, 0.7,'randomize');
function data = data_preporcess(file)
data = imread(file);
% ranging between 0 and 1 instead of 0 and 255
data = mat2gray(data);
end

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 9 月 25 日
Sure. Use mat2gray() or rescale() or im2double().

カテゴリ

Help Center および File ExchangeRecognition, Object Detection, and Semantic Segmentation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by