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

Mistake in "Scopes and when to use them" #26

Closed
MTDzi opened this issue Mar 1, 2018 · 1 comment
Closed

Mistake in "Scopes and when to use them" #26

MTDzi opened this issue Mar 1, 2018 · 1 comment

Comments

@MTDzi
Copy link

MTDzi commented Mar 1, 2018

I've tried to run the penultimate example of the "Scopes and when to use them" section like so:

image1 = tf.placeholder(tf.float32, shape=[None, 100, 100, 3])
image2 = tf.placeholder(tf.float32, shape=[None, 100, 100, 3])

features1 = tf.layers.conv2d(image1, filters=32, kernel_size=3)

# Use the same convolution weights to process the second image
with tf.variable_scope(tf.get_variable_scope(), reuse=True):
    features2 = tf.layers.conv2d(image2, filters=32, kernel_size=3)

but I got:

ValueError: Variable conv2d_1/kernel does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=tf.AUTO_REUSE in VarScope?

So I tried:

conv1_weights = tf.get_variable('conv1_w', [3, 3, 3, 64])
features1 = tf.nn.conv2d(image1, conv1_weights, strides=[1, 1, 1, 1], padding='SAME')

# Use the same convolution weights to process the second image
with tf.variable_scope(tf.get_variable_scope(), reuse=True):
    conv1_weights = tf.get_variable('conv1_w')
    features2 = tf.nn.conv2d(image2, conv1_weights, strides=[1, 1, 1, 1], padding='SAME')

and this does work (at least in terms of raising errors), but does not provide the segue to the final example (which uses tf.layers.conv2d).

Perhaps you know a way of modifying the current example so that it's runnable?

EDIT:
I should have added: my tf.__version__ is '1.6.0-rc0'

@vahidk
Copy link
Owner

vahidk commented Mar 3, 2018

Thanks for reporting this. This looks like a newly introduced bug in TensorFlow that doesn't behave well with unnamed scopes. Naming the scope should resolve this. I updated the doc.

@vahidk vahidk closed this as completed Mar 3, 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