(self, growth_rate=32, block_config=(6, 12, 24, 16),
num_init_features=64, bn_size=4, drop_rate=0, num_classes=1000)
| 99 | """ |
| 100 | |
| 101 | def __init__(self, growth_rate=32, block_config=(6, 12, 24, 16), |
| 102 | num_init_features=64, bn_size=4, drop_rate=0, num_classes=1000): |
| 103 | |
| 104 | super(DenseNet_features, self).__init__() |
| 105 | self.kernel_sizes = [] |
| 106 | self.strides = [] |
| 107 | self.paddings = [] |
| 108 | |
| 109 | self.n_layers = 0 |
| 110 | |
| 111 | # First convolution |
| 112 | self.features = nn.Sequential(OrderedDict([ |
| 113 | ('conv0', nn.Conv2d(in_channels=3, out_channels=num_init_features, kernel_size=7, stride=2, padding=3, bias=False)), |
| 114 | ('norm0', nn.BatchNorm2d(num_init_features)), |
| 115 | ('relu0', nn.ReLU(inplace=True)), |
| 116 | ('pool0', nn.MaxPool2d(kernel_size=3, stride=2, padding=1)), |
| 117 | ])) |
| 118 | |
| 119 | self.kernel_sizes.extend([7, 3]) |
| 120 | self.strides.extend([2, 2]) |
| 121 | self.paddings.extend([3, 1]) |
| 122 | |
| 123 | # Each denseblock |
| 124 | num_features = num_init_features |
| 125 | for i, num_layers in enumerate(block_config): |
| 126 | block = _DenseBlock(num_layers=num_layers, num_input_features=num_features, |
| 127 | bn_size=bn_size, growth_rate=growth_rate, drop_rate=drop_rate) |
| 128 | self.n_layers += block.num_layers |
| 129 | |
| 130 | block_kernel_sizes, block_strides, block_paddings = block.block_conv_info() |
| 131 | self.kernel_sizes.extend(block_kernel_sizes) |
| 132 | self.strides.extend(block_strides) |
| 133 | self.paddings.extend(block_paddings) |
| 134 | |
| 135 | self.features.add_module('denseblock%d' % (i + 1), block) |
| 136 | num_features = num_features + num_layers * growth_rate |
| 137 | if i != len(block_config) - 1: |
| 138 | trans = _Transition(num_input_features=num_features, num_output_features=num_features // 2) |
| 139 | |
| 140 | self.n_layers += trans.num_layers |
| 141 | |
| 142 | block_kernel_sizes, block_strides, block_paddings = trans.block_conv_info() |
| 143 | self.kernel_sizes.extend(block_kernel_sizes) |
| 144 | self.strides.extend(block_strides) |
| 145 | self.paddings.extend(block_paddings) |
| 146 | |
| 147 | self.features.add_module('transition%d' % (i + 1), trans) |
| 148 | num_features = num_features // 2 |
| 149 | |
| 150 | # Final batch norm |
| 151 | self.features.add_module('norm5', nn.BatchNorm2d(num_features)) |
| 152 | self.features.add_module('final_relu', nn.ReLU(inplace=True)) |
| 153 | |
| 154 | # Official init from torch repo. |
| 155 | for m in self.modules(): |
| 156 | if isinstance(m, nn.Conv2d): |
| 157 | nn.init.kaiming_normal_(m.weight) |
| 158 | elif isinstance(m, nn.BatchNorm2d): |
nothing calls this directly
no test coverage detected