tf.keras.layers中的转置卷积

时间:2019-03-15 21:08:59

标签: tensorflow keras

如何将该函数转换为等效的tf.keras(Tensorflow 2.0)实现?

def deconv2d(inputs,out_channels, name=None):
batch, in_height, in_width, in_channels = [int(d) for d in inputs.get_shape()]
filter = tf.get_variable(name + "filter", [4, 4, out_channels, in_channels], initializer= tf.variance_scaling_initializer())
return tf.nn.conv2d_transpose(inputs, filter, [batch, in_height * 2, in_width * 2, out_channels], strides=[1,2,2,1],
                             padding='SAME', name= name)

1 个答案:

答案 0 :(得分:0)

TensoFlow 2.0具有tf.keras.layers.Conv2DTranspose。 Keras是TF 2.0的默认高级API,但对于低级应用程序仍然具有tf.nn.conv2d_transpose

https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/keras/layers/Conv2DTranspose