Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with Variable Scope #156

Closed
mandar2812 opened this issue Mar 10, 2019 · 2 comments
Closed

Problems with Variable Scope #156

mandar2812 opened this issue Mar 10, 2019 · 2 comments

Comments

@mandar2812
Copy link

After migrating DynaML code from tf-0.2.4 to tf-0.4.1 or tf-0.4.2-SNAPSHOT

Accessing variables becomes buggy.

When using the tf.variable() method

tf.variable[D]("Linear_1/Weights", shape = Shape(-1, 10), reuse = ReuseExistingOnly)

I see the following exception stack trace

java.lang.IllegalArgumentException: Variable 'Loss/ProbWeightedTS/Loss/ProbWeightedTS//Linear_1/Weights' does not exist, but variable scope re-use was set to 'ReuseExistingOnly'.
  org.platanios.tensorflow.api.ops.variables.VariableStore.getVariable(VariableStore.scala:99)
  org.platanios.tensorflow.api.ops.variables.VariableScope.$anonfun$getVariable$1(VariableScope.scala:105)
  scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
  org.platanios.tensorflow.api.ops.Op$.nameScope(Op.scala:2067)
  org.platanios.tensorflow.api.ops.variables.VariableScope.getVariable(VariableScope.scala:105)
  org.platanios.tensorflow.api.ops.variables.Variable$.getVariable(Variable.scala:508)
  org.platanios.tensorflow.api.ops.variables.package$API.variable(package.scala:86)
  org.platanios.tensorflow.api.ops.variables.package$API.variable$(package.scala:80)
  org.platanios.tensorflow.api.package$tf$.variable(package.scala:294)
  io.github.mandar2812.dynaml.tensorflow.layers.L2Regularization.$anonfun$forwardWithoutContext$1(L2Regularization.scala:45)

The string Loss/ProbWeightedTS is the name of the Loss function, in earlier versions of tf-scala (until 0.2.4) this was appended to the variable name only once, now it seems the VariableScope is being appended twice Loss/ProbWeightedTS/Loss/ProbWeightedTS//Linear_1/Weights when using tf.variable()

@eaplatanios
Copy link
Owner

@mandar2812 Was this resolved or is it still an issue that would need to be fixed in TF Scala?

@mandar2812
Copy link
Author

@eaplatanios No this does not seem to be an issue in TF Scala :)
After looking in the API, I was able to use tf.variableScope() and tf.nameScope() to my advantage.
What I currently have as a stop gap for #88 is using these two methods to access variables by name (with tf.ReuseExistingOnly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants