导出和构建张量流图后出错

时间:2016-11-29 21:51:27

标签: tensorflow tensorflow-serving

在我成功训练模型后,使用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层几乎完全依赖于教程中的图层。

1 个答案:

答案 0 :(得分: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)

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

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