tensorflow - Does tensorflow allow LSTM deconvolution ( convlstm2d) as it does for 2D convolution?
问题描述
I am trying to augment a network. For the convolution part, I am using convlstm2d from keras. Is there a process to perform deconvolution ( i.e. lstmdeconv2d ? )
解决方案
应该可以将任何模型与TimeDistributed包装器结合起来。因此,您可以创建一个反卷积模型,并使用 TimeDistributed 包装器将其应用于 LSTM 的输出(即向量序列)。
一个例子。首先使用 Conv2DTranspose 层创建一个反卷积网络。
from keras.models import Model
from keras.layers import LSTM,Conv2DTranspose, Input, Activation, Dense, Reshape, TimeDistributed
# Hyperparameters
layer_filters = [32, 64]
# Deconv Model
# (adapted from https://github.com/keras-team/keras/blob/master/examples/mnist_denoising_autoencoder.py )
deconv_inputs = Input(shape=(lstm_dim,), name='deconv_input')
feature_map_shape = (None, 50, 50, 64) # deconvolve from [batch_size, 50,50,64] => [batch_size, 200,200,3]
x = Dense(feature_map_shape[1] * feature_map_shape[2] * feature_map_shape[3])(deconv_inputs)
x = Reshape((feature_map_shape[1], feature_map_shape[2],feature_map_shape[3]))(x)
for filters in layer_filters[::-1]:
x = Conv2DTranspose(filters=16,kernel_size=3,strides=2,activation='relu',padding='same')(x)
x = Conv2DTranspose(filters=3,kernel_size=3, padding='same')(x) # last layer has 3 channels
deconv_output = Activation('sigmoid', name='deconv_output')(x)
deconv_model = Model(deconv_inputs, deconv_output, name='deconv_network')
然后,您可以使用 TimeDistributed 层将此反卷积模型应用于 LSTM 的输出。
# LSTM
lstm_input = Input(shape=(None,16), name='lstm_input') # => [batch_size, timesteps, input_dim]
lstm_outputs = LSTM(units=64, return_sequences=True)(lstm_input) # => [batch_size, timesteps, output_dim]
predicted_images = TimeDistributed(deconv_model)(lstm_outputs)
model = Model(lstm_input , predicted_images , name='lstm_deconv')
model.summary()
推荐阅读
- javascript - React JS获取数组中数字的总和
- html - Google Apps 脚本 HTML 服务功能未运行 onclick
- flutter - 缺少 InheritedWidget.updateShouldNotify 的具体实现
- postgis - Postgis 得到一个最小面积的多边形,它将覆盖所有定义的多边形
- php - 为什么 htaccess 重定向到 https://example.com/index.php 而不是特定的子 URL?
- ios - 在 ios 上使用 XMLHttpRequest 获取本地路径 uri 时出现随机网络请求失败错误
- apache-spark - 从 spark 工作节点写入 databricks 表
- python - 过滤 int、float in list、Python
- python-3.x - PackagesNotFoundError:当前频道不提供以下软件包:- ipython-notebook
- python - 如何检查一个值是否存在于列表中,并将包含它的元素存储在变量中