2016-11-29 59 views
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层。该池4层看起来像这样[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教程为起点模型。我的local3层很大程度上依赖于教程中的图层。

回答

0

好吧,我不明白的错误,但我已经通过修改local3层

# 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()方法,因为它似乎没有记载在tho API-Reference中。