python - 具有 Lambda 函数的 HSTACK CNN 输出

标签 python tensorflow keras conv-neural-network lstm

我制作了一种使用 CNNLSTMNN 类型 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/

相关文章:

python - 我应该使用哪个语句来替换创建虚拟变量的自定义函数以提高 python 中的速度?

Python psutil memory_info 上限为 4.0G

machine-learning - 使用 TensorFlow 1.2.1 和 InceptionV3 对图像进行分类

python - 虚拟环境中无法导入 Keras

Keras-无法创建TensorBoard目录

Python 将字节拆分为高半字节和低半字节

python - pickle scipy 的 SuperLU 类用于不完全 LU 分解

python - 在 TF 2.0 上设置随机种子

python - 无法为占位符张量提供值

python - 重命名失败;访问被拒绝的 Tensorflow