Resize images in ImageDataStore on GPU

3 vues (au cours des 30 derniers jours)
RP
RP le 3 Oct 2017
Commenté : ENVER AKBACAK le 21 Nov 2018
I have trained a neural net (based on AlexNet) and want to classify new images by means of this neural net. First I read the images into an ImageDataStore but for AlexNet the dimension of the images have to be 227 x 227. Can I resize all images in the ImageDataStore on GPU? I currently use below code for the resizing but am wondering if this is the "fastest" way.
newSample.ReadFcn = @(newSample)imresize(imread(newSample),[227 227])
Thanks for your help,
Raf

Réponses (4)

Joss Knight
Joss Knight le 16 Oct 2017
A ReadFcn is fine for classifying one image at a time. For classifying large batches of images it will slow things down considerably. You should resize all your data in batches before calling classify:
batchData = imresize(imds.read(), [227 227]);
If you have a large dataset to classify, it may be best simply to resize all the images and save them to new files.
For training, in R2017b you can use the augmentedImageSource.
  2 commentaires
RP
RP le 19 Oct 2017
Thanks for your suggestion Joss. I'm fairly new to Matlab and noticed that only my first image ends up in batchData. Do I have to create a for loop around the batchData resizing?
Joss Knight
Joss Knight le 24 Oct 2017
Sorry. Set the ReadSize to the size of the batch and concatenate:
imds.ReadSize = 128;
batch = imds.read();
batch = cat(4, batch{:});

Connectez-vous pour commenter.


ENVER AKBACAK
ENVER AKBACAK le 27 Fév 2018
Modifié(e) : ENVER AKBACAK le 27 Fév 2018
Hi,
Set the number of images to be read in imds by executing:
imds.ReadSize = numpartitions(imds)
Then resize all images by:
imds.ReadFcn = @(loc)imresize(imread(loc),[227,227]);
thats it, all your images in imds is now [227,227]
check some of them randomly:
img = readimage(imds,5); imshow(img); size(img)
img = readimage(imds,222); imshow(img); size(img)
  1 commentaire
Anup Gurung
Anup Gurung le 19 Mar 2018
Hi I am trying to do the same thing, i want to reduce the size of the images i have in my folders. But its not working for me. Can you help me?
imds = imageDatastore('Shapes','IncludeSubfolders',true,'Labelsource','foldernames');
% % Count the label and how many images are there in each of the label % images
labelCount = countEachLabel(imds); % % Resize images in an image datastore
imds.ReadSize = (imds)25; imds.ReadFcn = @(loc)imresize(imread(loc),[32,32,1]);

Connectez-vous pour commenter.


ENVER AKBACAK
ENVER AKBACAK le 27 Avr 2018
Try this
imds = imageDatastore('Shapes','IncludeSubfolders',true,'Labelsource','foldernames');
imds.ReadSize = numpartitions(imds)
imds.ReadFcn = @(loc)imresize(imread(loc),[32,32]);
  2 commentaires
Rituraj Kushwaha
Rituraj Kushwaha le 21 Nov 2018
what is loc?
ENVER AKBACAK
ENVER AKBACAK le 21 Nov 2018
It is the parameter (input) of anonymous function. You can use any proper name instead. Each images in imds passed the function over this parameter. For example sqr= @y y.^2;
c=sqr(5);
c=25
here, 5 passed the function through y, like loc.

Connectez-vous pour commenter.


benhadid ahmed
benhadid ahmed le 17 Juil 2018
try this you make a function to read a picture and resize it like this function img = CrerDataStore( file ) % Import image img = imread(file); % resize image img = imresize(img,[227 227]); % Convert grayscale to color (RGB) if you need img = repmat(img,[1 1 3]); end
after this you make your call function in your program like this imds= imageDatastore(pathToImages,'ReadFcn',@CrerDataStore); img=readimage(imds,1); size(img)

Catégories

En savoir plus sur Deep Learning for Image Processing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by