使用variable_scope
with tf.variable_scope('conv1') as scope:
kernel = _variable_with_weight_decay('weights',
shape=[5, 5, 3, 64],
stddev=5e-2,
wd=0.0)
conv = tf.nn.conv2d(images, kernel, [1, 1, 1, 1], padding='SAME')
biases = _variable_on_cpu('biases', [64], tf.constant_initializer(0.0))
bias = tf.nn.bias_add(conv, biases)
conv1 = tf.nn.relu(bias, name=scope.name)
_activation_summary(conv1)
然后使用ckpt文件保存和恢复变量。但是,在使用以下代码恢复尝试获取变量失败后。
with tf.variable_scope('conv1'):
sasa=tf.get_variable("kernel")
网络(以及上面的conv1层)来自CIFAR10示例: https://www.tensorflow.org/versions/r0.11/tutorials/deep_cnn/index.html https://github.com/tensorflow/tensorflow/tree/master/tensorflow/models/image/cifar10
编辑1:
'kernel'不起作用,但'偏见'确实有效。
with tf.variable_scope('conv1'):
sasa=tf.get_variable("biases")