def join_block(self, x, y, name): with tf.variable_scope(name): x_dim = x.get_shape().as_list()[1:3] scaled = tf.image.resize_images( y, x_dim[0], x_dim[1], method=tf.image.ResizeMethod.NEAREST_NEIGHBOR) x_norm = get_norm(x) y_norm = get_norm(scaled) return tf.concat(3, [x_norm, y_norm], name="concat")
def conv_block(self, bottom, n, S, stride, name, relu=True): """ conv -> bias -> (norm -> relu | nop) -> out """ with tf.variable_scope(name): if n > 1 and self.is_training: pad = n // 2 bottom = tf.pad(bottom, [[0, 0], [pad, pad], [pad, pad], [0, 0]], "REFLECT") C = bottom.get_shape().as_list()[-1] filt = self.get_conv_filter(n, C, S, name) if self.is_training: conv = tf.nn.conv2d(bottom, filt, [1, stride, stride, 1], padding='VALID') else: conv = tf.nn.conv2d(bottom, filt, [1, stride, stride, 1], padding='SAME') conv_biases = self.get_bias(name, S) bias = tf.nn.bias_add(conv, conv_biases) if relu: norm = get_norm(bias) return tf.nn.relu(norm) else: return bias
def deconv_block(self, bottom, n, S, stride, name): """ AKA convolutional transpose """ with tf.variable_scope(name): b, h, w, C = bottom.get_shape().as_list() filt = self.get_conv_filter(n, S, C, name) deconv = tf.nn.conv2d_transpose(bottom, filt, [b, h * stride, w * stride, S], [1, stride, stride, 1], padding='SAME') biases = self.get_bias(name, S) bias = tf.nn.bias_add(deconv, biases) norm = get_norm(bias) return tf.nn.relu(norm)
def get_residual(self, bottom, name, S=3): with tf.variable_scope(name): _, _, _, C = bottom.get_shape().as_list() conv = self.conv_block(bottom, S, C, 1, "%s-a" % name) return bottom + get_norm( self.conv_block(conv, S, C, 1, "%s-b" % name, relu=False))