简体   繁体   English

Keras Conv1D作为第一层

[英]Keras Conv1D as first layer

Keras documentation includes this bit on the section of Conv1D Keras文档在Conv1D的部分中包含了此位

When using this layer as the first layer in a model, provide an input_shape argument (tuple of integers or None, eg (10, 128) for sequences of 10 vectors of 128-dimensional vectors, or (None, 128) for variable-length sequences of 128-dimensional vectors. 当将此层用作模型中的第一层时,请提供input_shape参数(整数元组或None,例如对于10个向量的128维向量的序列,为(10,128),对于可变长度,则为(None,128) 128维向量的序列。

I am wondering why this is required and why it is not required to provide the inputs shape elsewhere in the model. 我想知道为什么需要这样做,为什么不要求在模型的其他地方提供输入形状。

It's about how layers are connected. 关于各层如何连接。 The layers after the first layer are chained so their input shapes are equal to the output shape of the previous layer in a sequential model: 将第一层之后的层链接在一起,以便在顺序模型中它们的输入形状等于上一层的输出形状:

model.layers[i].input_shape == model.layers[i-1].output_shape

But what about the very first layer? 但是第一层呢? Since the model cannot infer what the shape should be, it asks you to provide it. 由于模型无法推断形状应该是什么,因此要求您提供它。 After the first input all the shapes can be calculated. 首次输入后,可以计算所有形状。

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

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