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

這裏出錯的原因是定義的 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)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章