tf.keras遇见的坑:Output tensors to a Model must be the output of a TensorFlow `Layer`

经过网上查找,找到了问题所在:在使用keras编程模式是,中间插入了tf.reshape()方法便遇到此问题。 

解决办法:对于遇到相同问题的任何人,可以使用keras的Lambda层来包装张量流操作,这是我所做的:

embed1 = keras.layers.Embedding(10000, 32)(inputs)
 
# embed = keras.layers.Reshape(-1,256, 32, 1)(embed1)
# embed = tf.reshape(embed1, [-1, 256, 32, 1])
def reshapes(embed1):
    embed = tf.reshape(embed1, [-1, 256, 32, 1])
    return embed
embed = keras.layers.Lambda(reshapes)(embed1)
原文地址:https://www.cnblogs.com/jqpy1994/p/11433746.html