变量conv1 / weights / ExponentialMovingAverage /不存在,或者不是使用tf.get_variable()创建的

时间:2018-11-05 19:48:21

标签: python tensorflow deep-learning

尽管我知道这不是未知的错误消息,因为许多人在尝试使用Tensorflow最新版本中的Tensorflow 0.12.1代码时可能已经遇到了此问题。我也面临着同样的问题,并尝试了GitHub和StackOverflow中几乎所有可能的解决方案。如果你们中的任何人可以提出一些线索,我将非常有义务

Cifar10代码:

tower_grads = []
    with tf.variable_scope(tf.get_variable_scope()):
      for i in xrange(FLAGS.num_gpus):
        with tf.device('/gpu:%d' % i):
          with tf.name_scope('%s_%d' % (cifar10.TOWER_NAME, i)) as scope:
            # Dequeues one batch for the GPU
            image_batch, label_batch = batch_queue.dequeue()
            # Calculate the loss for one tower of the CIFAR model. This function
            # constructs the entire CIFAR model but shares the variables across
            # all towers.
            loss = tower_loss(scope, image_batch, label_batch)

            # Reuse variables for the next tower.
            tf.get_variable_scope().reuse_variables()

            # Retain the summaries from the final tower.
            summaries = tf.get_collection(tf.GraphKeys.SUMMARIES, scope)

            # Calculate the gradients for the batch of data on this CIFAR tower.
            grads = opt.compute_gradients(loss)

            # Keep track of the gradients across all towers.
            tower_grads.append(grads)

指数移动平均线:

# Track the moving averages of all trainable variables.
    variable_averages = tf.train.ExponentialMovingAverage(
        new_model.MOVING_AVERAGE_DECAY, global_step)
    variables_averages_op = variable_averages.apply(tf.trainable_variables())

跟踪:

File "/usr/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "model_train.py", line 395, in main
    train()
  File "model_train.py", line 316, in train
    variables_averages_op = variable_averages.apply(tf.trainable_variables())
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/training/moving_averages.py", line 403, in apply
    colocate_with_primary=True)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/training/slot_creator.py", line 117, in create_slot
    return _create_slot_var(primary, val, "", validate_shape, None, None)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/training/slot_creator.py", line 65, in _create_slot_var
    validate_shape=validate_shape)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 1467, in get_variable
    aggregation=aggregation)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 1217, in get_variable
    aggregation=aggregation)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 527, in get_variable
    aggregation=aggregation)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 481, in _true_getter
    aggregation=aggregation)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 866, in _get_single_variable
    "reuse=tf.AUTO_REUSE in VarScope?" % name)
ValueError: Variable conv1/weights/ExponentialMovingAverage/ does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=tf.AUTO_REUSE in VarScope?

0 个答案:

没有答案