r"""Densenet-BC model class, based on `"Densely Connected Convolutional Networks" `_ Args: growth_rate (int) - how many filters to add each layer (`k` in paper) block_config (list of 4 ints) - how many layers in each pooling block
| 85 | |
| 86 | |
| 87 | class DenseNet_features(nn.Module): |
| 88 | r"""Densenet-BC model class, based on |
| 89 | `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_ |
| 90 | |
| 91 | Args: |
| 92 | growth_rate (int) - how many filters to add each layer (`k` in paper) |
| 93 | block_config (list of 4 ints) - how many layers in each pooling block |
| 94 | num_init_features (int) - the number of filters to learn in the first convolution layer |
| 95 | bn_size (int) - multiplicative factor for number of bottle neck layers |
| 96 | (i.e. bn_size * k features in the bottleneck layer) |
| 97 | drop_rate (float) - dropout rate after each dense layer |
| 98 | num_classes (int) - number of classification classes |
| 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) |
no outgoing calls
no test coverage detected