LeeJunHyun / Image_Segmentation

Pytorch implementation of U-Net, R2U-Net, Attention U-Net, and Attention R2U-Net.
2.66k stars 594 forks source link

Model prediction error #47

Closed peterhsu2018 closed 1 year ago

peterhsu2018 commented 4 years ago

Training is fine, when I tested an image and got a error message as follow: UnboundLocalError: local variable 'x1' referenced before assignment

The error occur from network.py

60 class Recurrent_block(nn.Module):
61    def __init__(self,ch_out,t=2):
62        super(Recurrent_block,self).__init__()
63        self.t = t
64        self.ch_out = ch_out
65        self.conv = nn.Sequential(
66            nn.Conv2d(ch_out,ch_out,kernel_size=3,stride=1,padding=1,bias=True),
67          nn.BatchNorm2d(ch_out),
68          nn.ReLU(inplace=True)
69        )
70
71    def forward(self,x):
72        for i in range(self.t):
73
74            if i==0:
75                x1 = self.conv(x)
76            
77           x1 = self.conv(x+x1)
78        return x1           <====================== error here

How to fix it? Thanks a lot