简体   繁体   English

如何在喀拉拉邦创建功能性的CONV1D图层?

[英]How to create a functional CONV1D layer in keras?

So i'm trying to build a cnn network. 因此,我正在尝试建立一个CNN网络。 I have one hot encoded "scipy.sparse.coo.coo_matrix" of size "(109248, 101)". 我有一个热编码的“ scipy.sparse.coo.coo_matrix”,大小为“(109248,101)”。 I need to build a two layer conv1D model with the given data and concatenate with another LSTM layer to process further.I am not getting the part to build the conv1D layers Any help would be appreciated.... 我需要使用给定的数据构建一个两层的conv1D模型,并与另一个LSTM层连接以进行进一步处理。我没有准备构建conv1D层的任何部分。

I have tried the documentation using the following way to build the network.Also i have tried the functional way to build the network but it seems like i'm doing it wrong 我尝试使用以下方式构建网络文档。我也尝试了功能性方式构建网络,但似乎我做错了

So i tried this: 所以我尝试了这个:

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())

and This 和这个

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)

Either of them Don't seem to work 他们两个似乎都不起作用

There is always throws up error like 总是会抛出错误,例如

Layer concatenate_4 was called with an input that isn't a symbolic tensor. 层concatenate_4的调用不是符号张量。 Received type: . 收到的类型:。 Full input: [, ]. 全输入:[,]。 All inputs to the layer should be tensors. 该层的所有输入应为张量。

This is the architecture i'm trying to build 这是我要建立的架构

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]                    
==================================================================================================

The first version of your code seems to be working. 您的代码的第一个版本似乎正在运行。 Here is the model it builds: 这是它构建的模型:

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
_________________________________________________________________

It seems that the problem is related to the LSTM layer you want yo use next (though I cannot help you since you did not provide this part of the code). 看来问题与您接下来要使用的LSTM层有关(尽管由于您未提供代码的这一部分,所以我无法为您提供帮助)。 You may find a solution here . 您可以在此处找到解决方案。

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

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