TensorF中5D张量的上采样

2024-09-30 20:17:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目标是三维医学图像。在

对于形状为[batch, height, width, channels]的4-D张量B,使用tf.image.resize_*进行上采样。在

对于形状为[batch, height, width, depth, channels]的5-D张量A,例如要向上采样到形状[batch, 1.5*height, 1.5*width, 1.5*depth, channels]tf.nn.conv3d_transpose可以用于上采样,但我不需要额外的权重用于训练。在

张量流中的5维张量上采样是否有直接运算?在


Tags: 图像image目标tfbatchnnwidth医学
1条回答
网友
1楼 · 发布于 2024-09-30 20:17:23

你可以用tf.常数为conv3d_transpose提供过滤器。它不会为训练增加额外的重量。您也可以使用conv3d的一个额外的过程,使用相同的常量过滤器进行双线性插值上采样。下面的例子是我使用双线性插值进行3D张量(5D格式)上采样的函数。在

def upsample(input, upsamplescale, channel_count):
    deconv = tf.nn.conv3d_transpose(value=input, filter=tf.constant(np.ones([upsamplescale,upsamplescale,upsamplescale,channel_count,channel_count], np.float32)), output_shape=[1, xdim, ydim, zdim, channel_count],
                                strides=[1, upsamplescale, upsamplescale, upsamplescale, 1],
                                padding="SAME", name='UpsampleDeconv')
    smooth5d = tf.constant(np.ones([upsamplescale,upsamplescale,upsamplescale,channel_count,channel_count],dtype='float32')/np.float32(upsamplescale)/np.float32(upsamplescale)/np.float32(upsamplescale), name='Upsample'+str(upsamplescale))
    print('Upsample', upsamplescale)
    return tf.nn.conv3d(input=deconv,
                 filter=smooth5d,
                 strides=[1, 1, 1, 1, 1],
                 padding='SAME',
                 name='UpsampleSmooth'+str(upsamplescale))    

相关问题 更多 >