我是张力流新手。我想构建一个vgg-16网络,然后用它来修改网络。
到目前为止,我在第1层被困在这里是我所拥有的:
def conv_layer(bottom, name, kernel):
with tf.variable_scope(name):
#net weight dictionary from caffe's version of caffe
conv = tf.nn.conv2d(net.weights[name+'/w'], kernel, [1, 1, 1, 1], padding='SAME')
conv_biases = tf.constant(net.weights[name+'/b'], name="biases")
bias = tf.nn.bias_add(conv, conv_biases)
relu = tf.nn.relu(bias)
return relu
kernel1_1= tf.Variable(tf.truncated_normal([3, 3, 3, 64], dtype=tf.float32, stddev=1e-1), name='weights')
conv_layer(tf.cast(image_batch, tf.float32), "conv1_1", kernel1_1)
我得到的错误是:
Dimensions must be equal, but are 64 and 3 for 'conv1_1_15/Conv2D' (op: 'Conv2D') with input shapes: [3,3,3,64], [3,3,3,64]
这对我来说毫无意义
答案 0 :(得分:0)
我不确定net.weights包含什么,但假设你的内核有权重,在我看来你应该将它们分配给内核变量。
conv = tf.nn.conv2d(net.weights[name+'/w'], kernel, [1, 1, 1, 1], padding='SAME')
应该是
conv = tf.nn.conv2d(bottom, kernel, [1, 1, 1, 1], padding='SAME')
一旦完成网络定义,就可以将权重分配给内核和偏差。