2016-02-12 35 views
2

我被卡在有關CNN的錯誤上。加偏差點處的第一個卷積層上的錯誤

試圖在tensorflow上實現以下結構。

enter image description here

我寫我的代碼作爲教程(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. 

回答

0

該錯誤不是來自您顯示的代碼。看起來您正在創建多個圖表(可能是因爲ipython筆記本單元的重複調用?),並嘗試在同一計算中使用不同圖表中的內容。

+0

我怎麼知道哪個圖是哪個圖?有沒有代碼可以證明這一點? – user3768495