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

通過網上查找,找到了問題所在:在使用keras編程模式是,中間插入了tf.reshape()方法便遇到此問題。 編程

解決辦法:對於遇到相同問題的任何人,能夠使用keras的Lambda層來包裝張量流操做,這是我所作的:spa

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)
相關文章
相關標籤/搜索