我正在尝试为序列数据构建卷积网络,但是Keras层Conv1D的行为不符合预期。
当我将滤波器的数量设置为> =输入通道的数量,并且扩张率> 1时,输出全为零。下面再现了我的问题。
# imports
import numpy as np
from keras.layers import Input, Conv1D
from keras.models import Model
# data prep
input_shape = (32, 256, 5) # batchsize, steps, features
test_data = np.random.randn(*input_shape)
# model structure
input_layer = Input(batch_shape=input_shape)
conv1d_layer = Conv1D(
filters=5,
kernel_size=3,
padding='causal',
data_format='channels_last',
dilation_rate=2
)(input_layer)
conv1d_model = Model(inputs=input_layer, outputs=conv1d_layer)
# weights and predictions
preds = conv1d_model.predict(test_data)
conv_weights = conv1d_model.layers[1].get_weights()[0]
'preds'的所有元素均为0,但'conv_weights'看起来很好。