日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

unet脑肿瘤分割_2D UNet3+ Pytorch实现 脑肿瘤分割

發(fā)布時間:2024/8/1 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 unet脑肿瘤分割_2D UNet3+ Pytorch实现 脑肿瘤分割 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、網(wǎng)絡(luò)介紹

論文下載地址及論文翻譯與解讀:玖零猴:UNet3+(UNet+++)論文翻譯與詳細(xì)解讀?zhuanlan.zhihu.com

原代碼鏈接:鏈接

二、BraTs數(shù)據(jù)預(yù)處理

本文用的訓(xùn)練集和驗證集均來自BraTs2018的訓(xùn)練集(其中HGG:210個病人,LGG:75個病人)

但由于BraTs只公開訓(xùn)練集數(shù)據(jù),沒有測試集數(shù)據(jù),如果在訓(xùn)練集中再拆一部分用來作測試集的話,那訓(xùn)練集便少了許多,訓(xùn)練數(shù)據(jù)如果過少,容易出現(xiàn)過擬合現(xiàn)象,即在訓(xùn)練集中表現(xiàn)好,而在測試集中表現(xiàn)差,此時的網(wǎng)絡(luò)泛化能力變差了.為了解決數(shù)據(jù)少的問題,靈機(jī)一動的我想出了一個辦法.

因為BraTs2019的訓(xùn)練集在BraTs2018的基礎(chǔ)上增多了,其中HGG增加了49例,LGG增加了1例,那么我就把這些新增的作為我的測試集

下面我提供百度云盤給大家下載,這是原始數(shù)據(jù)

BraTs18數(shù)據(jù)集下載地址(不包含測試集,提供的驗證集無GT)

鏈接:https://pan.baidu.com/s/1Ry41OVl9VLOMzhQQR9qXuA 提取碼:qvmo

BraTs19數(shù)據(jù)集下載地址如下(不包含測試集,提供的驗證集無GT)

鏈接: https://pan.baidu.com/s/1S5XGTdHkwFnagKS-5vWYBg 提取碼: 2333

數(shù)據(jù)的預(yù)處理以及實現(xiàn)代碼

把上面兩年的數(shù)據(jù)下下來,然后我對數(shù)據(jù)的預(yù)處理方法是鏈接

完整的實現(xiàn)代碼(jupyter notebook打開)https://github.com/Merofine/BraTS2Dpreprocessing?github.comGetTrainingSets.ipynb——>訓(xùn)練集和驗證集

GetTestingSetsFrom2019.ipynb-—>測試集

代碼執(zhí)行完后,獲得npy數(shù)據(jù)

鏈接:https://pan.baidu.com/s/1W3rcl9I-Y8DwWu5p4o--cw 密碼:hfe7

三、運(yùn)行環(huán)境的安裝

1、系統(tǒng)環(huán)境 WIN10 + CUDA 92 + CUDNN7 + ANACONDA

2、ANACONDA指令快速配置環(huán)境,先下載下面文件

四、核心代碼

# -*- 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 times

self.h1_PT_hd4 = nn.MaxPool2d(8, 8, ceil_mode=True)

self.h1_PT_hd4_conv = nn.Conv2d(filters[0], self.CatChannels, 3, padding=1)

self.h1_PT_hd4_bn = nn.BatchNorm2d(self.CatChannels)

self.h1_PT_hd4_relu = nn.ReLU(inplace=True)

# h2->160*160, hd4->40*40, Pooling 4 times

self.h2_PT_hd4 = nn.MaxPool2d(4, 4, ceil_mode=True)

self.h2_PT_hd4_conv = nn.Conv2d(filters[1], self.CatChannels, 3, padding=1)

self.h2_PT_hd4_bn = nn.BatchNorm2d(self.CatChannels)

self.h2_PT_hd4_relu = nn.ReLU(inplace=True)

# h3->80*80, hd4->40*40, Pooling 2 times

self.h3_PT_hd4 = nn.MaxPool2d(2, 2, ceil_mode=True)

self.h3_PT_hd4_conv = nn.Conv2d(filters[2], self.CatChannels, 3, padding=1)

self.h3_PT_hd4_bn = nn.BatchNorm2d(self.CatChannels)

self.h3_PT_hd4_relu = nn.ReLU(inplace=True)

# h4->40*40, hd4->40*40, Concatenation

self.h4_Cat_hd4_conv = nn.Conv2d(filters[3], self.CatChannels, 3, padding=1)

self.h4_Cat_hd4_bn = nn.BatchNorm2d(self.CatChannels)

self.h4_Cat_hd4_relu = nn.ReLU(inplace=True)

# hd5->20*20, hd4->40*40, Upsample 2 times

self.hd5_UT_hd4 = nn.Upsample(scale_factor=2, mode='bilinear') # 14*14

self.hd5_UT_hd4_conv = nn.Conv2d(filters[4], self.CatChannels, 3, padding=1)

self.hd5_UT_hd4_bn = nn.BatchNorm2d(self.CatChannels)

self.hd5_UT_hd4_relu = nn.ReLU(inplace=True)

# fusion(h1_PT_hd4, h2_PT_hd4, h3_PT_hd4, h4_Cat_hd4, hd5_UT_hd4)

self.conv4d_1 = nn.Conv2d(self.UpChannels, self.UpChannels, 3, padding=1) # 16

self.bn4d_1 = nn.BatchNorm2d(self.UpChannels)

self.relu4d_1 = nn.ReLU(inplace=True)

'''stage 3d'''

# h1->320*320, hd3->80*80, Pooling 4 times

self.h1_PT_hd3 = nn.MaxPool2d(4, 4, ceil_mode=True)

self.h1_PT_hd3_conv = nn.Conv2d(filters[0], self.CatChannels, 3, padding=1)

self.h1_PT_hd3_bn = nn.BatchNorm2d(self.CatChannels)

self.h1_PT_hd3_relu = nn.ReLU(inplace=True)

# h2->160*160, hd3->80*80, Pooling 2 times

self.h2_PT_hd3 = nn.MaxPool2d(2, 2, ceil_mode=True)

self.h2_PT_hd3_conv = nn.Conv2d(filters[1], self.CatChannels, 3, padding=1)

self.h2_PT_hd3_bn = nn.BatchNorm2d(self.CatChannels)

self.h2_PT_hd3_relu = nn.ReLU(inplace=True)

# h3->80*80, hd3->80*80, Concatenation

self.h3_Cat_hd3_conv = nn.Conv2d(filters[2], self.CatChannels, 3, padding=1)

self.h3_Cat_hd3_bn = nn.BatchNorm2d(self.CatChannels)

self.h3_Cat_hd3_relu = nn.ReLU(inplace=True)

# hd4->40*40, hd4->80*80, Upsample 2 times

self.hd4_UT_hd3 = nn.Upsample(scale_factor=2, mode='bilinear') # 14*14

self.hd4_UT_hd3_conv = nn.Conv2d(self.UpChannels, self.CatChannels, 3, padding=1)

self.hd4_UT_hd3_bn = nn.BatchNorm2d(self.CatChannels)

self.hd4_UT_hd3_relu = nn.ReLU(inplace=True)

# hd5->20*20, hd4->80*80, Upsample 4 times

self.hd5_UT_hd3 = nn.Upsample(scale_factor=4, mode='bilinear') # 14*14

self.hd5_UT_hd3_conv = nn.Conv2d(filters[4], self.CatChannels, 3, padding=1)

self.hd5_UT_hd3_bn = nn.BatchNorm2d(self.CatChannels)

self.hd5_UT_hd3_relu = nn.ReLU(inplace=True)

# fusion(h1_PT_hd3, h2_PT_hd3, h3_Cat_hd3, hd4_UT_hd3, hd5_UT_hd3)

self.conv3d_1 = nn.Conv2d(self.UpChannels, self.UpChannels, 3, padding=1) # 16

self.bn3d_1 = nn.BatchNorm2d(self.UpChannels)

self.relu3d_1 = nn.ReLU(inplace=True)

'''stage 2d '''

# h1->320*320, hd2->160*160, Pooling 2 times

self.h1_PT_hd2 = nn.MaxPool2d(2, 2, ceil_mode=True)

self.h1_PT_hd2_conv = nn.Conv2d(filters[0], self.CatChannels, 3, padding=1)

self.h1_PT_hd2_bn = nn.BatchNorm2d(self.CatChannels)

self.h1_PT_hd2_relu = nn.ReLU(inplace=True)

# h2->160*160, hd2->160*160, Concatenation

self.h2_Cat_hd2_conv = nn.Conv2d(filters[1], self.CatChannels, 3, padding=1)

self.h2_Cat_hd2_bn = nn.BatchNorm2d(self.CatChannels)

self.h2_Cat_hd2_relu = nn.ReLU(inplace=True)

# hd3->80*80, hd2->160*160, Upsample 2 times

self.hd3_UT_hd2 = nn.Upsample(scale_factor=2, mode='bilinear') # 14*14

self.hd3_UT_hd2_conv = nn.Conv2d(self.UpChannels, self.CatChannels, 3, padding=1)

self.hd3_UT_hd2_bn = nn.BatchNorm2d(self.CatChannels)

self.hd3_UT_hd2_relu = nn.ReLU(inplace=True)

# hd4->40*40, hd2->160*160, Upsample 4 times

self.hd4_UT_hd2 = nn.Upsample(scale_factor=4, mode='bilinear') # 14*14

self.hd4_UT_hd2_conv = nn.Conv2d(self.UpChannels, self.CatChannels, 3, padding=1)

self.hd4_UT_hd2_bn = nn.BatchNorm2d(self.CatChannels)

self.hd4_UT_hd2_relu = nn.ReLU(inplace=True)

# hd5->20*20, hd2->160*160, Upsample 8 times

self.hd5_UT_hd2 = nn.Upsample(scale_factor=8, mode='bilinear') # 14*14

self.hd5_UT_hd2_conv = nn.Conv2d(filters[4], self.CatChannels, 3, padding=1)

self.hd5_UT_hd2_bn = nn.BatchNorm2d(self.CatChannels)

self.hd5_UT_hd2_relu = nn.ReLU(inplace=True)

# fusion(h1_PT_hd2, h2_Cat_hd2, hd3_UT_hd2, hd4_UT_hd2, hd5_UT_hd2)

self.conv2d_1 = nn.Conv2d(self.UpChannels, self.UpChannels, 3, padding=1) # 16

self.bn2d_1 = nn.BatchNorm2d(self.UpChannels)

self.relu2d_1 = nn.ReLU(inplace=True)

'''stage 1d'''

# h1->320*320, hd1->320*320, Concatenation

self.h1_Cat_hd1_conv = nn.Conv2d(filters[0], self.CatChannels, 3, padding=1)

self.h1_Cat_hd1_bn = nn.BatchNorm2d(self.CatChannels)

self.h1_Cat_hd1_relu = nn.ReLU(inplace=True)

# hd2->160*160, hd1->320*320, Upsample 2 times

self.hd2_UT_hd1 = nn.Upsample(scale_factor=2, mode='bilinear') # 14*14

self.hd2_UT_hd1_conv = nn.Conv2d(self.UpChannels, self.CatChannels, 3, padding=1)

self.hd2_UT_hd1_bn = nn.BatchNorm2d(self.CatChannels)

self.hd2_UT_hd1_relu = nn.ReLU(inplace=True)

# hd3->80*80, hd1->320*320, Upsample 4 times

self.hd3_UT_hd1 = nn.Upsample(scale_factor=4, mode='bilinear') # 14*14

self.hd3_UT_hd1_conv = nn.Conv2d(self.UpChannels, self.CatChannels, 3, padding=1)

self.hd3_UT_hd1_bn = nn.BatchNorm2d(self.CatChannels)

self.hd3_UT_hd1_relu = nn.ReLU(inplace=True)

# hd4->40*40, hd1->320*320, Upsample 8 times

self.hd4_UT_hd1 = nn.Upsample(scale_factor=8, mode='bilinear') # 14*14

self.hd4_UT_hd1_conv = nn.Conv2d(self.UpChannels, self.CatChannels, 3, padding=1)

self.hd4_UT_hd1_bn = nn.BatchNorm2d(self.CatChannels)

self.hd4_UT_hd1_relu = nn.ReLU(inplace=True)

# hd5->20*20, hd1->320*320, Upsample 16 times

self.hd5_UT_hd1 = nn.Upsample(scale_factor=16, mode='bilinear') # 14*14

self.hd5_UT_hd1_conv = nn.Conv2d(filters[4], self.CatChannels, 3, padding=1)

self.hd5_UT_hd1_bn = nn.BatchNorm2d(self.CatChannels)

self.hd5_UT_hd1_relu = nn.ReLU(inplace=True)

# fusion(h1_Cat_hd1, hd2_UT_hd1, hd3_UT_hd1, hd4_UT_hd1, hd5_UT_hd1)

self.conv1d_1 = nn.Conv2d(self.UpChannels, self.UpChannels, 3, padding=1) # 16

self.bn1d_1 = nn.BatchNorm2d(self.UpChannels)

self.relu1d_1 = nn.ReLU(inplace=True)

# output

self.outconv1 = nn.Conv2d(self.UpChannels, n_classes, 3, padding=1)

# initialise weights

for m in self.modules():

if isinstance(m, nn.Conv2d):

init_weights(m, init_type='kaiming')

elif isinstance(m, nn.BatchNorm2d):

init_weights(m, init_type='kaiming')

def forward(self, inputs):

## -------------Encoder-------------

h1 = self.conv1(inputs) # h1->320*320*64

h2 = self.maxpool1(h1)

h2 = self.conv2(h2) # h2->160*160*128

h3 = self.maxpool2(h2)

h3 = self.conv3(h3) # h3->80*80*256

h4 = self.maxpool3(h3)

h4 = self.conv4(h4) # h4->40*40*512

h5 = self.maxpool4(h4)

hd5 = self.conv5(h5) # h5->20*20*1024

## -------------Decoder-------------

h1_PT_hd4 = self.h1_PT_hd4_relu(self.h1_PT_hd4_bn(self.h1_PT_hd4_conv(self.h1_PT_hd4(h1))))

h2_PT_hd4 = self.h2_PT_hd4_relu(self.h2_PT_hd4_bn(self.h2_PT_hd4_conv(self.h2_PT_hd4(h2))))

h3_PT_hd4 = self.h3_PT_hd4_relu(self.h3_PT_hd4_bn(self.h3_PT_hd4_conv(self.h3_PT_hd4(h3))))

h4_Cat_hd4 = self.h4_Cat_hd4_relu(self.h4_Cat_hd4_bn(self.h4_Cat_hd4_conv(h4)))

hd5_UT_hd4 = self.hd5_UT_hd4_relu(self.hd5_UT_hd4_bn(self.hd5_UT_hd4_conv(self.hd5_UT_hd4(hd5))))

hd4 = self.relu4d_1(self.bn4d_1(self.conv4d_1(

torch.cat((h1_PT_hd4, h2_PT_hd4, h3_PT_hd4, h4_Cat_hd4, hd5_UT_hd4), 1)))) # hd4->40*40*UpChannels

h1_PT_hd3 = self.h1_PT_hd3_relu(self.h1_PT_hd3_bn(self.h1_PT_hd3_conv(self.h1_PT_hd3(h1))))

h2_PT_hd3 = self.h2_PT_hd3_relu(self.h2_PT_hd3_bn(self.h2_PT_hd3_conv(self.h2_PT_hd3(h2))))

h3_Cat_hd3 = self.h3_Cat_hd3_relu(self.h3_Cat_hd3_bn(self.h3_Cat_hd3_conv(h3)))

hd4_UT_hd3 = self.hd4_UT_hd3_relu(self.hd4_UT_hd3_bn(self.hd4_UT_hd3_conv(self.hd4_UT_hd3(hd4))))

hd5_UT_hd3 = self.hd5_UT_hd3_relu(self.hd5_UT_hd3_bn(self.hd5_UT_hd3_conv(self.hd5_UT_hd3(hd5))))

hd3 = self.relu3d_1(self.bn3d_1(self.conv3d_1(

torch.cat((h1_PT_hd3, h2_PT_hd3, h3_Cat_hd3, hd4_UT_hd3, hd5_UT_hd3), 1)))) # hd3->80*80*UpChannels

h1_PT_hd2 = self.h1_PT_hd2_relu(self.h1_PT_hd2_bn(self.h1_PT_hd2_conv(self.h1_PT_hd2(h1))))

h2_Cat_hd2 = self.h2_Cat_hd2_relu(self.h2_Cat_hd2_bn(self.h2_Cat_hd2_conv(h2)))

hd3_UT_hd2 = self.hd3_UT_hd2_relu(self.hd3_UT_hd2_bn(self.hd3_UT_hd2_conv(self.hd3_UT_hd2(hd3))))

hd4_UT_hd2 = self.hd4_UT_hd2_relu(self.hd4_UT_hd2_bn(self.hd4_UT_hd2_conv(self.hd4_UT_hd2(hd4))))

hd5_UT_hd2 = self.hd5_UT_hd2_relu(self.hd5_UT_hd2_bn(self.hd5_UT_hd2_conv(self.hd5_UT_hd2(hd5))))

hd2 = self.relu2d_1(self.bn2d_1(self.conv2d_1(

torch.cat((h1_PT_hd2, h2_Cat_hd2, hd3_UT_hd2, hd4_UT_hd2, hd5_UT_hd2), 1)))) # hd2->160*160*UpChannels

h1_Cat_hd1 = self.h1_Cat_hd1_relu(self.h1_Cat_hd1_bn(self.h1_Cat_hd1_conv(h1)))

hd2_UT_hd1 = self.hd2_UT_hd1_relu(self.hd2_UT_hd1_bn(self.hd2_UT_hd1_conv(self.hd2_UT_hd1(hd2))))

hd3_UT_hd1 = self.hd3_UT_hd1_relu(self.hd3_UT_hd1_bn(self.hd3_UT_hd1_conv(self.hd3_UT_hd1(hd3))))

hd4_UT_hd1 = self.hd4_UT_hd1_relu(self.hd4_UT_hd1_bn(self.hd4_UT_hd1_conv(self.hd4_UT_hd1(hd4))))

hd5_UT_hd1 = self.hd5_UT_hd1_relu(self.hd5_UT_hd1_bn(self.hd5_UT_hd1_conv(self.hd5_UT_hd1(hd5))))

hd1 = self.relu1d_1(self.bn1d_1(self.conv1d_1(

torch.cat((h1_Cat_hd1, hd2_UT_hd1, hd3_UT_hd1, hd4_UT_hd1, hd5_UT_hd1), 1)))) # hd1->320*320*UpChannels

d1 = self.outconv1(hd1) # d1->320*320*n_classes

return d1

完整代碼請私聊博主~(QQ:704783475、博主想恰杯奶茶)

五、訓(xùn)練

python train.py --arch=“UNet_3Plus” --dataset=“Jiu0Monkey”

六、測試

python test.py --name="jiu0Monkey_UNet_3Plus_woDS"

七、與其它模型對比

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的unet脑肿瘤分割_2D UNet3+ Pytorch实现 脑肿瘤分割的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。