GANs not scaling up or down
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to in future make this GANs be able to handle data sets with different sized images, as I may want or use smaller images to experiment faster or actual dataset may have smaller images. Additionally, I may even want bigger. I wish to make it so everything scales down to save power of image smaller. This is example GANs I’m using https://www.mathworks.com/help/deeplearning/ug/train-generative-adversarial-network.html however any rescaling I do or change in number leads to an error it seems like, including changing all numbers, one number at time, and more.
2 commentaires
Walter Roberson
le 31 Mar 2023
You might possibly be able to take advantage of Transfer Learning; https://www.mathworks.com/discovery/transfer-learning.html
Réponses (1)
Nayan
le 5 Avr 2023
Modifié(e) : Nayan
le 5 Avr 2023
Hi,
GANs makes use of two network namely generator and descriminator. To train GANs with images a convolutional neural network is used in practice.
There is a limitation towards passing different size image input to the CNN. Though the convolution2dLayer(filterSize,numFilters) requires only filterSize and numFilters, the network must have at least one input layer (that requires the size of the input image) to train and downstream data to following layers.
Having a feedforward layer before the classification layer requires the exact size of input data.
Also if the dataset has images of variable size, creating datastore(location)(imageDatastore in case of images) can be very complex task.
I would suggest you to use resize to bring all the images to the same size and train the network.
Attaching a code example to resize images directly from the imageDatastore
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...
'nndatasets','DigitDataset');
imds = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
% % -----------------------------------------------------
% % We will use 'read' function to read images from the datastore
% % First call of read returns first image
% % Second call of read returns second image, and so on
I = read(imds); % % read first image from imds
figure,
subplot(121); imshow(I); title('First image, before resize'); axis on;
% % -----------------------------------------------------
% % Now from this point, use the custom reader function
imds.ReadFcn = @customreader;
% % Reset the datastore to the state where no data has been read from it.
reset(imds);
J = read(imds); % % read the first image again (because we reset read)
subplot(122); imshow(J); title('First image, after resize'); axis on;
K = read(imds); % % read the second image
L = read(imds); % % read the third image
figure,
subplot(121); imshow(K); title('Second image, after resize'); axis on;
subplot(122); imshow(L); title('Third image, after resize'); axis on;
% % -----------------------------------------------------
% % Code of custom image datastore reader function
function data = customreader(filename)
onState = warning('off', 'backtrace');
c = onCleanup(@() warning(onState));
data = imread(filename);
data = data(:,:,min(1:3, end));
data = imresize(data, [64 64]);
end
0 commentaires
Voir également
Catégories
En savoir plus sur Image Data Workflows dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!