日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2025/3/21 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ValueError: Shape mismatch: The shape of labels (received (768,)) should equal the shape of logits e 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

問題

運行tensorflow 的resnet網(wǎng)絡(luò),預(yù)測結(jié)果,出現(xiàn)報錯

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.
這個問題是由于輸出層的類別數(shù)和訓(xùn)練數(shù)據(jù)shape不同導(dǎo)致。
在訓(xùn)練模型時,一般會將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

?

?

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的ValueError: Shape mismatch: The shape of labels (received (768,)) should equal the shape of logits e的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。