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

tf.AUTO_REUSE work with tf.layers.conv2d #28

Closed
raytroop opened this issue Jun 20, 2018 · 1 comment
Closed

tf.AUTO_REUSE work with tf.layers.conv2d #28

raytroop opened this issue Jun 20, 2018 · 1 comment

Comments

@raytroop
Copy link

In 'Scopes and when to use them` section

with tf.variable_scope("scope", reuse=tf.AUTO_REUSE):
  features1 = tf.layers.conv2d(image1, filters=32, kernel_size=3)
  features2 = tf.layers.conv2d(image2, filters=32, kernel_size=3)

The above conv2d layer won't share weights, it seems that we have to explicitly specify name attribute of tf.layers.conv2d to share weights like,

with tf.variable_scope("scope", reuse=tf.AUTO_REUSE):
  features1 = tf.layers.conv2d(image1, filters=32, kernel_size=3, name='conv2d')
  features2 = tf.layers.conv2d(image2, filters=32, kernel_size=3, name='conv2d')

tf.version = 1.8.0

Thanks

@vahidk
Copy link
Owner

vahidk commented Jul 11, 2018

Thanks for finding this. Fixed.

Note that the reason this doesn't work is because of the counter in the variable_scope. The following should work:

with tf.variable_scope("scope", reuse=tf.AUTO_REUSE):
  features1 = tf.layers.conv2d(image1, filters=32, kernel_size=3)
  
with tf.variable_scope("scope", reuse=tf.AUTO_REUSE):
  features2 = tf.layers.conv2d(image2, filters=32, kernel_size=3)

@vahidk vahidk closed this as completed Jul 11, 2018
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