首页 > 解决方案 > 如何编写自定义 keras 层来重新采样 3D 体积?

问题描述

(batch_size, height, width, depth, channel)在网络中有一个张量(代表 3D 体积),需要重新采样。我正在考虑编写一个自定义 keras 层来做到这一点。

input = Input()
x = net(input) # another network
x = custom_resample_3d(...)(x)
x = ...

的输出net让我们说(batch_size, 64, 64, 64, 1)。我想调整张量的大小以(batch_size, 256, 256, 32, 1)使用插值。

所以我最初的想法就像用scipy.ndimage.interpolation.zoom.

class MyLayer(Layer):

    def __init__(self, output_dim, **kwargs):
        self.output_dim = output_dim
        super(MyLayer, self).__init__(**kwargs)

    def build(self, input_shape):
        super(MyLayer, self).build(input_shape)  # Be sure to call this at the end

    def call(self, x):
        return scipy.ndimage.interpolation.zoom(x, ...)

    def compute_output_shape(self, input_shape):
        return ...

有没有更好的方法呢?还是我需要将其转换keras tensor为 numpy 数组,然后将其转换回张量?

标签: tensorflowkerasimage-resizingvolume

解决方案


推荐阅读