日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

ValueError: Shape mismatch: The shape of labels (received (768,)) should equal the shape of logits e

發布時間:2025/3/21 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。