`scope.reuse_variables ()` не работает при попытке повторно использовать вес модели

michael спросил: 03 февраля 2018 в 12:33 в: tensorflow

Я работаю над примером набора цветов в тонком ноутбуке walkthough и пытается повторно использовать общие веса для модели

def my_cnn(images, num_classes, is_training):  # is_training is not used...
    with slim.arg_scope([slim.max_pool2d], kernel_size=[3, 3], stride=2):
        net = slim.conv2d(images, 64, [5, 5])
        net = slim.max_pool2d(net)
        net = slim.conv2d(net, 64, [5, 5])
        net = slim.max_pool2d(net)
        net = slim.flatten(net)
        net = slim.fully_connected(net, 192)
        net = slim.fully_connected(net, num_classes, activation_fn=None)       
        return net...with tf.variable_scope("model") as scope:
  logits = my_cnn(images, num_classes=dataset.num_classes, is_training=True)
  scope.reuse_variables()
  val_logits = my_cnn(val_images, num_classes=dataset.num_classes, is_training=False)

, но когда я пытаюсь запустить этот сеанс, я все еще получите эту ошибку:

<ipython-input-49-15390a9fff86> in <module>()
     21       logits = my_cnn(images, num_classes=dataset.num_classes, is_training=True)
     22       scope.reuse_variables()
---> 23       val_logits = my_cnn(val_images, num_classes=dataset.num_classes, is_training=False)
     24 
     25     # Specify the `train` loss function:
...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variable_scope.py in _get_single_variable(self, name, shape, dtype, initializer, regularizer, partition_info, reuse, trainable, collections, caching_device, validate_shape, use_resource, constraint)
    763       raise ValueError("Variable %s does not exist, or was not created with "
    764                        "tf.get_variable(). Did you mean to set "
--> 765                        "reuse=tf.AUTO_REUSE in VarScope?" % name)
    766     if not shape.is_fully_defined() and not initializing_from_value:
    767       raise ValueError("Shape of a new variable (%s) must be fully defined, "ValueError: Variable model/Conv_2/weights does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=tf.AUTO_REUSE in VarScope?

0 ответов