0
votes

I am just using TensorFlow to realise a CNN model called DVF: https://github.com/liuziwei7/voxel-flow.

The output of the model is 'deconv4' with the shape of [batch_size, 256, 256,3], then I need to extract optical flow using command:'flow = tf.slice(deconv4.outputs, [0,0,0,0], [batch_size, 256, 256, 2])'.

However, if the 'batch_size' is 'None', how do I slice the 'flow' tensor?

Thanks in advance.

The shape of 'deconv4' is [?,256,256,3] and I want to obtain the 'flow' with the shape of [?,256,256,2] from the 'deconv4'.

deconv4 = Conv2d(deconv3_bn_relu, 3, [5, 5], act=tf.tanh, padding='SAME', W_init=w_init, name='deconv4')

    #################### Calculate Voxel Flow based on the 'deconv4' ############################
    flow = tf.slice(deconv4.outputs, [0,0,0,0], [batch_size, 256, 256, 2])

The shape of 'flow' should be [?, 256,256,2]. But I am not sure how to obtain it.

1
For any dimension you want to be dynamic you can use None. - ARAT
@ARAT Thanks for your help. I tried to use 'None' in 'tf.slice', but I noticed that I could not directly replace the 'batch_size' with 'None', otherwise, it returns an error. Do you have any idea about this? - Dee Ma

1 Answers

0
votes

You should be able to replace your batch_size with None and that should do the trick.

Alternatively, this: tf.shape(x)[0] will give you a variable tensor with your batch size.