cannot resize images in a datastore

7 visualizaciones (últimos 30 días)
Mahmoud Dinar
Mahmoud Dinar el 24 de Feb. de 2022
Comentada: Mahmoud Dinar el 24 de Feb. de 2022
I was going through the Deep Learning with MATLAB course and working on the first project. I tried to resize the images to feed them into googlenet. The original datastore had 1000+ images of size [200 200 3]. I tried:
trainds = augmentedImageDatastore([224 224],original_trainds);
but when I read the first image, the size had not changed. The baffling part was that when I looked at the provided solution, it was exactly what I had thought.
trainDs = augmentedImageDatastore([224 224],trainImgs);
I don't know which step went wrong. Thanks for your help.

Respuesta aceptada

Image Analyst
Image Analyst el 24 de Feb. de 2022
I think the image scaling happens "on the fly" when doing training. I'm pretty sure it does not save the scaled images. And you need to specify the amount to scale. Here's a snippet from my code which basically comes from the Mathworks example for SegNet
%------------------------------------------------------------------------------------------------------------------------------------------------
% Create Augmenter which applies random reflection/translation/scale
augmenter = imageDataAugmenter('RandXReflection',true,...
'RandXTranslation',[-10 10],'RandYTranslation',[-10 10],'RandXScale',[0.8 1.2]);
% create the datastore for images,labels and augmenter together
pximds = pixelLabelImageDatastore(imds,pxds,'DataAugmentation',augmenter);
%Train Front - 50 epochs and 10 Augmentations per mask
options = trainingOptions('sgdm','InitialLearnRate',1e-3, ...
'MaxEpochs',1000,'VerboseFrequency',1,'MiniBatchSize',4,'Shuffle','every-epoch','Plots','training-progress','CheckpointPath',checkpointPath );
  1 comentario
Mahmoud Dinar
Mahmoud Dinar el 24 de Feb. de 2022
You are right about "scaling happens on the fly". It turns out that the problem was not in resizing the image with augmentedImageDatastore but with the setup of my network layers. So, the augmentation (resizing in this case) as you said only happens during runtime, and the output size isn't really stored.
Oddly, replacing layers() didn't do the same thing as layerGraph().

Iniciar sesión para comentar.

Más respuestas (1)

yanqi liu
yanqi liu el 24 de Feb. de 2022
yes,sir,may be augmentedImageDatastore process as function,such as
which cameraman.tif
/MATLAB/toolbox/images/imdata/cameraman.tif
imdsTrain = imageDatastore(fullfile(matlabroot,'toolbox/images/imdata'), ...
'IncludeSubfolders',true,'LabelSource','foldernames');
augimdsTrain = augmentedImageDatastore([224 224],imdsTrain,'ColorPreprocessing','gray2rgb');
img1 = readimage(imdsTrain,1);
size(img1)
ans = 1×2
480 640
db = read(augimdsTrain);
Warning: The ability to read FITS files with IMREAD may be removed in a future release. Use FITSREAD to import FITS files.
img2 = db.input{1};
size(img2)
ans = 1×3
224 224 3

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by