|
def | SEResNet (input_shape=None, initial_conv_filters=64, depth=[3, filters=[64, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000) |
|
def | SEResNet18 (input_shape=None, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000) |
|
def | SEResNet34 (input_shape=None, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000) |
|
def | SEResNet50 (input_shape=None, width=1, bottleneck=True, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000) |
|
def | SEResNet101 (input_shape=None, width=1, bottleneck=True, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000) |
|
def | SEResNet154 (input_shape=None, width=1, bottleneck=True, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000) |
|
def | _resnet_block (input, filters, k=1, strides=(1, 1)) |
|
def | _resnet_bottleneck_block (input, filters, k=1, strides=(1, 1)) |
|
def | _create_se_resnet (classes, img_input, include_top, initial_conv_filters, filters, depth, width, bottleneck, weight_decay, pooling) |
|
Based on https://github.com/titu1994/keras-squeeze-excite-network/blob/master/se_resnet.py
Squeeze-and-Excitation ResNets
References:
- [Deep Residual Learning for Image Recognition](https://arxiv.org/abs/1512.03385)
- []() # added when paper is published on Arxiv
def se_resnet_saul._create_se_resnet |
( |
|
classes, |
|
|
|
img_input, |
|
|
|
include_top, |
|
|
|
initial_conv_filters, |
|
|
|
filters, |
|
|
|
depth, |
|
|
|
width, |
|
|
|
bottleneck, |
|
|
|
weight_decay, |
|
|
|
pooling |
|
) |
| |
|
private |
Creates a SE ResNet model with specified parameters
Args:
initial_conv_filters: number of features for the initial convolution
include_top: Flag to include the last dense layer
filters: number of filters per block, defined as a list.
filters = [64, 128, 256, 512
depth: number or layers in the each block, defined as a list.
ResNet-50 = [3, 4, 6, 3]
ResNet-101 = [3, 6, 23, 3]
ResNet-152 = [3, 8, 36, 3]
width: width multiplier for network (for Wide ResNet)
bottleneck: adds a bottleneck conv to reduce computation
weight_decay: weight_decay (l2 norm)
pooling: Optional pooling mode for feature extraction
when `include_top` is `False`.
- `None` means that the output of the model will be
the 4D tensor output of the
last convolutional layer.
- `avg` means that global average pooling
will be applied to the output of the
last convolutional layer, and thus
the output of the model will be a 2D tensor.
- `max` means that global max pooling will
be applied.
Returns: a Keras Model
Definition at line 330 of file se_resnet_saul.py.
330 depth, width, bottleneck, weight_decay, pooling):
331 '''Creates a SE ResNet model with specified parameters 333 initial_conv_filters: number of features for the initial convolution 334 include_top: Flag to include the last dense layer 335 filters: number of filters per block, defined as a list. 336 filters = [64, 128, 256, 512 337 depth: number or layers in the each block, defined as a list. 338 ResNet-50 = [3, 4, 6, 3] 339 ResNet-101 = [3, 6, 23, 3] 340 ResNet-152 = [3, 8, 36, 3] 341 width: width multiplier for network (for Wide ResNet) 342 bottleneck: adds a bottleneck conv to reduce computation 343 weight_decay: weight_decay (l2 norm) 344 pooling: Optional pooling mode for feature extraction 345 when `include_top` is `False`. 346 - `None` means that the output of the model will be 347 the 4D tensor output of the 348 last convolutional layer. 349 - `avg` means that global average pooling 350 will be applied to the output of the 351 last convolutional layer, and thus 352 the output of the model will be a 2D tensor. 353 - `max` means that global max pooling will 355 Returns: a Keras Model 358 channel_axis = 1
if K.image_data_format() ==
'channels_first' else -1
364 for i
in range(len(img_input)):
367 branch = Conv2D(initial_conv_filters, (7, 7), padding=
'same', use_bias=
False, strides=(2, 2),
368 kernel_initializer=
'he_normal', kernel_regularizer=l2(weight_decay))(img_input[i])
370 branch = MaxPooling2D((3, 3), strides=(2, 2), padding=
'same')(branch)
373 for i
in range(N[0]):
379 branches.append(branch)
384 # block 1 (initial conv block) 385 x = Conv2D(initial_conv_filters, (7, 7), padding='same', use_bias=False, strides=(2, 2), 386 kernel_initializer='he_normal', kernel_regularizer=l2(weight_decay))(img_input) 388 x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x) 390 # block 2 (projection block) 391 for i in range(N[0]): 393 x = _resnet_bottleneck_block(x, filters[0], width) 395 x = _resnet_block(x, filters[0], width) 399 for k
in range(1, len(N)):
405 for i
in range(N[k] - 1):
411 x = BatchNormalization(axis=channel_axis)(x)
412 x = Activation(
'relu')(x)
415 x = GlobalAveragePooling2D()(x)
416 x = Dense(classes, use_bias=
False, kernel_regularizer=l2(weight_decay),
417 activation=
'sigmoid', name=
'output')(x)
420 x = GlobalAveragePooling2D()(x)
421 elif pooling ==
'max':
422 x = GlobalMaxPooling2D()(x)
425 def _resnet_bottleneck_block(input, filters, k=1, strides=(1, 1))
std::string concatenate(H const &h, T const &...t)
def _resnet_block(input, filters, k=1, strides=(1, 1))
def se_resnet_saul._resnet_block |
( |
|
input, |
|
|
|
filters, |
|
|
|
k = 1 , |
|
|
|
strides = (1, 1) |
|
) |
| |
|
private |
Adds a pre-activation resnet block without bottleneck layers
Args:
input: input tensor
filters: number of output filters
k: width factor
strides: strides of the convolution layer
Returns: a keras tensor
Definition at line 251 of file se_resnet_saul.py.
252 ''' Adds a pre-activation resnet block without bottleneck layers 256 filters: number of output filters 258 strides: strides of the convolution layer 260 Returns: a keras tensor 263 channel_axis = 1
if K.image_data_format() ==
"channels_first" else -1
265 x = BatchNormalization(axis=channel_axis)(input)
266 x = Activation(
'relu')(x)
268 if strides != (1, 1)
or init._keras_shape[channel_axis] != filters * k:
269 init = Conv2D(filters * k, (1, 1), padding=
'same', kernel_initializer=
'he_normal',
270 use_bias=
False, strides=strides)(x)
272 x = Conv2D(filters * k, (3, 3), padding=
'same', kernel_initializer=
'he_normal',
273 use_bias=
False, strides=strides)(x)
274 x = BatchNormalization(axis=channel_axis)(x)
275 x = Activation(
'relu')(x)
277 x = Conv2D(filters * k, (3, 3), padding=
'same', kernel_initializer=
'he_normal',
Coord add(Coord c1, Coord c2)
def squeeze_excite_block(input, ratio=16)
def _resnet_block(input, filters, k=1, strides=(1, 1))
def se_resnet_saul._resnet_bottleneck_block |
( |
|
input, |
|
|
|
filters, |
|
|
|
k = 1 , |
|
|
|
strides = (1, 1) |
|
) |
| |
|
private |
Adds a pre-activation resnet block with bottleneck layers
Args:
input: input tensor
filters: number of output filters
k: width factor
strides: strides of the convolution layer
Returns: a keras tensor
Definition at line 287 of file se_resnet_saul.py.
288 ''' Adds a pre-activation resnet block with bottleneck layers 292 filters: number of output filters 294 strides: strides of the convolution layer 296 Returns: a keras tensor 299 channel_axis = 1
if K.image_data_format() ==
"channels_first" else -1
300 bottleneck_expand = 4
302 x = BatchNormalization(axis=channel_axis)(input)
303 x = Activation(
'relu')(x)
305 if strides != (1, 1)
or init._keras_shape[channel_axis] != bottleneck_expand * filters * k:
306 init = Conv2D(bottleneck_expand * filters * k, (1, 1), padding=
'same', kernel_initializer=
'he_normal',
307 use_bias=
False, strides=strides)(x)
309 x = Conv2D(filters * k, (1, 1), padding=
'same', kernel_initializer=
'he_normal',
311 x = BatchNormalization(axis=channel_axis)(x)
312 x = Activation(
'relu')(x)
314 x = Conv2D(filters * k, (3, 3), padding=
'same', kernel_initializer=
'he_normal',
315 use_bias=
False, strides=strides)(x)
316 x = BatchNormalization(axis=channel_axis)(x)
317 x = Activation(
'relu')(x)
319 x = Conv2D(bottleneck_expand * filters * k, (1, 1), padding=
'same', kernel_initializer=
'he_normal',
def _resnet_bottleneck_block(input, filters, k=1, strides=(1, 1))
Coord add(Coord c1, Coord c2)
def squeeze_excite_block(input, ratio=16)
def se_resnet_saul.SEResNet |
( |
|
input_shape = None , |
|
|
|
initial_conv_filters = 64 , |
|
|
|
depth = [3 , |
|
|
|
filters = [64 , |
|
|
|
width = 1 , |
|
|
|
bottleneck = False , |
|
|
|
weight_decay = 1e-4 , |
|
|
|
include_top = True , |
|
|
|
weights = None , |
|
|
|
input_tensor = None , |
|
|
|
pooling = None , |
|
|
|
classes = 1000 |
|
) |
| |
Instantiate the Squeeze and Excite ResNet architecture. Note that ,
when using TensorFlow for best performance you should set
`image_data_format="channels_last"` in your Keras config
at ~/.keras/keras.json.
The model are compatible with both
TensorFlow and Theano. The dimension ordering
convention used by the model is the one
specified in your Keras config file.
# Arguments
initial_conv_filters: number of features for the initial convolution
depth: number or layers in the each block, defined as a list.
ResNet-50 = [3, 4, 6, 3]
ResNet-101 = [3, 6, 23, 3]
ResNet-152 = [3, 8, 36, 3]
filter: number of filters per block, defined as a list.
filters = [64, 128, 256, 512
width: width multiplier for the network (for Wide ResNets)
bottleneck: adds a bottleneck conv to reduce computation
weight_decay: weight decay (l2 norm)
include_top: whether to include the fully-connected
layer at the top of the network.
weights: `None` (random initialization) or `imagenet` (trained
on ImageNet)
input_tensor: optional Keras tensor (i.e. output of `layers.Input()`)
to use as image input for the model.
input_shape: optional shape tuple, only to be specified
if `include_top` is False (otherwise the input shape
has to be `(224, 224, 3)` (with `tf` dim ordering)
or `(3, 224, 224)` (with `th` dim ordering).
It should have exactly 3 inputs channels,
and width and height should be no smaller than 8.
E.g. `(200, 200, 3)` would be one valid value.
pooling: Optional pooling mode for feature extraction
when `include_top` is `False`.
- `None` means that the output of the model will be
the 4D tensor output of the
last convolutional layer.
- `avg` means that global average pooling
will be applied to the output of the
last convolutional layer, and thus
the output of the model will be a 2D tensor.
- `max` means that global max pooling will
be applied.
classes: optional number of classes to classify images
into, only to be specified if `include_top` is True, and
if no `weights` argument is specified.
# Returns
A Keras model instance.
Definition at line 56 of file se_resnet_saul.py.
57 """ Instantiate the Squeeze and Excite ResNet architecture. Note that , 58 when using TensorFlow for best performance you should set 59 `image_data_format="channels_last"` in your Keras config 60 at ~/.keras/keras.json. 61 The model are compatible with both 62 TensorFlow and Theano. The dimension ordering 63 convention used by the model is the one 64 specified in your Keras config file. 66 initial_conv_filters: number of features for the initial convolution 67 depth: number or layers in the each block, defined as a list. 68 ResNet-50 = [3, 4, 6, 3] 69 ResNet-101 = [3, 6, 23, 3] 70 ResNet-152 = [3, 8, 36, 3] 71 filter: number of filters per block, defined as a list. 72 filters = [64, 128, 256, 512 73 width: width multiplier for the network (for Wide ResNets) 74 bottleneck: adds a bottleneck conv to reduce computation 75 weight_decay: weight decay (l2 norm) 76 include_top: whether to include the fully-connected 77 layer at the top of the network. 78 weights: `None` (random initialization) or `imagenet` (trained 80 input_tensor: optional Keras tensor (i.e. output of `layers.Input()`) 81 to use as image input for the model. 82 input_shape: optional shape tuple, only to be specified 83 if `include_top` is False (otherwise the input shape 84 has to be `(224, 224, 3)` (with `tf` dim ordering) 85 or `(3, 224, 224)` (with `th` dim ordering). 86 It should have exactly 3 inputs channels, 87 and width and height should be no smaller than 8. 88 E.g. `(200, 200, 3)` would be one valid value. 89 pooling: Optional pooling mode for feature extraction 90 when `include_top` is `False`. 91 - `None` means that the output of the model will be 92 the 4D tensor output of the 93 last convolutional layer. 94 - `avg` means that global average pooling 95 will be applied to the output of the 96 last convolutional layer, and thus 97 the output of the model will be a 2D tensor. 98 - `max` means that global max pooling will 100 classes: optional number of classes to classify images 101 into, only to be specified if `include_top` is True, and 102 if no `weights` argument is specified. 104 A Keras model instance. 107 if weights
not in {
'imagenet',
None}:
108 raise ValueError(
'The `weights` argument should be either ' 109 '`None` (random initialization) or `imagenet` ' 110 '(pre-training on ImageNet).')
112 if weights ==
'imagenet' and include_top
and classes != 1000:
113 raise ValueError(
'If using `weights` as imagenet with `include_top`' 114 ' as true, `classes` should be 1000')
116 assert len(depth) == len(filters),
"The length of filter increment list must match the length " \
123 data_format=K.image_data_format(),
124 require_flatten=
False)
126 if input_tensor
is None:
128 img_input1 = Input(shape=input_shape, name=
'view0')
129 img_input2 = Input(shape=input_shape, name=
'view1')
130 img_input3 = Input(shape=input_shape, name=
'view2')
132 img_input = [img_input1, img_input2, img_input3]
135 filters, depth, width, bottleneck, weight_decay, pooling)
140 model = Model(inputs=inputs, outputs=x, name=
'resnext')
def _create_se_resnet(classes, img_input, include_top, initial_conv_filters, filters, depth, width, bottleneck, weight_decay, pooling)
def _obtain_input_shape(input_shape, default_size, min_size, data_format, require_flatten, weights=None)
def se_resnet_saul.SEResNet101 |
( |
|
input_shape = None , |
|
|
|
width = 1 , |
|
|
|
bottleneck = True , |
|
|
|
weight_decay = 1e-4 , |
|
|
|
include_top = True , |
|
|
|
weights = None , |
|
|
|
input_tensor = None , |
|
|
|
pooling = None , |
|
|
|
classes = 1000 |
|
) |
| |
Definition at line 217 of file se_resnet_saul.py.
221 bottleneck=bottleneck,
222 weight_decay=weight_decay,
223 include_top=include_top,
225 input_tensor=input_tensor,
def SEResNet(input_shape=None, initial_conv_filters=64, depth=[3, filters=[64, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
def se_resnet_saul.SEResNet154 |
( |
|
input_shape = None , |
|
|
|
width = 1 , |
|
|
|
bottleneck = True , |
|
|
|
weight_decay = 1e-4 , |
|
|
|
include_top = True , |
|
|
|
weights = None , |
|
|
|
input_tensor = None , |
|
|
|
pooling = None , |
|
|
|
classes = 1000 |
|
) |
| |
Definition at line 238 of file se_resnet_saul.py.
242 bottleneck=bottleneck,
243 weight_decay=weight_decay,
244 include_top=include_top,
246 input_tensor=input_tensor,
def SEResNet(input_shape=None, initial_conv_filters=64, depth=[3, filters=[64, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
def se_resnet_saul.SEResNet18 |
( |
|
input_shape = None , |
|
|
|
width = 1 , |
|
|
|
bottleneck = False , |
|
|
|
weight_decay = 1e-4 , |
|
|
|
include_top = True , |
|
|
|
weights = None , |
|
|
|
input_tensor = None , |
|
|
|
pooling = None , |
|
|
|
classes = 1000 |
|
) |
| |
Definition at line 155 of file se_resnet_saul.py.
159 bottleneck=bottleneck,
160 weight_decay=weight_decay,
161 include_top=include_top,
163 input_tensor=input_tensor,
def SEResNet(input_shape=None, initial_conv_filters=64, depth=[3, filters=[64, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
def se_resnet_saul.SEResNet34 |
( |
|
input_shape = None , |
|
|
|
width = 1 , |
|
|
|
bottleneck = False , |
|
|
|
weight_decay = 1e-4 , |
|
|
|
include_top = True , |
|
|
|
weights = None , |
|
|
|
input_tensor = None , |
|
|
|
pooling = None , |
|
|
|
classes = 1000 |
|
) |
| |
Definition at line 176 of file se_resnet_saul.py.
180 bottleneck=bottleneck,
181 weight_decay=weight_decay,
182 include_top=include_top,
184 input_tensor=input_tensor,
def SEResNet(input_shape=None, initial_conv_filters=64, depth=[3, filters=[64, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
def se_resnet_saul.SEResNet50 |
( |
|
input_shape = None , |
|
|
|
width = 1 , |
|
|
|
bottleneck = True , |
|
|
|
weight_decay = 1e-4 , |
|
|
|
include_top = True , |
|
|
|
weights = None , |
|
|
|
input_tensor = None , |
|
|
|
pooling = None , |
|
|
|
classes = 1000 |
|
) |
| |
Definition at line 197 of file se_resnet_saul.py.
200 bottleneck=bottleneck,
201 weight_decay=weight_decay,
202 include_top=include_top,
204 input_tensor=input_tensor,
def SEResNet(input_shape=None, initial_conv_filters=64, depth=[3, filters=[64, width=1, bottleneck=False, weight_decay=1e-4, include_top=True, weights=None, input_tensor=None, pooling=None, classes=1000)
string se_resnet_saul.WEIGHTS_PATH = "" |
string se_resnet_saul.WEIGHTS_PATH_NO_TOP = "" |