我以前没用过膨胀,但我用的是基于卷积的自动编码器。下面是一个采用输入大小28x28x1(如mnist图像)的体系结构示例。使用步幅为2时,尺寸将缩小到14x14x1,然后降至7x7x1。然后将其展平,然后减小到32,即编码大小。之后,一组跨距为2的转置卷积层将使大小恢复到28x28x1。在
下面是代码示例:def autoencoder_network(x):
encoder_14 = tf.layers.conv2d(x, filters=1, kernel_size=3, strides=2, padding='same', activation=tf.nn.relu)
encoder_7 = tf.layers.conv2d(encoder_14, filters=1,kernel_size=3, strides=2, padding='same', activation=tf.nn.relu)
flatten_dim = np.prod(encoder_7.get_shape().as_list()[1:])
flat = tf.reshape(encoder_7, [-1, flatten_dim])
code = tf.layers.dense(flat, 32, activation=tf.nn.relu)
hidden_decoder = tf.layers.dense(code, flatten_dim, activation=tf.nn.relu)
decoder_7 = tf.reshape(hidden_decoder, [-1, 7, 7, 1])
decoder_14 = tf.layers.conv2d_transpose(decoder_7, 1, 3, strides=2, padding='same', activation=tf.nn.relu)
output = tf.layers.conv2d_transpose(decoder_14, 1, 3, strides=2, padding='same', activation=tf.nn.relu)
return code, output