U Net 中 keras 中的多尺度分割掩码输出

时间:2021-02-09 05:12:26

标签: image tensorflow keras unity3d-unet

这就是模型,输入为单个图像,输出图像的不同尺度,即 I、1/2 I、1/4 I 和 1/8 I,Model(inputs=[inputs], outputs=[out6, out7, out8, out9])

我不确定如何创建训练数据集。假设 y_train 的输入将是形状为 (50, 192, 256, 3) 的数据,其中 3 = 图像的通道,192 是宽度,256 是高度,其中有 50 个,但是如何创建一个 y_train 将有 4 个组件?我曾尝试使用 zip 然后将其转换为 numpy 但这不起作用...

1 个答案:

答案 0 :(得分:1)

如果您一定希望模型学习生成多尺度掩码,那么您可以尝试下采样以使用 UNET 为监督学习生成缩放掩码。您可以使用基于插值的方法以最小的损失自动调整图像大小。 Here is a post 我将基准与多种此类方法进行比较。

如果您想为您的 df.apply(func, axis=1, args=['a', 'b']) 创建 [masks, masks_half, masks_quarter, masks_eighth],这是原始 + 重新缩放版本的蒙版图像列表,您可能想尝试一种快速下采样方法(取决于您的数据集)。

在这里,我使用 model.fit 将掩码下采样到其比例的一半、四分之一和八分之一。该方法使用插值(样条),但可以通过参数进行控制。查看this了解更多详情。

skimage.transform.pyramid_reduce
from skimage.transform import pyramid_reduce

masks = np.random.random((50, 192, 256, 3))

masks_half = np.stack([pyramid_reduce(i, 2, multichannel=True) for i in masks])
masks_quater = np.stack([pyramid_reduce(i, 4, multichannel=True) for i in masks])
masks_eighth = np.stack([pyramid_reduce(i, 8, multichannel=True) for i in masks])

print('Shape of original',masks.shape)
print('Shape of half scaled',masks_half.shape)
print('Shape of quater scaled',masks_quater.shape)
print('Shape of eighth scaled',masks_eighth.shape)

在单个图像/蒙版上进行测试 -

Shape of original (50, 192, 256, 3)
Shape of half scaled (50, 96, 128, 3)
Shape of quater scaled (50, 48, 64, 3)
Shape of eighth scaled (50, 24, 32, 3)

enter image description here

注意 x 和 y 轴上的比例变化 --------------------->