3
$\begingroup$

I have a GAN defined like so:

GAN = NetGraph[{"gen" -> generator, 
    "dis" -> discriminator}, {"gen" -> "dis"}];

My question is if I use NetTrain on GAN using the following command, will it also update the generator or do I have to use NetTake and create Generator every time?

GAN = NetTrain[GAN, GANtrainingdata, LossFunction -> loss, 
   Method -> "ADAM", MaxTrainingRounds -> 1, BatchSize -> 128, 
   LearningRateMultipliers -> {"dis" -> 0}];

Also, I have a loop like this which does one batch for discriminator and then one for GAN, but I think this isn't the optimal way to do in Mathematica:

For[i = 1, i <= 500, i++,
 discriminatorTrainingData = 
  RandomSample[
   Union[Map[# -> {0} &, generateFakeSamples[64]], 
    Map[# -> {1} &, generateRealSamples[64]]], 128];

 discriminator = 
  NetTrain[discriminator, discriminatorTrainingData, 
   LossFunction -> loss, Method -> "ADAM", MaxTrainingRounds -> 1, 
   BatchSize -> 128];

 GANtrainingdata = # -> {1} & /@ generateLatentPoints[128, 5];

 GAN = NetGraph[{"gen" -> generator, 
    "dis" -> discriminator}, {"gen" -> "dis"}];

 GAN = NetTrain[GAN, GANtrainingdata, LossFunction -> loss, 
   Method -> "ADAM", MaxTrainingRounds -> 1, BatchSize -> 128, 
   LearningRateMultipliers -> {"dis" -> 0}];
 ]

Any help to optimise the for loop (perhaps remove it completely) would be appreciated! Thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.