Skip to content

How to resize (downsample) 5D samples in keras? #16260

Closed
@innat

Description

@innat

(Reposting from here)


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 https://stackoverflow.com/q/57341504/9215780, 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 )

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions