我的目标是 3D 医学图像。
对于形状为 [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 可用于上采样,但我不希望额外的权重用于训练。
tensorflow 中的 5-D 张量上采样是否有直接操作?
请您参考如下方法:
您可以使用 tf.constant 为 conv3d_transpose 提供过滤器。它不会产生任何额外的训练重量。您还可以使用相同的常量滤波器使用额外的 conv3d channel 进行双线性插值上采样。下面的示例是我使用双线性插值对 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))
