How to resize 5D samples in keras?

Currently, for 5D data (batch_size, h, w, depth, channel), the tf.keras.backend.resize_volumes or UpSampling3D can be used to upsampling purpose. For example, I can do

a  = tf.ones(shape=(1, 100, 100, 64, 1))

tf.keras.backend.resize_volumes(
       a, depth_factor=2, 
       height_factor=2, 
       width_factor=2, 
       data_format="channels_last").shape
TensorShape([1, 200, 200, 128, 1])

These factor values (above) should be an integer. https://github.com/keras-team/keras/blob/master/keras/backend.py#L3441-L3444 - in that case, how can I downsample the input sample, ie.

a  = tf.ones(shape=(1, 100, 100, 64, 1))

tf.keras.backend.resize_volumes(
       a, depth_factor=0.5, 
       height_factor=0.5, 
       width_factor=0.5 
       data_format="channels_last").shape

TypeError: 'float' object cannot be interpreted as an integer

# EXPECTED
TensorShape([1, 50, 50, 32, 1])

And HERE python 3.x - How to resize a 3D volumes in a Keras network model? - Stack Overflow, another scenario where the factor needed to be fractional.


( PS. downsample or upsample can be done properly in the same manner with scipy.ndimage.zoom )


Raise and issue.

resize_volume there is int arg constrained cause It Is just like a np.repeat.

Are you looking for something like:

I saw this already. It’s not actually solving my issue.

In that SO, all they need to resize is height and width and not depth, I think. That’s why they were able to use tf.image.resize with two axes. Now, their issue can be solved also with the resize_volumes.

a  = tf.ones(shape=(5, 50, 50, 10, 256))
tf.keras.backend.resize_volumes(
    a, 
    depth_factor=2, 
    height_factor=2, 
    width_factor=1, 
    data_format="channels_last"
).shape
TensorShape([5, 100, 100, 10, 256])

If you need to resize also the depth dimension It Is something different
It was tracked in:

But the bot close the issue if the original requester doesn’t keep the ticket alive

Yes, visited this one too. I also noticed that the bot closed it. IMO, the bot needs to be fixed. It’s not only the OP who was facing this issue but many other users too. :roll_eyes:

1 Like

It would be nice If you can open a ticket about this and proposing an alternative behaviour at GitHub - tensorflow/community: Stores documents used by the TensorFlow developer community

1 Like