我需要调整一些3D数据的大小,例如用于2d数据的tf.image.resize_images
方法。在张量流中调整3D数据的大小,如tf.image.resize_images
我在想我可以尝试运行tf.image.resize_images
它在一个循环和交换轴,但我认为必须有一个更简单的方法。简单的最近邻居应该没问题。
任何想法?它的效果并不理想,但我可以勉强接受的情况下的数据仅仅是0或1,使用这样的:
tf.where(boolMap, tf.fill(data_im*2, 0), tf.fill(data_im*2), 1)
但我不知道怎么去boolMap
。会使用tf.while_loop
去超过所有的值大幅降低性能?我觉得它会在GPU上,除非有某种自动循环并行化。
的数据是大小[batch_size, width, height, depth, 1]
预先感谢的张量。
N.B输出尺寸应该是:
[batch_size, width*scale, height*scale, depth*scale, 1]
我想出了这一点:
def resize3D(self, input_layer, width_factor, height_factor, depth_factor):
shape = input_layer.shape
print(shape)
rsz1 = tf.image.resize_images(tf.reshape(input_layer, [shape[0], shape[1], shape[2], shape[3]*shape[4]]), [shape[1]*width_factor, shape[2]*height_factor])
rsz2 = tf.image.resize_images(tf.reshape(tf.transpose(tf.reshape(rsz1, [shape[0], shape[1]*width_factor, shape[2]*height_factor, shape[3], shape[4]]), [0, 3, 2, 1, 4]), [shape[0], shape[3], shape[2]*height_factor, shape[1]*width_factor*shape[4]]), [shape[3]*depth_factor, shape[2]*height_factor])
return tf.transpose(tf.reshape(rsz2, [shape[0], shape[3]*depth_factor, shape[2]*height_factor, shape[1]*width_factor, shape[4]]), [0, 3, 2, 1, 4])
果然:
到:
我相信最近的邻居不应该有楼梯 - 套管效应(我故意删除了颜色)。
哈斯答案工作正常,但是我想知道我的最新错误是否有人可以破解它。
什么是您的3D数据格式? –
这是一个尺寸[batch_size,width,height,depth,1]的张量,类型为float32,值为1的5维可能在某个点上变为3 –
我指的是您使用的是哪种3D数据?深度图,音量,点云,... –