Home > other >  Lack of multiple classes unet image segmentation results
Lack of multiple classes unet image segmentation results

Time:11-22

Use the torch to write unet training results lack of prediction of multiple classes, how be to return a responsibility excuse me



Unet code:
# - * - coding: utf-8 - * -
# @ Time: 2020/6/15 coast
# @ Author: Zhao HL
# @ File: unet. Py
The from my_utils. Global_config import *
From the attention_module import *
From the RRM import *

# region set up network

# region codec structure definition
# struct1:3 * 3 conv and 3 * 3 conv
The class Conv_33_a (Module) :
Def __init__ (self, input_chs output_chs) :
Super (Conv_33_a, self) __init__ ()

Self. Conv1=Sequential (
Conv2d (input_chs output_chs, 3, padding=1),
BatchNorm2d (output_chs),
ReLU (),
)
Self. Conv2=Sequential (
Conv2d (output_chs output_chs, 3, padding=1),
BatchNorm2d (output_chs),
ReLU (),
)

Def forward (self, x) :
X=self. Conv1 (x)
X=self. Conv2 (x)
Return the x

The class Conv_33_b (Module) :
Def __init__ (self, input_chs output_chs) :
Super (Conv_33_b, self) __init__ ()

Self. Conv1=Sequential (
Conv2d (input_chs input_chs, 3, padding=1),
BatchNorm2d (input_chs),
ReLU (),
)
Self. Conv2=Sequential (
Conv2d (input_chs output_chs, 3, padding=1),
BatchNorm2d (output_chs),
ReLU (),
)

Def forward (self, x) :
X=self. Conv1 (x)
X=self. Conv2 (x)
Return the x





The class Conv_33_mid (Module) :
Def __init__ (self, input_chs output_chs) :
Super (Conv_33_mid, self) __init__ ()
Self. Conv1=Sequential (
Conv2d (input_chs Mid_chs, 3, padding=1),
BatchNorm2d (Mid_chs),
ReLU (),
)
Self. Conv2=Sequential (
Conv2d (Mid_chs output_chs, 3, padding=1),
BatchNorm2d (output_chs),
ReLU (),
)

Def forward (self, x) :
X=self. Conv1 (x)
X=self. Conv2 (x)
Return the x
# endregion

# region encoding, decoding, bridge structure definition
The class Conv_Group_En (Conv_33_a) :
Def __init__ (self, input_chs output_chs,) :
Super (Conv_Group_En, self) __init__ (input_chs output_chs,)


The class Conv_Group_De (Conv_33_b) :
Def __init__ (self, input_chs output_chs,) :
Super (Conv_Group_De, self) __init__ (input_chs output_chs,)


The class Conv_Group_Mid (Conv_33_mid) :
Def __init__ (self, input_chs output_chs) :
Super (Conv_Group_Mid, self) __init__ (input_chs output_chs,)


The class Bridge_connection (Module) :
Def __init__ (self, input_chs output_chs) :
# super (Bridge_connection, self) __init__ (input_chs output_chs)
Super (Bridge_connection, self) __init__ ()
Def forward (self, x) :
Return the x
# endregion

The class Unet (Module) :
Def __init__ (self) :
Super (Unet, self) __init__ ()

Mid_in_chs mid_out_chs=Layer4_chs, Layer4_chs

Self. En_conv1=Conv_Group_En (Img_chs Layer1_chs)
Self. En_conv2=Conv_Group_En (Layer1_chs Layer2_chs)
Self. En_conv3=Conv_Group_En (Layer2_chs Layer3_chs)
Self. En_conv4=Conv_Group_En (Layer3_chs Layer4_chs)

Self. En_down1=MaxPool2d (2, stride=2)
Self. En_down2=MaxPool2d (2, stride=2)
Self. En_down3=MaxPool2d (2, stride=2)
Self. En_down4=MaxPool2d (Mid_resize, stride=Mid_resize)

Self. Mid_layer=Conv_Group_Mid (mid_in_chs mid_out_chs)
Self. Bc4=Bridge_connection (Layer4_chs Layer4_chs)
Self. Bc3=Bridge_connection (Layer3_chs Layer3_chs)
Self. Bc2=Bridge_connection (Layer2_chs Layer2_chs)
Self. Bc1=Bridge_connection (Layer1_chs Layer1_chs)

Self. De_up4=ConvTranspose2d (Layer4_chs + mid_out_chs Layer4_chs, kernel_size=Mid_resize, stride=Mid_resize)
Self. De_up3=ConvTranspose2d (Layer3_chs * 2, Layer3_chs kernel_size=2, stride=2)
Self. De_up2=ConvTranspose2d (Layer2_chs * 2, Layer2_chs kernel_size=2, stride=2)
Self. De_up1=ConvTranspose2d (Layer1_chs * 2, Layer1_chs kernel_size=2, stride=2)

Self. De_conv4=Conv_Group_De (Layer4_chs Layer3_chs)
Self. De_conv3=Conv_Group_De (Layer3_chs Layer2_chs)
Self. De_conv2=Conv_Group_De (Layer2_chs Layer1_chs)
Self. De_conv1=Conv_Group_De (Layer1_chs Labels_nums)
Self. Act_output=Softmax ()
#
# self. De_conv1=Conv_Group_De (Layer1_chs Layer1_chs)
# self. Act_output=RRM_Bu (Layer1_chs Labels_nums)

Def forward (self, input) : # size size * * img_chs
Ec1=self. En_conv1 (input) ch1 # size size * *
Ed1=self. En_down1 (ec1) # size/size/2 * 2 * ch1
Ec2=self. En_conv2 (ed1) # size/size/2 * 2 * ch2
Ed2=self. En_down2 (ec2) # size/size/4 * 4 * ch2
Ec2=self. En_conv3 (ed2) # size/size/4 * 4 * ch3
Ed3=self. En_down3 (ec2) # size/size/8 * 8 * ch3
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related