Skip to content

Instantly share code, notes, and snippets.

@ericjang
Created July 31, 2016 22:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericjang/c7740033e0082d6c4fab7e2862d37665 to your computer and use it in GitHub Desktop.
Save ericjang/c7740033e0082d6c4fab7e2862d37665 to your computer and use it in GitHub Desktop.
alternating convolution & upsampling in TensorFlow
#!/bin/env python
# uses tf-slim from release 0.10.0
import tensorflow as tf
slim = tf.contrib.slim
batch = 13
in_height, in_width, in_channels = 7, 7, 512
x = tf.ones([batch, in_height, in_width, in_channels])
print(x.get_shape())
b,h,w,c = x.get_shape().as_list()
for i in range(3):
c /= 2
h *= 2
w *= 2
# kernel = tf.Variable(tf.truncated_normal([3, 3, in_channels, out_channels]))
# conv = tf.nn.conv2d(x, kernel, [1, 1, 1, 1], padding='SAME')
x = slim.conv2d(x,c,[3,3])
x = tf.image.resize_images(x,h,w)
print(x.get_shape())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment