python图像分割模型_用于图像分割的各种Unet模型的PyTorch实现

Unet-Segmentation-Pytorch-Nest-of-Unets

Implementation of different kinds of Unet Models for Image Segmentation

UNet - U-Net: Convolutional Networks for Biomedical Image Segmentation https://arxiv.org/abs/1505.04597

RCNN-UNet - Recurrent Residual Convolutional Neural Network based on U-Net (R2U-Net) for Medical Image Segmentation https://arxiv.org/abs/1802.06955

Attention Unet - Attention U-Net: Learning Where to Look for the Pancreas https://arxiv.org/abs/1804.03999

RCNN-Attention Unet - Attention R2U-Net : Just integration of two recent advanced works (R2U-Net + Attention U-Net)

Nested UNet - UNet++: A Nested U-Net Architecture for Medical Image Segmentation https://arxiv.org/abs/1807.10165

With Layer Visualization

1. Getting Started

Clone the repo:

git clone https://github.com/bigmb/Unet-Segmentation-Pytorch-Nest-of-Unets.git

2. Requirements

python>=3.6

torch>=0.4.0

torchvision

torchsummary

tensorboardx

natsort

numpy

pillow

scipy

scikit-image

sklearn

Install all dependent libraries:

pip install -r requirements.txt

3. Run the file

Add all your folders to this line 106-113

t_data = '' # Input data

l_data = '' #Input Label

test_image = '' #Image to be predicted while training

test_label = '' #Label of the prediction Image

test_folderP = '' #Test folder Image

test_folderL = '' #Test folder Label for calculating the Dice score

4. Types of Unet

Unet

RCNN Unet

Attention Unet

Attention-RCNN Unet

Nested Unet

5. Visualization

To plot the loss , Visdom would be required. The code is already written, just uncomment the required part. Gradient flow can be used too. Taken from (https://discuss.pytorch.org/t/check-gradient-flow-in-network/15063/10)

A model folder is created and all the data is stored inside that. Last layer will be saved in the model folder. If any particular layer is required , mention it in the line 361.

Layer Visulization

Filter Visulization

TensorboardX Still have to tweak some parameters to get visualization. Have messed up this trying to make pytorch 1.1.0 working with tensorboard directly (and then came to know Currently it doesn't support anything apart from linear graphs)

Input Image Visulization for checking

a) Original Image

b) CenterCrop Image

6. Results

Dice Score for hippocampus segmentation ADNI-LONI Dataset

7. Citation

If you find it usefull for your work.

@article{DBLP:journals/corr/abs-1906-07160,

author = {Malav Bateriwala and

Pierrick Bourgeat},

title = {Enforcing temporal consistency in Deep Learning segmentation of brain

{MR} images},

journal = {CoRR},

volume = {abs/1906.07160},

year = {2019},

url = {http://arxiv.org/abs/1906.07160},

archivePrefix = {arXiv},

eprint = {1906.07160},

timestamp = {Mon, 24 Jun 2019 17:28:45 +0200},

biburl = {https://dblp.org/rec/bib/journals/corr/abs-1906-07160},

bibsource = {dblp computer science bibliography, https://dblp.org}

}

8. Blog about different Unets

In progress

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unet是一种用于图像分割的深度学习架构,它由Ronneberger等人在2015年提出,它的结构类似于编码器-解码器(encoder-decoder)。在这里,我将为您介绍如何使用PyTorch实现Unet图像分割。 首先,我们需要导入必要的库: ```python import torch import torch.nn as nn import torch.nn.functional as F ``` 接下来,我们定义Unet模型的编码器(encoder)和解码器(decoder)部分。编码器由一系列卷积层组成,每个卷积层后面跟着一个最大池化层。解码器由一系列反卷积层组成,每个反卷积层后面跟着一个卷积层。 ```python class DoubleConv(nn.Module): def __init__(self, in_channels, out_channels): super(DoubleConv, self).__init__() self.conv = nn.Sequential( nn.Conv2d(in_channels, out_channels, 3, padding=1), nn.BatchNorm2d(out_channels), nn.ReLU(inplace=True), nn.Conv2d(out_channels, out_channels, 3, padding=1), nn.BatchNorm2d(out_channels), nn.ReLU(inplace=True) ) def forward(self, x): x = self.conv(x) return x class Unet(nn.Module): def __init__(self): super(Unet, self).__init__() self.max_pool = nn.MaxPool2d(2, 2) self.down_conv1 = DoubleConv(3, 64) self.down_conv2 = DoubleConv(64, 128) self.down_conv3 = DoubleConv(128, 256) self.down_conv4 = DoubleConv(256, 512) self.down_conv5 = DoubleConv(512, 1024) self.up_transpose1 = nn.ConvTranspose2d(1024, 512, 2, stride=2) self.up_conv1 = DoubleConv(1024, 512) self.up_transpose2 = nn.ConvTranspose2d(512, 256, 2, stride=2) self.up_conv2 = DoubleConv(512, 256) self.up_transpose3 = nn.ConvTranspose2d(256, 128, 2, stride=2) self.up_conv3 = DoubleConv(256, 128) self.up_transpose4 = nn.ConvTranspose2d(128, 64, 2, stride=2) self.up_conv4 = DoubleConv(128, 64) self.out_conv = nn.Conv2d(64, 2, 1) def forward(self, x): # Encoder x1 = self.down_conv1(x) x2 = self.max_pool(x1) x3 = self.down_conv2(x2) x4 = self.max_pool(x3) x5 = self.down_conv3(x4) x6 = self.max_pool(x5) x7 = self.down_conv4(x6) x8 = self.max_pool(x7) x9 = self.down_conv5(x8) # Decoder x = self.up_transpose1(x9) x = torch.cat([x, x7], dim=1) x = self.up_conv1(x) x = self.up_transpose2(x) x = torch.cat([x, x5], dim=1) x = self.up_conv2(x) x = self.up_transpose3(x) x = torch.cat([x, x3], dim=1) x = self.up_conv3(x) x = self.up_transpose4(x) x = torch.cat([x, x1], dim=1) x = self.up_conv4(x) x = self.out_conv(x) return x ``` 在上面的代码中,我们定义了`DoubleConv`类来实现Unet中的双卷积层。我们还定义了`Unet`类,该类包括编码器和解码器部分。`Unet`类的前向函数实现Unet网络的正向传播,其中使用了卷积、反卷积和池化层。 最后,我们可以使用定义的Unet模型来进行图像分割: ```python unet = Unet() x = torch.randn(1, 3, 256, 256) output = unet(x) print(output.shape) ``` 在上面的代码中,我们首先创建一个Unet模型的实例,然后生成一个随机的输入张量,并通过Unet模型将其传递。最后,我们打印输出张量的形状(shape)。 希望这个简单的教程能够帮助您了解如何使用PyTorch实现Unet图像分割
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值