语义分割的相关介绍可参考该博客:
https://blog.youkuaiyun.com/u012931582/article/details/70314859
代码参考图1设计,黑色加粗的标注是笔者添加的,和代码中的变量对应
图1 Unet
U-Net代码,实现比较简单,可以参考上面的图片(逆卷积详解)
import torch.nn as nn
import torch
from torch import autograd
#把常用的2个卷积操作简单封装下
class DoubleConv(nn.Module):
def __init__(self, in_ch, out_ch):
super(DoubleConv, self).__init__()
self.conv = nn.Sequential(
nn.Conv2d(in_ch, out_ch, 3, padding=1),
nn.BatchNorm2d(out_ch), #添加了BN层
nn.ReLU(inplace=True),
nn.Conv2d(out_ch, out_ch, 3, padding=1),
nn.BatchNorm2d(out_ch),
nn.ReLU(inplac