| 2 | |
| 3 | |
| 4 | def _make_scratch(in_shape, out_shape, groups=1, expand=False): |
| 5 | scratch = nn.Module() |
| 6 | |
| 7 | out_shape1 = out_shape |
| 8 | out_shape2 = out_shape |
| 9 | out_shape3 = out_shape |
| 10 | if len(in_shape) >= 4: |
| 11 | out_shape4 = out_shape |
| 12 | |
| 13 | if expand: |
| 14 | out_shape1 = out_shape |
| 15 | out_shape2 = out_shape * 2 |
| 16 | out_shape3 = out_shape * 4 |
| 17 | if len(in_shape) >= 4: |
| 18 | out_shape4 = out_shape * 8 |
| 19 | |
| 20 | scratch.layer1_rn = nn.Conv2d(in_shape[0], out_shape1, kernel_size=3, stride=1, padding=1, bias=False, groups=groups) |
| 21 | scratch.layer2_rn = nn.Conv2d(in_shape[1], out_shape2, kernel_size=3, stride=1, padding=1, bias=False, groups=groups) |
| 22 | scratch.layer3_rn = nn.Conv2d(in_shape[2], out_shape3, kernel_size=3, stride=1, padding=1, bias=False, groups=groups) |
| 23 | if len(in_shape) >= 4: |
| 24 | scratch.layer4_rn = nn.Conv2d(in_shape[3], out_shape4, kernel_size=3, stride=1, padding=1, bias=False, groups=groups) |
| 25 | |
| 26 | return scratch |
| 27 | |
| 28 | |
| 29 | class ResidualConvUnit(nn.Module): |