0
点赞
收藏
分享

微信扫一扫

Can not squeeze dim[1], expected a dimension of 1


遇上如题所示问题,多半是因为使用了​​sparse_categorical_crossentropy​​​作为损失函数
这会出现在分类问题中,这个激活函数要求如下:

labels vector must provide a single specific index for the true class for each row of logits

也就是说,你给的真实输出值,得是一个索引index而不是one hot编码,比如你给定的真实输出值应该是0而非[1, 0, 0, 0, 0]

参考文献:

  • ​​ValueError: Can not squeeze dim[1], expected a dimension of 1, got 3 for 'sparse_softmax_cross_entropy_loss​​
  • ​​tf.keras.losses.sparse_categorical_crossentropy​​



举报

相关推荐

0 条评论