eaplatanios / tensorflow_scala

TensorFlow API for the Scala Programming Language
http://platanios.org/tensorflow_scala/
Apache License 2.0
939 stars 95 forks source link

No way to switch / reset default graph #155

Closed Spiess closed 5 years ago

Spiess commented 5 years ago

In Python TensorFlow there are graph management functions to be able to reset and switch graphs around to allow using multiple different graphs within the same process. I haven't been able to find these functions in TensorFlow Scala and assume that they are not yet implemented.

The specific functions I am missing are tf.reset_default_graph and tf.Graph.as_default.

Are these already implemented in TensorFlow Scala and I've just missed them? Or would it be possible to implement them in TensorFlow Scala?

eaplatanios commented 5 years ago

You just use:

val newGraph = tf.Graph()
tf.createWith(graph = newGraph) {
  // Put everything that needs to go in newGraph here.
}
Spiess commented 5 years ago

Perfect, thank you, this is exactly what I need!

And just in case someone else looking for the same thing finds this issue: tf.Graph() doesn't work for me, but just Graph() does.