InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 10 for metrics/acc/
報錯代碼顯示:
InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 10 for ‘metrics/acc/Squeeze’ (op: ‘Squeeze’) with input shapes: [?,10].
錯誤原因:
使用稀疏分類交叉熵的損失函數,模型的真實輸出值得是一個索引index而不是one hot編碼,比如你給定的真實輸出值應該是0而非[1, 0, 0, 0, 0]
解決辦法
1 修改損失函數為:loss=‘categorical_crossentropy’,
2 還有一種就是將one-hot編碼轉換為索引index。
參考文章:
https://blog.csdn.net/qq_32623363/article/details/104183117?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.nonecase
https://blog.csdn.net/zhangpeterx/article/details/89290303?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159118576519195162519650%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=159118576519195162519650&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v2~pc_rank_v3-1-89290303.first_rank_ecpm_v2_pc_rank_v3&utm_term=InvalidArgumentError%3A+Can+not+
總結
以上是生活随笔為你收集整理的InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 10 for metrics/acc/的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 百度地图线路规划问题
- 下一篇: R语言Prod函数