问题

运行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

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

  1. 成功解决IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (100,)

    成功解决IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (100,) 目 ...

  2. Cannot copy param 0 weights from layer 'fc6'; shape mismatch.

    问题: Cannot copy param 0 weights from layer 'fc6'; shape mismatch. Source param shape is 4096 9216 (3 ...

  3. 超分辨率分割SLIC算法实现过程遇到的问题,shape mismatch: value array of shape (3,) could not be broadcast to indexing

    超分辨率分割SLIC算法实现过程遇到的问题 shape mismatch: value array of shape (3,) could not be broadcast to indexing r ...

  4. size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([9

    1. 报错 RuntimeError: Error(s) in loading state_dict for FasterRCNN: size mismatch for roi_heads.box_p ...

  5. ValueError: mode mismatch

    项目场景:PIL库Image模块处理数组合并成3通道RGB图像 项目中,使用Pytorch的torch.utils.data.DataLoader加载自己准备好的数据集.同时想要直观查看或验证生成的数 ...

  6. valueError: Length mismatch: Expected axis has 40 elements, new values have 38 elements

    背景 我拿原来的模型准备跑一个新数据集,当然列就会不同 新数据集没有head,我就自己傻乎乎一个一个数的列数(应该是数错了 我原来数的38其实是40) 就报了valueError: Length mi ...

  7. 成功解决 ValueError: feature_names mismatch training data did not have the following fields

    成功解决 ValueError: feature_names mismatch training data did not have the following fields 目录 解决问题 解决思路 ...

  8. 编写一个抽象类Shape,声明计算图形面积的抽象方法。再分别定义Shape的子类Circle(圆)和Rectangle(矩形),在两个子类中按照不同图形的面积计算公式,实现Shape类中计算面积的方法

    编写一个抽象类Shape,声明计算图形面积的抽象方法.再分别定义Shape的子类Circle(圆)和Rectangle(矩形),在两个子类中按照不同图形的面积计算公式,实现Shape类中计算面积的方法 ...

  9. Check failed: top_shape[j] == bottom[i]-shape(j) (1 vs. 2) All inputs must have the same shape, exc

    在运行ShuffleNet的过程中碰到了如下报错 : I1018 19:26:19.104892 3548 net.cpp:84] Creating Layer resx13_concat I1018 ...

最新文章

  1. Skype for Business Server 2015-07-边缘服务器-3-部署
  2. 算法:枚举法---kotlin
  3. Linux服务器通过LVM扩展其磁盘空间
  4. AE After Effect 如何分段渲染
  5. 为什么每个请求都要有用户名密码呢,那不是每次都要查询一下了,token,表示这个用户已经验证通过了,在token有效期内,只需要判断token是否有效就可以了...
  6. 菜鸟教程-css学习笔记
  7. java编写记事本程序出现图形,高手帮忙啊,老师布置了一个作业,要用java编写一个记事本程序...
  8. ubuntu14.04上网问题
  9. keras报错ModuleNotFoundError: No module named ‘keras.backend.tensorflow_backend‘;
  10. php private ,public protected三者的区别
  11. c语言的适当大小的子集,使用直接分析法编制C语言子集的词法分析程序..doc
  12. VC++2010下载教程
  13. Linux在Ubuntu下安装TFTP
  14. 知识图谱构建(概念,工具,实例调研)
  15. MySQL学习笔记(二)
  16. 电脑中病毒所有html文件,文件夹全部变成exe文件该怎么办?电脑中了kiss病毒的两种解决办法...
  17. 验证OpenVino时,找不到指定模块的解决
  18. iOS Mac Catalyst
  19. MySQL5.6建索引时遇到 Specified key was too long; max key length is 767 bytes错误提示解决办法
  20. The Thirty-fifth Of Word-Day

热门文章

  1. 决策树--从原理到实现
  2. 语言检测工具-langid
  3. 日调度5万亿次,腾讯云微服务架构体系TSF深度解读
  4. Kafka设计解析(三):Kafka High Availability (下)--转
  5. 今天犯的一个错误,导致method GET must not have a request body
  6. 信用评分卡模型开发及评估指标
  7. 【采用】风控老客户续贷业务知识
  8. 本周看代码找bug总结
  9. 云宇宙iwemeta: 亚马逊全面进军元宇宙
  10. 老夫疗法少年狂:微软中国CTO黎江:不要给区块链贴标签,也不要非黑即白区分谁是好人谁是坏人