Leopold·Lin 2020-12-04 21:21 采纳率: 0%
浏览 374

Tensorflow

Model was constructed with shape (None, 28, 28) for input Tensor("flatten_input:0", shape=(None, 28, 28), dtype=float32), but it was called on an input with incompatible shape (None, 28).

这个问题怎么解决,

  • 写回答

1条回答 默认 最新

  • 233彭于晏 2021-01-11 20:47
    关注

    这种情况一般是输入对不上,检查下tfrecorf的输入名字和input layer里面name应该有没对齐的。

    我之前也遇到同样的问题,我模型定义某个输入时写的是

    neg_item_sample_input = Input(shape=(neg_sample_num,), name="neg_item", dtype='string')

    但是我tf-record里面写的变量名字是

    feature_spec["neg_sample"] = tf.io.FixedLenFeature([], tf.string)

    这里面neg_sample 和 neg_item就没对上,导致模型在called的时候变量shape会乱掉

    附上我的当时报错信息

    WARNING:tensorflow:Model was constructed with shape (None, 1) for input Tensor("zodiac:0", shape=(None, 1), dtype=string), but it was called on an input with incompatible shape (None, 20).
    WARNING:tensorflow:Model was constructed with shape (None, 20) for input Tensor("item_id_hist:0", shape=(None, 20), dtype=string), but it was called on an input with incompatible shape (None, 1).
    WARNING:tensorflow:Model was constructed with shape (None, 1) for input Tensor("item_id:0", shape=(None, 1), dtype=string), but it was called on an input with incompatible shape (None, 10).
    WARNING:tensorflow:Model was constructed with shape (None, 10) for input Tensor("neg_item:0", shape=(None, 10), dtype=string), but it was called on an input with incompatible shape (None, 1)

    可以看到我的变量好几个shape都乱掉了,一个对不上会影响很多

    参考:https://www.cnblogs.com/oaks/p/14043877.html

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)