GANs not scaling up or down
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2023-3-31
You might possibly be able to take advantage of Transfer Learning; https://www.mathworks.com/discovery/transfer-learning.html
回答(1 个)
Nayan
2023-4-5
编辑:Nayan
2023-4-5
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!