Python 带Lambda函数的HSTACK CNN输出
我制作了一种Python 带Lambda函数的HSTACK CNN输出,python,tensorflow,keras,conv-neural-network,lstm,Python,Tensorflow,Keras,Conv Neural Network,Lstm,我制作了一种NN,使用CNN和LSTM呈现: 在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 r
NN
,使用CNN
和LSTM
呈现:
在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)