| 24 | |
| 25 | class BasicBlock(nn.Module): |
| 26 | def __init__(self, in_planes, out_planes, stride, drop_rate=0.0, activate_before_residual=False): |
| 27 | super(BasicBlock, self).__init__() |
| 28 | self.bn1 = nn.BatchNorm2d(in_planes, momentum=0.001, eps=0.001) |
| 29 | self.relu1 = nn.LeakyReLU(negative_slope=0.1, inplace=False) |
| 30 | self.conv1 = nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, |
| 31 | padding=1, bias=True) |
| 32 | self.bn2 = nn.BatchNorm2d(out_planes, momentum=0.001, eps=0.001) |
| 33 | self.relu2 = nn.LeakyReLU(negative_slope=0.1, inplace=False) |
| 34 | self.conv2 = nn.Conv2d(out_planes, out_planes, kernel_size=3, stride=1, |
| 35 | padding=1, bias=True) |
| 36 | self.drop_rate = drop_rate |
| 37 | self.equalInOut = (in_planes == out_planes) |
| 38 | self.convShortcut = (not self.equalInOut) and nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, |
| 39 | padding=0, bias=True) or None |
| 40 | self.activate_before_residual = activate_before_residual |
| 41 | |
| 42 | def forward(self, x): |
| 43 | if not self.equalInOut and self.activate_before_residual == True: |