How to change the generator output size

3 visualizzazioni (ultimi 30 giorni)
Nikolay
Nikolay il 12 Apr 2023
Risposto: Divyanshu il 18 Apr 2023
I am trying to design a GAN using the example provided by matlab, however the data I'm using to train it are 150x105 grayscal images and in the example they are using 64x64 rgb. Could anyone sugest how can I change the output of the generator to 150x105 here? From what i understood, it's doable by eitheer changing the projectionSize or doing something witht the last convolution layer, yet isn't clear what exacly. If this could help, here's the tutorial link : https://ch.mathworks.com/help/deeplearning/ug/train-generative-adversarial-network.html
filterSize = 5;
numFilters = 32;
numLatentInputs = 100;
projectionSize = [4 4 512];
layersGenerator = [
featureInputLayer(numLatentInputs, 'Normalization', 'none')
projectAndReshapeLayer(projectionSize)
transposedConv2dLayer(filterSize, 2*numFilters, 'Name', 'tconv1')
batchNormalizationLayer('Name', 'bn1')
reluLayer
transposedConv2dLayer(filterSize, numFilters, 'Stride', 2, 'Cropping', 'same', 'Name', 'tconv2')
batchNormalizationLayer('Name', 'bn2')
reluLayer
transposedConv2dLayer(filterSize, 1, 'Stride', 2, 'Cropping', 'same', 'Name', 'tconv3')
tanhLayer('Name', 'tanh')];
netG = dlnetwork(layersGenerator);

Risposte (1)

Divyanshu
Divyanshu il 18 Apr 2023
One possible approach to change the output size of the generator network can be by changing the projectionSize parameter which is given as an input to the function projectAndReshapeLayer.
You can have a look at the below code:
filterSize = 5;
numFilters = 64;
numLatentInputs = 100;
projectionSize = [150 105 1];
layersGenerator = [
featureInputLayer(numLatentInputs,'Normalization','none')
projectAndReshapeLayer(projectionSize)
transposedConv2dLayer(filterSize,4*numFilters,'Name','tconv1')
batchNormalizationLayer('Name','bn1')
reluLayer
transposedConv2dLayer(filterSize,2*numFilters,Stride=2,Cropping="same")
batchNormalizationLayer
reluLayer
transposedConv2dLayer(filterSize,numFilters,Stride=2,Cropping="same")
batchNormalizationLayer
reluLayer
transposedConv2dLayer(filterSize,3,'Stride',2,Cropping="same")
tanhLayer('Name','tanh')
];
netG = dlnetwork(layersGenerator);
Also, remember to adjust the size of the input noise vector as well and change it according to the new image dimensions 150 * 105. To project and reshape the noise input, use the custom layer projectAndReshapeLayer, attached to the example as a supporting file. To access this layer, open the example as a live script.

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!

Translated by