这里出错的原因是定义的 loss 采用 sparse_softmax_cross_entropy_with_logits

loss = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=tf.argmax(labels_holder,1), logits=label_predict)

查阅 TensorFlow API:https://tensorflow.google.cn/api_docs/python/tf/losses/sparse_softmax_cross_entropy

sparse_softmax_cross_entropy_with_logits 返回:Weighted loss Tensor of the same type as logits. If reduction is NONE, this has the same shape as labels; otherwise, it is scalar.

即返回和输入标签具有相同形状的张量
 

将 tf.summary.scalar(name="loss", tensor=loss) 改为 tf.summary.histogram(name="loss", tensor=loss)

TensorFlow 报错:InvalidArgumentError (see above for traceback): tags and values not the same shape: [

相关文章: