显示完整图像预测结果的挑战(Unpatchify 问题)

问题描述 投票:0回答:0

我正在利用 UNet 模型来处理医学图像分析任务。然而,数据的稀缺构成了一个显着的障碍,因为我只能访问 28 张图像,每张图像的尺寸为 1038 x 1388 像素。为了减轻数据限制并增强模型的泛化性,我采用了数据增强技术。

通过将原始图像分解为更小的、可管理的 256 x 256 像素块,我有效地扩展了训练数据集的多样性。为了实现这一目标,我巧妙地应用了 Albumentations 函数,该函数熟练地引入了各种变换来生成额外的训练图像。 经过强化训练阶段后,UNet 模型吸收了增强数据中的知识,

我很想评估它在测试数据上的表现。然而,当尝试显示完整图像的预测结果时,它们没有按预期对齐。

我注意到,当我单独显示补丁时,模型的预测是准确的。这让我怀疑问题可能与用于从分段补丁重建全图像预测的“unpatchify”函数有关。我怎么解决这个问题?您有什么解决方案可以建议我吗?

注意: 在测试阶段,我使用了 Sreenivas Bhattiprolu 博士的 Github 存储库中的代码“206_sem_segm_large_images_using_unet_with_patchify.py”。

这是我的代码的测试阶段:

patches = patchify(test_img, (256, 256, 3), step = 128)
predicted_patches = []

for i in range(patches.shape[0]):
  for j in range(patches.shape[1]):
    print(i,j)
    single_patch = patches[i,j,:,:,:,:]
    single_patch_prediction = (model.predict(single_patch)[0,:,:,0] > 0.5).astype(np.uint8)
    predicted_patches.append(single_patch_prediction)
predicted_patches = np.array(predicted_patches)

predicted_patches_reshaped = np.reshape(predicted_patches, (patches.shape[0], patches.shape[1], 256, 256))
new_array = np.expand_dims(predicted_patches_reshaped, axis=2)
expnd_array = np.repeat(np.expand_dims(new_array, axis=-1), 3, axis=-1)

reconstructed_image = unpatchify(expnd_array, large_image.shape)

The prediction result of the full image

The prediction results of each patche

python machine-learning artificial-intelligence prediction unet-neural-network
© www.soinside.com 2019 - 2025. All rights reserved.