我制作了一种使用 CNN
和 LSTM
的 NN
类型 here :
在 CNN
层之后,我使用 Lambda
函数将每个过滤器(在 CNN
上创建的图像)提供给一个 LSTM
,一一对应。
现在我想更改此设置,以将所有过滤器水平连接在一起提供给 LSTM。
我见过一些水平连接图像的代码,例如:
images = encoded_imgs[0,:,:,:] // eg: first output of a CNN layer
print(images[1,1,:].size)
image=images[:,:,0]
for i in range(1,10):
image=hstack((image,images[:,:,i]))
但是我如何将其应用于 lambda 函数来更改我的示例以将所有内容输入到一个 LSTM
中?
最佳答案
好吧,我设法在 lambda 函数之后使用 merge concat axis 2 来“个性化”每个“过滤后的图像”
conv2=Conv2D(filters,(3,3), padding="same")(conv1)
conv2=AveragePooling2D(pool_size=(2, 1), strides=(1, 1))(conv2)
conv2=Activation("relu")(conv2)
channels=Dropout(0.40)(conv2)
filtersVec=[]
for x in range(0,filters):
filterImg=Lambda(lambda element : element[:,x,:,:])(channels)
filtersVec.append(filterImg)
merged = merge(filtersVec, mode='concat',concat_axis=2)
lstm=Bidirectional(LSTM(20),merge_mode='concat',dropout=0.35)(merged)
classificationLayer=Dense(classes)(lstm)
classificationLayer=Activation("softmax")(classificationLayer)
关于python - 具有 Lambda 函数的 HSTACK CNN 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48831893/