提问人:Pranjal 提问时间:8/7/2021 最后编辑:InnatPranjal 更新时间:8/7/2021 访问量:684
深度学习 - 为 3D 多模态数据生成补丁
Deep Learning - generate patches for 3D multimodal data
问:
我选择了使用深度学习对脑肿瘤进行语义分割的问题。我正在使用 BRATS2015 数据集。它有 274 次患者 MRI 扫描,每次扫描尺寸为 240x240x155。每位患者有四种模式(T1、T2、T1c、FLAIR)。因此,我使用这些模式作为网络中的渠道。
在理想情况下,我的 3D UNet 网络的输入在channels_last模式下可以具有形状(Batch_size、240、240、155、4)。但是显卡显然无法处理这种大小的数据。因此,我需要将我的 MRI 扫描转换为贴片。
这就是我感到困惑的地方。获取单通道 3D 数据的补丁相对容易。为此,我们有许多库和辅助函数。我面临的问题是为多模态数据(即带有通道的 3D 数据)生成补丁。
- 我想到了为每个通道生成补丁的想法 分开并连接最终结果,但我相信我可能会输 一些多通道信息,如果我单独处理而不是 直接为多模态数据生成补丁。
我查看了库,我们可以在其中使用以下内容来生成补丁patchify
from patchify import patchify, unpatchify
#This will split the image into small images of shape [3,3,3]
patches = patchify(image, (3, 3, 3), step=1)
reconstructed_image = unpatchify(patches, image.shape)
但我不确定如何生成多模态补丁。有没有办法使用或任何其他库/帮助程序函数来做到这一点?patchify
答:
0赞
Prefect
8/7/2021
#1
您可能希望按view_as_blocks修补数据集。文档说
输入 n 维数组的块视图(使用重步长)。模块是输入数组的非重叠视图。
这是一个虚拟示例。
import numpy as np
from skimage.util.shape import view_as_blocks
# batch_size:3
# height:4
# width:6
# depth:8
# channels:4
arr = np.arange(3*4*6*8*4).reshape(3,4,6,8,4)
patches = view_as_blocks(arr,block_shape=(1,2,2,2,4))
print(patches.shape) # (3, 2, 3, 4, 1, 1, 2, 2, 2, 4)
# Print the first patch
print(patches[0,0,0,0,0,:,:,:,:,:])
# [[[[[ 0 1 2 3]
# [ 4 5 6 7]]
# [[ 32 33 34 35]
# [ 36 37 38 39]]]
# [[[192 193 194 195]
# [196 197 198 199]]
# [[224 225 226 227]
# [228 229 230 231]]]]]
patches.shape
可能看起来令人困惑,这里有一个简短的解释。最后 5 个数字代表块形状 (1,2,2,2,4),前 5 个数字代表相应尺寸的块数。或者,简单地说,arr.shape/block_shape 会给你 (3, 2, 3, 4, 1)。
需要注意的几点:
-
每个维度(block_shape)必须均匀地划分为arr_in的相应维度。
为此,您可以先根据您的 .block_shape
patches
将占用比 更多的存储空间。因此,将所有补丁保存到磁盘,然后将它们一一提供给模型是有意义的。arr
评论