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