caffe 3d Unet网络实现
程序员文章站
2022-07-12 09:35:54
...
github下载3Dunet并编译。这里主要按照3D U-Net: Learning Dense Volumetric Segmentation from Sparse Annotation论文,官方介绍在这里。
我主要想用一下论文中提到的elastic deformation数据扩充方法,论文实现了在caffe中添加了一个deformation的层,专门用来做扩充,这样每次送入网络的图都要经过elastic deformation,可以无限次的扩充图像。所以这里主要介绍下作者添加的这些层。
先看下作者做的一个介绍
* Modified layers
ND: N dimension
Below listed modifications extend the functionality of existing layers.
The layers remain compatible with the original implementation and have
no additional parameters except the extension to ND.
* ND support for CuDNN engine in 'Convolution' layer
* CuDNN engine for layer 'Deconvolution'
* support for ND pooling in 'Pooling' layer
* automatic network reshaping in 'HDF5Data' layer
* output of selected blobs to individual files in every iteration by 'HDF5Output'
layer
* automatic cropping of central region in 'Concat' layer
* New layers
* 'ValueAugmentation' layer
Re-maps the intensity values of each channel. All values below zero
will be mapped to the value drawn from a uniform distribution between
black_from and black_to. All values above one will be mapped to
the value drawn from a uniform distribution between white_from and white_to.
The mapping function that re-maps the in input values between zero and one is
smooth and has slopes between slope_min and slope_max.
Parameters:
black_from minimum value that zero is mapped to
black_to maximum value that zero is mapped to
white_from minimum value that one is mapped to
white_to maximum value that one is mapped to
slope_min minimum slope
slope_max maximum slope
lut_size number of elements in lookup table
n_control_point_insertions number of control point insertions, i.e.
0 -> two control points (black and white)
1 -> three control points
2 -> five control points
3 -> nine control points
...
Example:
layer { type: 'ValueAugmentation'
name: 'augm_data-d0a'
bottom: 'd0a'
top: 'd0a'
value_augmentation_param {
black_from: -0.02 black_to: 0.02
slope_min: 0.70 slope_max: 1.30
white_from: 0.90 white_to: 1.10
n_control_point_insertions: 3 }
include: { phase: TRAIN } }
* 'CreateDeformation' and 'ApplyDeformation' layers
Creates and applies random elastic deformations. The location of the
extracted blob is either randomly drawn within the input blob, within
a specified region, or based on the probability density specified in an
additional blob.
Parameters:
batch_size batch size
nx,ny,nz output shape
ncomponents 2 for images (2D), 3 for volumes (3D)
random_elastic_grid_spacing grid spacing
larger results in smoother deformations
random_elastic_deform_magnitude magnitude of deformation drawn from
normal distridution
random_rotate_from minimum/maximum rotation angle in degrees
random_rotate_to drawn from uniform distribution
random_offset_from minimum/maximum offset
random_mirror_flag specify which axis should be mirrored
extrapolation method to determine values outside input range
'zero' or 'mirror'
interpolation interpolation 'linear' or 'nearest'
Example:
layer { type: 'CreateDeformation'
name: 'create_deformation'
bottom: 'sample_freq'
top: 'def'
create_deformation_param {
random_offset_range_from_pdf: true
nz: 148 ny: 148 nx: 148 ncomponents: 3
random_elastic_grid_spacing { v: 32 v: 32 v: 32 } #
random_elastic_deform_magnitude { v: 6 v: 6 v: 6 } #
random_rotate_from { v: -15 v: -15 v: -15 } #
random_rotate_to { v: 15 v: 15 v: 15 } #
voxel_relsize_z: 1 }
include: { phase: TRAIN } }
layer { type: 'ApplyDeformation'
name: 'def_data-d0a'
bottom: 'data'
bottom: 'def'
top: 'd0a'
apply_deformation_param { interpolation: 'linear' extrapolation: 'zero'} }
* 'ValueTransformation' layer
Shift and scales the input blob with fixed values as
y = scale * x + offset.
If one parameter is specified, then the same transformation is performed
for all channels. Provide as many repeated parameters as there are channels
to transform each channel with an individual transformation.
Parameters:
scale scale
offset offset
Example (three channels, offset -0.5 each):
layer { type: 'ValueTransformation'
name: 'val_trn'
bottom: 'd0a' top: 'd0a'
value_transformation_param { offset { v: -0.5 v: -0.5 v: -0.5 } } }
作者对其修改及添加的层做了介绍,其中修改了一些层,主要是让其这些本来就有的层支持多维并用cudnn加速,比较有用的一个层是作者加了个HDF5Output层,可以输出保存模型运行时候进行数据增强后的图,当然我们也可以用该层来输出各个feature map。
然后下面介绍了添加的一些层,我们想用的最重要的是CreateDeformation and ApplyDeformation layers, 可以把该层应用到网络中进行数据扩充。里面的几个参数作者也做了简单的介绍。这里有几点需要注意:
- CreateDeformation层里有个参数是random_offset_range_from_ignore_label,这里一定设成0,不要问为什么,我吃过亏,当然具体参数是干嘛的大家可以看caffe源码。
-
ApplyDeformation层里的参数interpolation,对label使用要设置成‘nearest’, 因为如果设置成‘linear’, 那你的label里面的值就乱了,你想想是为什么,应该很容易想到。
下面是使用deformation层的一个框图
上一篇: matplotlib学习笔记(代码)
下一篇: javaSE 循环练习题