【问题标题】:Error on the first convolution layer at the point of plus biases第一个卷积层在正偏差点的误差
【发布时间】:2016-02-12 09:10:12
【问题描述】:

我被关于 CNN 的错误困住了。

尝试在tensorflow上实现如下结构。

我按照教程 (Deep MNIST for Experts) 所示编写了代码。定义的权重和偏差初始化如下。

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.

【问题讨论】:

    标签: python tensorflow deep-learning


    【解决方案1】:

    该错误不是来自您显示的代码。看起来您正在创建多个图表(可能是因为重复调用 ipython 笔记本单元?)并尝试在同一计算中使用来自不同图表的内容。

    【讨论】:

    • 我怎样才能从哪个图表中分辨出哪个东西?有代码可以显示吗?
    猜你喜欢
    • 2016-02-01
    • 2021-02-28
    • 1970-01-01
    • 2016-05-02
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多