ValueError: Shape mismatch: The shape of labels (received (768,)) should equal the shape of logits e
問題
運行tensorflow 的resnet網絡,預測結果,出現報錯
ValueError: Shape mismatch: The shape of labels (received (768,)) should equal the shape of logits e
原因
解決:use of sparse_softmax_cross_entropy. feed it one hot encoded labels which it doesn’t want.
Switch to just normal softmax_cross_entropy and see if that works.
這個問題是由于輸出層的類別數和訓練數據shape不同導致。
在訓練模型時,一般會將label使用one hot編碼,然后模型的loss使用交叉熵:
解決方法
Use this crossentropy loss function when there are two or more label classes. We expect labels to be provided in a one_hot representation. If you want to provide labels as integers, please use SparseCategoricalCrossentropy loss. There should be # classes floating point values per feature.
修改sparse_categorical_crossentropy為ategorical_crossentropy
?
?
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的ValueError: Shape mismatch: The shape of labels (received (768,)) should equal the shape of logits e的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深度学习 tensorflow tf.l
- 下一篇: 神经网络 深度学习 专业术语解释(Ste