GANs not scaling up or down

1 visualizzazione (ultimi 30 giorni)
Gad Licht
Gad Licht il 31 Mar 2023
Modificato: Nayan il 5 Apr 2023
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 Commenti
Walter Roberson
Walter Roberson il 31 Mar 2023
You might possibly be able to take advantage of Transfer Learning; https://www.mathworks.com/discovery/transfer-learning.html
Gad Licht
Gad Licht il 1 Apr 2023
I am familar with that conceptually, but it does not answer my question on why I cant scale up or down this code specifically.

Accedi per commentare.

Risposte (1)

Nayan
Nayan il 5 Apr 2023
Modificato: Nayan il 5 Apr 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

Categorie

Scopri di più su Image Data Workflows in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by