2
我被卡在有关CNN的错误上。加偏差点处的第一个卷积层上的错误
试图在tensorflow上实现以下结构。
我写我的代码作为教程(Deep MNIST for Experts)shows.Defined重量和偏见的初始化如下。
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
def bias_variable(shape):
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
def conv2d(x, W):
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
而第一卷积层如下。几乎与教程相同。
with tf.name_scope('conv1') as scope:
W_conv1 = weight_variable([4, 1, 128, 256])
b_conv1 = bias_variable([256])
x_image = tf.reshape(images_placeholder, [-1,599,1,128])
print tf.Tensor.get_shape(x_image)
print tf.Tensor.get_shape(conv2d(x_image, W_conv1))
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
但是,我得到如下错误。如何解决这个错误?
File "CNN_model.py", line 43, in inference
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/math_ops.py", line 403, in binary_op_wrapper
return func(x, y, name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/gen_math_ops.py", line 44, in add
return _op_def_lib.apply_op("Add", x=x, y=y, name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/op_def_library.py", line 297, in apply_op
g = ops._get_graph_from_inputs(_Flatten(keywords.values()), graph=g)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 2879, in _get_graph_from_inputs
assert_same_graph([original_input, op_input])
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 698, in assert_same_graph
raise ValueError("Items must be from the same graph.")
ValueError: Items must be from the same graph.
我怎么知道哪个图是哪个图?有没有代码可以证明这一点? – user3768495