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)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM