所以我正在尝试建立一个cnn网络。我有一个热编码的“ scipy.sparse.coo.coo_matrix”,大小为“(109248,101)”。我需要使用给定的数据构建一个两层的conv1D模型,并与另一个LSTM层连接以进一步处理。我没有得到构建conv1D层的部分 任何帮助将不胜感激。...
我尝试使用以下方式来构建网络文档。我也尝试了功能性的方式来构建网络,但似乎我做错了
所以我尝试了这个:
from keras.layers import Conv1D
# input_tensor = Input(shape=(None, 101))
model = Sequential()
model.add(Conv1D(input_shape=(101, 1),
filters=16,
kernel_size=4,
padding='same'))
model.add(Conv1D(filters=16, kernel_size=4))
model.add(Flatten())
和这个
x_rest = Conv1D(input_shape=(101,1), filters=16, kernel_size=4, padding='same')
x2 = Conv1D(input_shape=(101,1), filters=16, kernel_size=4, padding='same')(x_rest)
out2 = Flatten()(x2)
他们似乎都不起作用
总是会出现
这样的错误层concatenate_4的输入不是符号张量。收到的类型:。全输入:[,]。该层的所有输入都应为张量。
这是我要构建的架构
Layer (type) Output Shape Param # Connected to
==================================================================================================
main_input (InputLayer) (None, 150) 0
__________________________________________________________________________________________________
rest_input (InputLayer) (None, 101, 1) 0
__________________________________________________________________________________________________
embedding_3 (Embedding) (None, 150, 300) 16873200 main_input[0][0]
__________________________________________________________________________________________________
conv1d_24 (Conv1D) (None, 99, 64) 256 rest_input[0][0]
__________________________________________________________________________________________________
lstm_3 (LSTM) (None, 150, 32) 42624 embedding_3[0][0]
__________________________________________________________________________________________________
conv1d_25 (Conv1D) (None, 97, 64) 12352 conv1d_24[0][0]
__________________________________________________________________________________________________
flatten_5 (Flatten) (None, 4800) 0 lstm_3[0][0]
__________________________________________________________________________________________________
flatten_7 (Flatten) (None, 6208) 0 conv1d_25[0][0]
__________________________________________________________________________________________________
concatenate_3 (Concatenate) (None, 11008) 0 flatten_5[0][0]
flatten_7[0][0]
__________________________________________________________________________________________________
dense_7 (Dense) (None, 1) 11009 concatenate_3[0][0]
__________________________________________________________________________________________________
dropout_3 (Dropout) (None, 1) 0 dense_7[0][0]
__________________________________________________________________________________________________
dense_8 (Dense) (None, 1) 2 dropout_3[0][0]
__________________________________________________________________________________________________
dense_9 (Dense) (None, 1) 2 dense_8[0][0]
__________________________________________________________________________________________________
main_output (Dense) (None, 1) 2 dense_9[0][0]
==================================================================================================
答案 0 :(得分:0)
您的代码的第一个版本似乎正在运行。 这是它构建的模型:
model.summary()
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_3 (Conv1D) (None, 101, 16) 80
_________________________________________________________________
conv1d_4 (Conv1D) (None, 98, 16) 1040
_________________________________________________________________
flatten_1 (Flatten) (None, 1568) 0
=================================================================
Total params: 1,120
Trainable params: 1,120
Non-trainable params: 0
_________________________________________________________________
问题似乎与您接下来要使用的LSTM层有关(尽管由于您未提供代码的这一部分,所以我无法为您提供帮助)。您可能会找到解决方法here。