TensorFlow中实现三维(3D)上下采样
程序员文章站
2022-03-20 12:50:56
...
def interpolate(x, scale=2, dhwc=None):
def interpolate_torch(x):
input = torch.Tensor(x)
b, d, h, w, c = input.shape
input = input.permute(0, 4, 1, 2, 3).contiguous()
input_resized = F.interpolate(input, size=(int(d * scale), int(h * scale), int(w * scale)), mode='trilinear')
input_resized = input_resized.permute(0, 2, 3, 4, 1).contiguous().numpy()
return input_resized
if dhwc is not None:
d, h, w, c = dhwc[0], dhwc[1], dhwc[2], dhwc[3] # dhwc stand for input size instead of output size!
else:
b, d, h, w, c = x.get_shape().as_list()[0], x.get_shape().as_list()[1], x.get_shape().as_list()[2], \
x.get_shape().as_list()[3], x.get_shape().as_list()[4]
output = tf.py_func(lambda x: interpolate_torch(x), [x], tf.float32)
output = tf.reshape(output, [-1, int(d * scale), int(h * scale), int(w * scale), int(c)])
return output
provided by Bo Hu
上一篇: 使用Scratch制作弹球游戏
下一篇: 电脑剪切的快捷键是什么?