Adds a Inception-ResNet block. This function builds 3 types of Inception-ResNet blocks mentioned in the paper, controlled by the `block_type` argument (which is the block name used in the official TF-slim implementation): - Inception-ResNet-A: `block_type='block35'` - In
(x, scale, block_type, block_idx, activation='relu')
| 101 | |
| 102 | |
| 103 | def inception_resnet_block(x, scale, block_type, block_idx, activation='relu'): |
| 104 | """Adds a Inception-ResNet block. |
| 105 | |
| 106 | This function builds 3 types of Inception-ResNet blocks mentioned |
| 107 | in the paper, controlled by the `block_type` argument (which is the |
| 108 | block name used in the official TF-slim implementation): |
| 109 | - Inception-ResNet-A: `block_type='block35'` |
| 110 | - Inception-ResNet-B: `block_type='block17'` |
| 111 | - Inception-ResNet-C: `block_type='block8'` |
| 112 | |
| 113 | # Arguments |
| 114 | x: input tensor. |
| 115 | scale: scaling factor to scale the residuals (i.e., the output of |
| 116 | passing `x` through an inception module) before adding them |
| 117 | to the shortcut branch. Let `r` be the output from the residual branch, |
| 118 | the output of this block will be `x + scale * r`. |
| 119 | block_type: `'block35'`, `'block17'` or `'block8'`, determines |
| 120 | the network structure in the residual branch. |
| 121 | block_idx: an `int` used for generating layer names. The Inception-ResNet blocks |
| 122 | are repeated many times in this network. We use `block_idx` to identify |
| 123 | each of the repetitions. For example, the first Inception-ResNet-A block |
| 124 | will have `block_type='block35', block_idx=0`, ane the layer names will have |
| 125 | a common prefix `'block35_0'`. |
| 126 | activation: activation function to use at the end of the block |
| 127 | (see [activations](keras./activations.md)). |
| 128 | When `activation=None`, no activation is applied |
| 129 | (i.e., "linear" activation: `a(x) = x`). |
| 130 | |
| 131 | # Returns |
| 132 | Output tensor for the block. |
| 133 | |
| 134 | # Raises |
| 135 | ValueError: if `block_type` is not one of `'block35'`, |
| 136 | `'block17'` or `'block8'`. |
| 137 | """ |
| 138 | if block_type == 'block35': |
| 139 | branch_0 = conv2d_bn(x, 32, 1) |
| 140 | branch_1 = conv2d_bn(x, 32, 1) |
| 141 | branch_1 = conv2d_bn(branch_1, 32, 3) |
| 142 | branch_2 = conv2d_bn(x, 32, 1) |
| 143 | branch_2 = conv2d_bn(branch_2, 48, 3) |
| 144 | branch_2 = conv2d_bn(branch_2, 64, 3) |
| 145 | branches = [branch_0, branch_1, branch_2] |
| 146 | elif block_type == 'block17': |
| 147 | branch_0 = conv2d_bn(x, 192, 1) |
| 148 | branch_1 = conv2d_bn(x, 128, 1) |
| 149 | branch_1 = conv2d_bn(branch_1, 160, [1, 7]) |
| 150 | branch_1 = conv2d_bn(branch_1, 192, [7, 1]) |
| 151 | branches = [branch_0, branch_1] |
| 152 | elif block_type == 'block8': |
| 153 | branch_0 = conv2d_bn(x, 192, 1) |
| 154 | branch_1 = conv2d_bn(x, 192, 1) |
| 155 | branch_1 = conv2d_bn(branch_1, 224, [1, 3]) |
| 156 | branch_1 = conv2d_bn(branch_1, 256, [3, 1]) |
| 157 | branches = [branch_0, branch_1] |
| 158 | else: |
| 159 | raise ValueError('Unknown Inception-ResNet block type. ' |
| 160 | 'Expects "block35", "block17" or "block8", ' |
no test coverage detected