Reputation: 591
I'm working on using multi-GPU tower defs on my work, but it seems to have errors: too big losses and not updated.
I think the problems are come from the code below:
# Calculate the gradients for each model tower.
tower_grads = []
for i in xrange(num_gpus):
with tf.device('/gpu:%d' % i):
with tf.name_scope('%s_%d' % (TOWER_NAME, i)) as scope:
loss = tower_loss(scope)
####### HERE #######
# Reuse variables for the next tower.
tf.get_variable_scope().reuse_variables()
####################
grads = opt.compute_gradients(loss)
tower_grads.append(grads)
print(tf.get_variable_scope().reuse_variables())
prints None
.
What's the problem do you think?
I set the variable_scope only with CONV1, CONV2, FC3, FC4 in INFERENCE just like in cifar10_multi_gpu_train.py
.
Upvotes: 1
Views: 4929
Reputation: 7130
Please refer to the source code, as you can see it has no return. Thus what you can get and print out is just None. Here is the relevant snippet:
def reuse_variables(self):
"""Reuse variables in this scope."""
self._reuse = True
Actually, it just switches the _reuse on.
Upvotes: 0
Reputation: 28198
There is no problem in your code, at least not with tf.get_variable_scope().reuse_variables()
.
The function reuse_variables()
will always produce None
as a result. Its only function is to set the attribute reuse
of the current scope to True
.
I think you mistake it with a function that would return all the variables in the current scope.
Upvotes: 4