0

在我成功训练模型后,使用 freeze_graph.py 导出图形并使用 bazel 使用自定义的 /tensorflow/examples/label_image/main.cc 构建它,我收到以下运行时错误。

Running model failed: Invalid argument: Matrix size-compatible: In[0]: [150,4],
In[1]: [600,36][[Node: local3/MatMul = MatMul[T=DT_FLOAT, transpose_a=false,
transpose_b=false, _device="/job:localhost/replica:0/task:0/cpu:0"(local3/Reshape,
local3/weights/read)]]

我很困惑,因为前面的所有步骤都成功了,我想知道 [150, 4]。我的 batch_size 是 150,4 是类的数量,但为什么这个张量是我本地层中 matmul 操作的输入?此代码显示 local3 层。pool4 层看起来像这样 [150x10x10x6]

# local3
with tf.variable_scope('local3') as scope:
    # Move everything into depth so we can perform a single matrix multiply.
    reshape = tf.reshape(pool4, [FLAGS.batch_size, -1])
    dim = reshape.get_shape()[1].value
    weights = _variable_with_weight_decay('weights', shape=[dim, 36], stddev=0.04, wd=0.0004)
    biases = _variable_on_cpu('biases', [36], tf.constant_initializer(0.1))
    local3 = tf.nn.relu(tf.matmul(reshape, weights) + biases, name=scope.name)

对于模型,我使用了 tensorflow 的 cifar10-tutorial 作为起点。我的 local3 层非常依赖于教程中的层。

4

1 回答 1

0

好的,我不明白这个错误,但我已经通过修改 local3-Layer 解决了它

# local3
with tf.variable_scope('local3') as scope:
    # Move everything into depth so we can perform a single matrix multiply.
    weights = _variable_with_weight_decay('weights', shape=[600, 36],
                                          stddev=0.04, wd=0.0004)
    biases = _variable_on_cpu('biases', [36], tf.constant_initializer(0.1))

    dense1 = tf.reshape(pool4, [-1, weights.get_shape().as_list()[0]])
    local3 = tf.nn.relu_layer(dense1, weights, biases)   # Relu activation
    _activation_summary(local3)

我在这个 repo 中看到了本地层定义 https://github.com/HamedMP/tensorflow_export_cpp_example

我想知道 tf.nn.relu_layer() 方法,因为它似乎没有记录在 API-Reference 中。

于 2016-12-02T09:20:23.647 回答