Resize images in ImageDataStore on GPU
18 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (4)
Joss Knight
il 16 Ott 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.
2 Commenti
Joss Knight
il 24 Ott 2017
Sorry. Set the ReadSize to the size of the batch and concatenate:
imds.ReadSize = 128;
batch = imds.read();
batch = cat(4, batch{:});
ENVER AKBACAK
il 27 Feb 2018
Modificato: ENVER AKBACAK
il 27 Feb 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 Commento
Anup Gurung
il 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]);
ENVER AKBACAK
il 27 Apr 2018
Try this
imds = imageDatastore('Shapes','IncludeSubfolders',true,'Labelsource','foldernames');
imds.ReadSize = numpartitions(imds)
imds.ReadFcn = @(loc)imresize(imread(loc),[32,32]);
2 Commenti
ENVER AKBACAK
il 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.
benhadid ahmed
il 17 Lug 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)
0 Commenti
Vedere anche
Categorie
Scopri di più su Image Data Workflows in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!