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

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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么