dkk
dkk

Reputation: 31

Upsampling 5-D tensor in TensorFlow

My target is 3D medical image.

For 4-D tensor B with shape [batch, height, width, channels] use tf.image.resize_* for upsampling.

For 5-D tensor A with shape [batch, height, width, depth, channels], for example to upsample to shape [batch, 1.5*height, 1.5*width, 1.5*depth, channels], tf.nn.conv3d_transpose can be used for upsampling, but I don't want extra weights for training.

Is there a direct op for 5-D tensor's upsampling in tensorflow?

Upvotes: 3

Views: 1321

Answers (1)

maxwk law
maxwk law

Reputation: 31

You can use tf.constant to supply filter to conv3d_transpose. It won't incur any additional weights for training. You can also use one extra pass of conv3d using the same constant filter for bilinear interpolation upsample. The example below is a function I used for 3D tensor (in 5D format) upsampling using bilinear interpolation.

def upsample(input, upsamplescale, channel_count):
    deconv = tf.nn.conv3d_transpose(value=input, filter=tf.constant(np.ones([upsamplescale,upsamplescale,upsamplescale,channel_count,channel_count], np.float32)), output_shape=[1, xdim, ydim, zdim, channel_count],
                                strides=[1, upsamplescale, upsamplescale, upsamplescale, 1],
                                padding="SAME", name='UpsampleDeconv')
    smooth5d = tf.constant(np.ones([upsamplescale,upsamplescale,upsamplescale,channel_count,channel_count],dtype='float32')/np.float32(upsamplescale)/np.float32(upsamplescale)/np.float32(upsamplescale), name='Upsample'+str(upsamplescale))
    print('Upsample', upsamplescale)
    return tf.nn.conv3d(input=deconv,
                 filter=smooth5d,
                 strides=[1, 1, 1, 1, 1],
                 padding='SAME',
                 name='UpsampleSmooth'+str(upsamplescale))    

Upvotes: 3

Related Questions