(self, inplanes, planes, reps, stride=1, dilation=1,
BatchNorm=None, start_with_relu=True, grow_first=True,
is_last=False)
| 42 | |
| 43 | class Block(nn.Module): |
| 44 | def __init__(self, inplanes, planes, reps, stride=1, dilation=1, |
| 45 | BatchNorm=None, start_with_relu=True, grow_first=True, |
| 46 | is_last=False): |
| 47 | super(Block, self).__init__() |
| 48 | |
| 49 | if planes != inplanes or stride != 1: |
| 50 | self.skip = nn.Conv2d(inplanes, planes, 1, stride=stride, |
| 51 | bias=False) |
| 52 | self.skipbn = BatchNorm(planes) |
| 53 | else: |
| 54 | self.skip = None |
| 55 | |
| 56 | self.relu = nn.ReLU(inplace=True) |
| 57 | rep = [] |
| 58 | |
| 59 | filters = inplanes |
| 60 | if grow_first: |
| 61 | rep.append(self.relu) |
| 62 | rep.append(SeparableConv2d(inplanes, planes, 3, 1, dilation, |
| 63 | BatchNorm=BatchNorm)) |
| 64 | rep.append(BatchNorm(planes)) |
| 65 | filters = planes |
| 66 | |
| 67 | for i in range(reps - 1): |
| 68 | rep.append(self.relu) |
| 69 | rep.append(SeparableConv2d(filters, filters, 3, 1, dilation, |
| 70 | BatchNorm=BatchNorm)) |
| 71 | rep.append(BatchNorm(filters)) |
| 72 | |
| 73 | if not grow_first: |
| 74 | rep.append(self.relu) |
| 75 | rep.append(SeparableConv2d(inplanes, planes, 3, 1, dilation, |
| 76 | BatchNorm=BatchNorm)) |
| 77 | rep.append(BatchNorm(planes)) |
| 78 | |
| 79 | if stride != 1: |
| 80 | rep.append(self.relu) |
| 81 | rep.append(SeparableConv2d(planes, planes, 3, 2, |
| 82 | BatchNorm=BatchNorm)) |
| 83 | rep.append(BatchNorm(planes)) |
| 84 | |
| 85 | if stride == 1 and is_last: |
| 86 | rep.append(self.relu) |
| 87 | rep.append(SeparableConv2d(planes, planes, 3, 1, |
| 88 | BatchNorm=BatchNorm)) |
| 89 | rep.append(BatchNorm(planes)) |
| 90 | |
| 91 | if not start_with_relu: |
| 92 | rep = rep[1:] |
| 93 | |
| 94 | self.rep = nn.Sequential(*rep) |
| 95 | |
| 96 | def forward(self, inp): |
| 97 | x = self.rep(inp) |
no test coverage detected