【发布时间】:2018-12-22 15:57:37
【问题描述】:
我的 data_split 文件中定义了一个 conv_net 函数,如下所示,
def conv_net(X, weights, biases, dropout):
X = tf.reshape(X, shape=[-1, HEIGHT, WIDTH, NETWORK_DEPTH])
#error occurs on the below line - while calling the function in debugging mode
conv1 = conv2d('conv1', X, weights['conv_weight1'], biases['conv_bias1'])
conv1 = maxpool2d('max_pool1', conv1, k=2)
conv2 = conv2d('conv2', conv1, weights['conv_weight2'], biases['conv_bias2'])
conv2 = maxpool2d('max_pool2', conv2, k=2)
conv3 = conv2d('conv3', conv2, weights['conv_weight3'], biases['conv_bias3'])
conv3 = maxpool2d('max_pool3', conv3, k=2)
conv4 = conv2d('conv4', conv3, weights['conv_weight4'], biases['conv_bias4'])
conv4 = maxpool2d('max_pool4', conv4, k=2)
fc1 = tf.reshape(conv4, shape=[-1, weights['fcl_weight1'].get_shape().as_list()[0]])
fc1 = tf.nn.relu(tf.add(tf.matmul(fc1, weights['fcl_weight1']), biases['fcl_bias1']))
fc1 = tf.nn.dropout(fc1, dropout)
fc2 = tf.nn.relu(tf.add(tf.matmul(fc1, weights['fcl_weight2']), biases['fcl_bias2']))
fc2 = tf.nn.dropout(fc2, dropout)
out = tf.add(tf.matmul(fc2, weights['out_weight']), biases['out_bias'], name='softmax')
return out
我在另一个这样的 .py 文件中调用这个函数,
print("Comp2")
logits = data_split.conv_net(data_split.X, data_split.weights, data_split.biases, keep_prob)
print("Comp2.0")
prediction = tf.nn.softmax(logits)
当我运行 logits 行时,这给了我一个错误。
ValueError: Tensor("conv_weight1:0", shape=(5, 5, 4, 16), dtype=float32_ref) 必须与 Tensor("Reshape_12:0", shape=(?, 100) 来自同一个图, 100, 4), dtype=float32).
我试图从这个question 得到我的答案 - 但没有任何帮助。
【问题讨论】:
-
您没有给出重现问题的完整代码。
标签: python tensorflow