dhruvrajan / tensorflow-keras-java

MIT License
54 stars 9 forks source link

How do I generate output from a model? #17

Open Sciss opened 3 years ago

Sciss commented 3 years ago

In this tutorial, one step tests the untrained generator to produce a noise image:

generator = make_generator_model()
noise = tf.random.normal([1, 100])
generated_image = generator(noise, training=False)

I have this:

val generator: Model[TFloat32] = makeGeneratorModel()
val graph     = new Graph
val tf        = Ops.create(graph)
val noise     = tf.random.randomStandardNormal(tf.constant(Array(1, 100)), classOf[TFloat32])
generator.compile(tf, 
  Optimizers.select(Optimizers.sgd), 
  Losses.select(Losses.sparseCategoricalCrossentropy),
  Seq(Metrics.select(Metrics.accuracy)).asJava)
val generatedImage = ???

I don't understand how I can now get values out of the model. Do I need to call something like fetch and run on the graph, or is there a direct way in Keras?

Internally, I see I would probably need a session runner, but I see no API that calls it to generate output.

Thanks

Sciss commented 3 years ago

I believe it's just generator.apply() or generator.call(), with the difference in Keras Python that the latter takes additional arguments testing and mask.