程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

TensorFlow中实现三维(3D)上下采样

发布于2020-02-25 12:51     阅读(1529)     评论(0)     点赞(10)     收藏(4)


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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

provided by Bo Hu

发布了132 篇原创文章 · 获赞 171 · 访问量 21万+


所属网站分类: 技术文章 > 博客

作者:美美哒

链接:https://www.pythonheidong.com/blog/article/233273/0c0e200587d70dcfe4a9/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

10 0
收藏该文
已收藏

评论内容:(最多支持255个字符)