一、网络介绍
论文下载地址及论文翻译与解读:玖零猴:UNet3+(UNet+++)论文翻译与详细解读zhuanlan.zhihu.com
原代码链接:链接
二、BraTs数据预处理
本文用的训练集和验证集均来自BraTs2018的训练集(其中HGG:210个病人,LGG:75个病人)
但由于BraTs只公开训练集数据,没有测试集数据,如果在训练集中再拆一部分用来作测试集的话,那训练集便少了许多,训练数据如果过少,容易出现过拟合现象,即在训练集中表现好,而在测试集中表现差,此时的网络泛化能力变差了.为了解决数据少的问题,灵机一动的我想出了一个办法.
因为BraTs2019的训练集在BraTs2018的基础上增多了,其中HGG增加了49例,LGG增加了1例,那么我就把这些新增的作为我的测试集
下面我提供百度云盘给大家下载,这是原始数据
BraTs18数据集下载地址(不包含测试集,提供的验证集无GT)
链接:https://pan.baidu.com/s/1Ry41OVl9VLOMzhQQR9qXuA 提取码:qvmo
BraTs19数据集下载地址如下(不包含测试集,提供的验证集无GT)
链接: https://pan.baidu.com/s/1S5XGTdHkwFnagKS-5vWYBg 提取码: 2333
数据的预处理以及实现代码
把上面两年的数据下下来,然后我对数据的预处理方法是链接
完整的实现代码(jupyter notebook打开)https://github.com/Merofine/BraTS2Dpreprocessinggithub.comGetTrainingSets.ipynb——>训练集和验证集
GetTestingSetsFrom2019.ipynb-—>测试集
代码执行完后,获得npy数据
链接:https://pan.baidu.com/s/1W3rcl9I-Y8DwWu5p4o--cw 密码:hfe7
三、运行环境的安装
1、系统环境 WIN10 + CUDA 92 + CUDNN7 + ANACONDA
2、ANACONDA指令快速配置环境,先下载下面文件
四、核心代码
# -*- coding: utf-8 -*-
import torch
import torch.nn as nn
import torch.nn.functional as F
from layers import unetConv2
from init_weights import init_weights
'''
UNet 3+
'''
class UNet_3Plus(nn.Module):
def __init__(self, args):
super(UNet_3Plus, self).__init__()
self.args = args
in_channels = 4
n_classes = 3
feature_scale = 4
is_deconv = True
is_batchnorm = True
self.is_deconv = is_deconv
self.in_channels = in_channels
self.is_batchnorm = is_batchnorm
self.feature_scale = feature_scale
filters = [64, 128, 256, 512, 1024]
## -------------Encoder--------------
self.conv1 = unetConv2(self.in_channels, filters[0], self.is_batchnorm)
self.maxpool1 = nn.MaxPool2d(kernel_size=2)
self.conv2 = unetConv2(filters[0], filters[1], self.is_batchnorm)
self.maxpool2 = nn.MaxPool2d(kernel_size=2)
self.conv3 = unetConv2(filters[1], filters[2], self.is_batchnorm)
self.maxpool3 = nn.MaxPool2d(kernel_size=2)
self.conv4 = unetConv2(filters[2], filters[3], self.is_batchnorm)
self.maxpool4 = nn.MaxPool2d(kernel_size=2)
self.conv5 = unetConv2(filters[3], filters[4], self.is_batchnorm)
## -------------Decoder--------------
self.CatChannels = filters[0]
self.CatBlocks = 5
self.UpChannels = self.CatChannels * self.CatBlocks
'''stage 4d'''
# h1->320*320, hd4->40*40, Pooling 8 tim