TransWikia.com

GAN LSTM Time Series

Mathematica Asked by unmark1 on July 26, 2021

Does anyone know if it is possible to use LSTM or another RNN in GAN architecture as the generator? Here a reference: 1

Thx!

To clarify, what I am asking is it possible in MMA 12.3 (my current version) and what I have done so far:

generator = NetChain[
  {
   50,
   ParametricRampLayer[],
   50,
   ParametricRampLayer[],
   LinearLayer[{}],
   Tanh
   }
  ,
  "Output" -> "Real"
  ]

discriminator = NetChain[
 {
 50,
 ParametricRampLayer[],
 50,
 ParametricRampLayer[],
 LinearLayer[]
 }
 ,
 "Input"->"Real",
 "Output"->"Real"
 ]

gan = NetGANOperator[{generator, discriminator}, "Latent" -> 20]

This works fine, by the way it is the reference example from Wolfram GAN Net Operator Wolfram

However, I have read in some recent papers Stanford, that researchers are including in the discriminator, for example, some kind of recurrent layer. So, I have tried, without success, the following:

discriminator = NetInitialize@
 NetChain[{GatedRecurrentLayer[1], LinearLayer[1]}, "Input" -> {1, 1},
   "Output" -> "Scalar"]

But I receive the following error message:

NetGANOperator: The discriminator (second element of the first argument), should output a real number, but it outputs a length-1 vector of real numbers instead.

I have already tried to change the output format but nothing seems to work.

So, if anyone has something to add I would be very grateful.

Thank you!

EDIT after answer @Dropped Bass

    generator =  NetChain[
  {
   50,
   ParametricRampLayer[]
   ,
   50
   ,
   ParametricRampLayer[]
   ,
   LinearLayer[{10}]
   ,
   ReshapeLayer[{10, 1}]
   }
  ]

discriminator =  NetInitialize@
  NetChain[{GatedRecurrentLayer[1], LinearLayer[{}]}, 
   "Input" -> {10, 1}]

gan = NetGANOperator[{generator, discriminator}, 
  "Latent" -> {10, 1}]

Net Configuration

It seems correct so far and here is the sample and latent function generator as is in NetGANOperator:

MatrixQ[Table[RandomVariate[NormalDistribution[], 1], {i, 1, 10}]]
Dimensions[Table[RandomVariate[NormalDistribution[], 1], {i, 1, 10}]]
sam = Table[RandomVariate[NormalDistribution[], 1], {i, 1, 10}]
MatrixQ[sam]
Dimensions[sam]
lat = Table[RandomReal[{0, 1}, 1], {i, 1, 10}]
MatrixQ[lat]
Dimensions[lat]

Check Dimensions

 NetTrain[gan,
 Function[
  <|
   "Sample" -> sam,
   "Latent" -> lat
   |>]
 ,
 TrainingUpdateSchedule -> {"Generator", "Discriminator"},
 BatchSize -> 10,
 MaxTrainingRounds -> 100,
 TargetDevice -> {"GPU",1}
 ]

But I receive this error:

NetTrain Error

One Answer

You should make the discriminator output a real number, instead of a length-1 vector. For that, instead of using LinearLayer[1] and "Output"->"Scalar", use LinearLayer[{}] and "Output"->"Real" (or just omit specifying the Output shape).

Also, you have to make sure the Input shape of the discriminator matches the Output shape of the generator.

Answered by Dropped Bass on July 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP