| 100 | nn.init.constant_(m.bias, 0) |
| 101 | |
| 102 | class Inception(nn.Module): |
| 103 | def __init__(self, in_channels, ch1x1, ch3x3red, ch3x3, ch5x5red, ch5x5, pool_proj): |
| 104 | super(Inception, self).__init__() |
| 105 | self.branch1 = BasicConv2d(in_channels, ch1x1, kernel_size=1) |
| 106 | |
| 107 | self.branch2 = nn.Sequential( |
| 108 | BasicConv2d(in_channels, ch3x3red, kernel_size=1), |
| 109 | BasicConv2d(ch3x3red, ch3x3, kernel_size=3, padding=1) |
| 110 | ) |
| 111 | |
| 112 | self.branch3 = nn.Sequential( |
| 113 | BasicConv2d(in_channels, ch5x5red, kernel_size=1), |
| 114 | BasicConv2d(ch5x5red, ch5x5, kernel_size=5, padding=5) |
| 115 | ) |
| 116 | |
| 117 | self.branch4 = nn.Sequential( |
| 118 | nn.MaxPool2d(kernel_size=3, stride=1, padding=1), |
| 119 | BasicConv2d(in_channels, pool_proj, kernel_size=1) |
| 120 | ) |
| 121 | |
| 122 | def forward(self, x): |
| 123 | branch1 = self.branch1(x) |
| 124 | branch2 = self.branch2(x) |
| 125 | branch3 = self.branch3(x) |
| 126 | branch4 = self.branch4(x) |
| 127 | |
| 128 | outputs = [branch1, branch2, branch3, branch4] |
| 129 | return torch.cat(outputs, 1) |
| 130 | |
| 131 | # 定义辅助分类器结构 |
| 132 | class InceptionAux(nn.Module): |