卷积神经网络 Conv1d 输入形状 [英] Convolutional neural network Conv1d input shape
问题描述
我正在尝试创建一个 CNN 来对数据进行分类.我的数据是 X[N_data, N_features]我想创建一个能够对其进行分类的神经网络.我的问题是关于 keras 后端的 Conv1D 的输入形状.
I am trying to create a CNN to classify data. My Data is X[N_data, N_features] I want to create a neural net capable of classifying it. My problem is concerning the input shape of a Conv1D for the keras back end.
我想重复一个过滤器......假设有 10 个特征,然后对接下来的 10 个特征保持相同的权重.对于每个数据,我的卷积层将创建 N_features/10 个新神经元.我该怎么做?我应该在 input_shape 中放入什么?
I want to repeat a filter over.. let say 10 features and then keep the same weights for the next ten features. For each data my convolutional layer would create N_features/10 New neurones. How can i do so? What should I put in input_shape?
def cnn_model():
model = Sequential()
model.add(Conv1D(filters=1, kernel_size=10 ,strides=10,
input_shape=(1, 1,N_features),kernel_initializer= 'uniform',
activation= 'relu'))
model.flatten()
model.add(Dense(N_features/10, init= 'uniform' , activation= 'relu' ))
有什么建议吗?谢谢!
推荐答案
@Marcin 的回答可能有效,但可能会根据此处的文档提出建议:
@Marcin's answer might work, but might suggestion given the documentation here:
当将此层用作模型中的第一层时,请提供input_shape 参数(整数元组或无,例如 (10, 128) for128 维向量的 10 个向量的序列,或 (None, 128) 用于128维向量的变长序列.
When using this layer as the first layer in a model, provide an input_shape argument (tuple of integers or None, e.g. (10, 128) for sequences of 10 vectors of 128-dimensional vectors, or (None, 128) for variable-length sequences of 128-dimensional vectors.
应该是:
model = Sequential()
model.add(Conv1D(filters=1, kernel_size=10 ,strides=10,
input_shape=(None, N_features),kernel_initializer= 'uniform',
activation= 'relu'))
请注意,由于输入数据(N_Data,N_features),我们将示例数量设置为未指定(None).在这种情况下,strides
参数控制时间步长的大小.
Note that since input data (N_Data, N_features), we set the number of examples as unspecified (None). The strides
argument controls the size of of the timesteps in this case.
这篇关于卷积神经网络 Conv1d 输入形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!