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

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 12: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

    评论
编辑
预览

报告相同问题?