简体   繁体   English

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

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

So, I noticed this strange behavior of Flatten layer of Keras. I'm using TF1.15 and Keras 2.3.0.所以,我注意到 Keras Flatten 层的这种奇怪行为。我使用的是 TF1.15 和 Keras 2.3.0。

Basically the output of the Flatten layer has an unknown shape.基本上 Flatten 层的 output 形状未知。 It's hard to troubleshoot the model when you can't keep track of the shape.当您无法跟踪形状时,很难对 model 进行故障排除。 Why is this happening with Flatten layer, and can I do something so it recognizes the shape?为什么 Flatten 层会发生这种情况,我可以做些什么让它识别形状吗?

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

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

Try using tf.keras instead of just keras :尝试使用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.

相关问题 Keras 模型输出形状为“(无,)” - Keras Model output shape is "(None,)" Keras 密集输入大小错误,展平返回(无,无) - Keras dense input size error, flatten returns (None, None) 在Keras自定义层中连接形状(None,m)的多个LSTM输出 - Concatenate multiple LSTM outputs of shape (None, m) in Keras custom layer Keras LSTM ValueError:层“顺序”的输入 0 与层不兼容:预期形状 =(无,478405,33),找到形状 =(1、33) - Keras LSTM ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 478405, 33), found shape=(1, 33) 你能用“无”获得神经网络层的输出形状吗? - Can you get Output Shape of Neural Network layer with 'None'? Keras:计算模型输出与输入返回的导数[无] - Keras: calculating derivatives of model output wrt input returns [None] Keras中的Flatten()层具有可变的输入形状 - Flatten() Layer in Keras with variable input shape Tensorflow / Keras ValueError:层“模型”的输入 0 与层不兼容:预期形状=(无,224,224,3),发现形状=(32,224,3) - Tensorflow / Keras ValueError: Input 0 of layer "model" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(32, 224, 3) 如何定义 2 个 keras 形状层的 Kronecker 产品层(无,4096)被执行? - How to define Kronecker product layer of 2 keras layers of shape (None, 4096) is performed? 改变 Keras 层 Output 形状 - Changing Keras Layer Output Shape
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM