def upsample2x(name, x): """ Nearest neighbor up-sampling """ return FixedUnPooling( name, x, 2, unpool_mat=np.ones((2, 2), dtype='float32'), data_format='channels_first')
def upsample2x(name, x): dtype_str = 'float16' if fp16 else 'float32' return FixedUnPooling(name, x, 2, unpool_mat=np.ones((2, 2), dtype=dtype_str), data_format='channels_first')
def upsample2x(name, x): return FixedUnPooling( name, x, 2, unpool_mat=np.ones((2, 2), dtype='float32'), data_format='channels_first')
def upsample2x(name, x): try: resize = tf.compat.v2.image.resize_images with tf.name_scope(name): shp2d = tf.shape(x)[2:] x = tf.transpose(x, [0, 2, 3, 1]) x = resize(x, shp2d * 2, 'nearest') x = tf.transpose(x, [0, 3, 1, 2]) return x except AttributeError: return FixedUnPooling( name, x, 2, unpool_mat=np.ones((2, 2), dtype='float32'), data_format='channels_first')
d4 = tf.stop_gradient(d4) if freeze else d4 d4 = Conv2D('conv_bot', d4, 1024, 1, padding='same') return [d1, d2, d3, d4] def atrous_spatial_pyramid_pooling(x, filters=64): """ ASPP layer: Dilated convolutions with rate tau = (6,12,18) """ pad = 'valid' with tf.variable_scope('ASSP_layers'): image_level_features = tf.reduce_mean(x, [2, 3], keep_dims=True) image_level_features = Conv2D('image_level_features', image_level_features, filters, 1, strides=1, padding=pad, activation=BNReLU) image_level_features = FixedUnPooling('unp_image_level_features', image_level_features, shape=(x.shape[2].value, x.shape[3].value), data_format='channels_first') at_pool1x1 = Conv2D('at_pool1x1', x, filters, 1, strides=1, padding=pad, activation=BNReLU) at_pool3x3_1 = Conv2D('at_pool3x3_1', x, filters, 3, strides=1, padding='same', activation=BNReLU, dilation_rate=6) at_pool3x3_2 = Conv2D('at_pool3x3_2', x, filters, 3, strides=1, padding='same', activation=BNReLU, dilation_rate=12) at_pool3x3_3 = Conv2D('at_pool3x3_3', x, filters, 3, strides=1, padding='same', activation=BNReLU, dilation_rate=18) net = tf.concat((image_level_features, at_pool1x1, at_pool3x3_1, at_pool3x3_2, at_pool3x3_3), axis=1) net = Conv2D('at_out', net, filters, 1, strides=1, padding=pad, activation=BNReLU) return net def decoder(name, i, use_assp=True): pad = 'same' #Change to valid if non local
def upsample2x(x): # TODO may not be optimal in speed or math return FixedUnPooling(x, 2, data_format='channels_first')