在张量流中使用 5D 张量调整 3D 图像的大小
resize 3D image with 5D tensor in tensorflow
我正在为我的网络使用 3D 卷积。在我网络的一个节点中,我需要将图像的大小从 [5,50,50,10,256]
调整为 [5,100,100,10,256]
。我只想调整图像的轴 1 和轴 2 的大小。
我尝试使用 tf.image.resize_images,但它似乎只适用于 3D 或 4D 张量。
有什么建议吗?
没问题,我们仍然可以使用tf.image.resize_images。我们需要做的是以张量 (4D) 所需的形状将数据发送到 tf.image.resize_images。
# First reorder your dimensions to place them where tf.image.resize_images needs them
transposed = tf.transpose( yourData, [0,3,1,2,4] )
# it is now [5,10,50,50,256]
# but we need it to be 4 dimensions, not 5
reshaped = tf.reshape( transposed, [5*10,50,50,256] )
# and finally we use tf.image.resize_images
new_size = tf.constant( [ 100 , 100 ] )
resized = tf.image.resize_images( reshaped , new_size )
# your data is now [5*10,100,100,256]
undo_reshape = tf.reshape( resized, [5,10,100,100,256] )
# it is now [5,10,100,100,256] so lastly we need to reorder it
undo_transpose = tf.transpose( undo_reshape, [0,2,3,1,4] )
# your output is now [5,100,100,10,256]
接受的答案是好的。但是,这里有另一种方法可以使用 built-in 方法实现此目的。
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])
但并非如此,对体积数据进行下采样可能不起作用。因为因子需要是整数。 (Check).
我正在为我的网络使用 3D 卷积。在我网络的一个节点中,我需要将图像的大小从 [5,50,50,10,256]
调整为 [5,100,100,10,256]
。我只想调整图像的轴 1 和轴 2 的大小。
我尝试使用 tf.image.resize_images,但它似乎只适用于 3D 或 4D 张量。
有什么建议吗?
没问题,我们仍然可以使用tf.image.resize_images。我们需要做的是以张量 (4D) 所需的形状将数据发送到 tf.image.resize_images。
# First reorder your dimensions to place them where tf.image.resize_images needs them
transposed = tf.transpose( yourData, [0,3,1,2,4] )
# it is now [5,10,50,50,256]
# but we need it to be 4 dimensions, not 5
reshaped = tf.reshape( transposed, [5*10,50,50,256] )
# and finally we use tf.image.resize_images
new_size = tf.constant( [ 100 , 100 ] )
resized = tf.image.resize_images( reshaped , new_size )
# your data is now [5*10,100,100,256]
undo_reshape = tf.reshape( resized, [5,10,100,100,256] )
# it is now [5,10,100,100,256] so lastly we need to reorder it
undo_transpose = tf.transpose( undo_reshape, [0,2,3,1,4] )
# your output is now [5,100,100,10,256]
接受的答案是好的。但是,这里有另一种方法可以使用 built-in 方法实现此目的。
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])
但并非如此,对体积数据进行下采样可能不起作用。因为因子需要是整数。 (Check).