繁体   English   中英

Keras 展平层返回 output 形状(无,无)

[英]Keras Flatten layer returns output shape (None, None)

所以,我注意到 Keras Flatten 层的这种奇怪行为。我使用的是 TF1.15 和 Keras 2.3.0。

基本上 Flatten 层的 output 形状未知。 当您无法跟踪形状时,很难对 model 进行故障排除。 为什么 Flatten 层会发生这种情况,我可以做些什么让它识别形状吗?

from keras.layers import Flatten
inputs = Input(shape=(3,2,4))
prediction = Flatten()(inputs)
print(inputs.shape, prediction.shape)

(?, 3, 2, 4) (?, ?)

尝试使用tf.keras而不仅仅是keras

import tensorflow as tf
print(tf.__version__)
inputs = tf.keras.layers.Input(shape=(3,2,4))
prediction = tf.keras.layers.Flatten()(inputs)
print(inputs.shape, prediction.shape)
1.15.2
(?, 3, 2, 4) (?, 24)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM