Does tensorflow allow LSTM deconvolution ( convlstm2d) as it does for 2D convolution?

徘徊边缘 提交于 2021-02-10 15:02:13

问题


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


回答1:


There is Conv3D for that, checkout this example used to predict the next frame




回答2:


It should be possible to combine any model with the TimeDistributed wrapper. So you can create a deconv-model, and apply it on the output (which is a sequence of vectors) of the LSTM using the TimeDistributed wrapper.

An example. First create a deconv network using Conv2DTranspose layers.

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

Then, you can apply this deconv-model to the outputs of your LSTM using the TimeDistributed layer.

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


来源:https://stackoverflow.com/questions/50186108/does-tensorflow-allow-lstm-deconvolution-convlstm2d-as-it-does-for-2d-convolu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!