The conv block where there is a conv layer at shortcut. Parameters ---------- input : tf tensor Input tensor from above layer. kernel_size : int The kernel size of middle conv layer at main path. n_filters : list of integers The numbers of filters for 3 c
(input, kernel_size, n_filters, stage, block, strides=(2, 2))
| 62 | |
| 63 | |
| 64 | def conv_block(input, kernel_size, n_filters, stage, block, strides=(2, 2)): |
| 65 | """The conv block where there is a conv layer at shortcut. |
| 66 | |
| 67 | Parameters |
| 68 | ---------- |
| 69 | input : tf tensor |
| 70 | Input tensor from above layer. |
| 71 | kernel_size : int |
| 72 | The kernel size of middle conv layer at main path. |
| 73 | n_filters : list of integers |
| 74 | The numbers of filters for 3 conv layer at main path. |
| 75 | stage : int |
| 76 | Current stage label. |
| 77 | block : str |
| 78 | Current block label. |
| 79 | strides : tuple |
| 80 | Strides for the first conv layer in the block. |
| 81 | |
| 82 | Returns |
| 83 | ------- |
| 84 | Output tensor of this block. |
| 85 | |
| 86 | """ |
| 87 | filters1, filters2, filters3 = n_filters |
| 88 | conv_name_base = 'res' + str(stage) + block + '_branch' |
| 89 | bn_name_base = 'bn' + str(stage) + block + '_branch' |
| 90 | |
| 91 | x = Conv2d(filters1, (1, 1), strides=strides, W_init=tf.initializers.he_normal(), name=conv_name_base + '2a')(input) |
| 92 | x = BatchNorm(name=bn_name_base + '2a', act='relu')(x) |
| 93 | |
| 94 | ks = (kernel_size, kernel_size) |
| 95 | x = Conv2d(filters2, ks, padding='SAME', W_init=tf.initializers.he_normal(), name=conv_name_base + '2b')(x) |
| 96 | x = BatchNorm(name=bn_name_base + '2b', act='relu')(x) |
| 97 | |
| 98 | x = Conv2d(filters3, (1, 1), W_init=tf.initializers.he_normal(), name=conv_name_base + '2c')(x) |
| 99 | x = BatchNorm(name=bn_name_base + '2c')(x) |
| 100 | |
| 101 | shortcut = Conv2d(filters3, (1, 1), strides=strides, W_init=tf.initializers.he_normal(), |
| 102 | name=conv_name_base + '1')(input) |
| 103 | shortcut = BatchNorm(name=bn_name_base + '1')(shortcut) |
| 104 | |
| 105 | x = Elementwise(tf.add, act='relu')([x, shortcut]) |
| 106 | return x |
| 107 | |
| 108 | |
| 109 | block_names = ['2a', '2b', '2c', '3a', '3b', '3c', '3d', '4a', '4b', '4c', '4d', '4e', '4f', '5a', '5b', '5c' |
no test coverage detected
searching dependent graphs…