conv_block is the block that has a conv layer at shortcut # Arguments input_tensor: input tensor kernel_size: defualt 3, the kernel size of middle conv layer at main path filters: list of integers, the filterss of 3 conv layer at main path stage: integer, current
(input_tensor, kernel_size, filters, stage, block, strides=(2, 2))
| 78 | |
| 79 | |
| 80 | def conv_block(input_tensor, kernel_size, filters, stage, block, strides=(2, 2)): |
| 81 | """conv_block is the block that has a conv layer at shortcut |
| 82 | |
| 83 | # Arguments |
| 84 | input_tensor: input tensor |
| 85 | kernel_size: defualt 3, the kernel size of middle conv layer at main path |
| 86 | filters: list of integers, the filterss of 3 conv layer at main path |
| 87 | stage: integer, current stage label, used for generating layer names |
| 88 | block: 'a','b'..., current block label, used for generating layer names |
| 89 | |
| 90 | # Returns |
| 91 | Output tensor for the block. |
| 92 | |
| 93 | Note that from stage 3, the first conv layer at main path is with strides=(2,2) |
| 94 | And the shortcut should have strides=(2,2) as well |
| 95 | """ |
| 96 | filters1, filters2, filters3 = filters |
| 97 | if K.image_data_format() == 'channels_last': |
| 98 | bn_axis = 3 |
| 99 | else: |
| 100 | bn_axis = 1 |
| 101 | conv_name_base = 'res' + str(stage) + block + '_branch' |
| 102 | bn_name_base = 'bn' + str(stage) + block + '_branch' |
| 103 | |
| 104 | x = Conv2D(filters1, (1, 1), strides=strides, |
| 105 | name=conv_name_base + '2a')(input_tensor) |
| 106 | x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2a')(x) |
| 107 | x = Activation('relu')(x) |
| 108 | |
| 109 | x = Conv2D(filters2, kernel_size, padding='same', |
| 110 | name=conv_name_base + '2b')(x) |
| 111 | x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2b')(x) |
| 112 | x = Activation('relu')(x) |
| 113 | |
| 114 | x = Conv2D(filters3, (1, 1), name=conv_name_base + '2c')(x) |
| 115 | x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2c')(x) |
| 116 | |
| 117 | shortcut = Conv2D(filters3, (1, 1), strides=strides, |
| 118 | name=conv_name_base + '1')(input_tensor) |
| 119 | shortcut = BatchNormalization(axis=bn_axis, name=bn_name_base + '1')(shortcut) |
| 120 | |
| 121 | x = layers.add([x, shortcut]) |
| 122 | x = Activation('relu')(x) |
| 123 | return x |
| 124 | |
| 125 | |
| 126 | def ResNet50(include_top=True, weights='imagenet', |