|
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._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 334 of file se_resnet.py.
334 depth, width, bottleneck, weight_decay, pooling):
335 '''Creates a SE ResNet model with specified parameters 337 initial_conv_filters: number of features for the initial convolution 338 include_top: Flag to include the last dense layer 339 filters: number of filters per block, defined as a list. 340 filters = [64, 128, 256, 512 341 depth: number or layers in the each block, defined as a list. 342 ResNet-50 = [3, 4, 6, 3] 343 ResNet-101 = [3, 6, 23, 3] 344 ResNet-152 = [3, 8, 36, 3] 345 width: width multiplier for network (for Wide ResNet) 346 bottleneck: adds a bottleneck conv to reduce computation 347 weight_decay: weight_decay (l2 norm) 348 pooling: Optional pooling mode for feature extraction 349 when `include_top` is `False`. 350 - `None` means that the output of the model will be 351 the 4D tensor output of the 352 last convolutional layer. 353 - `avg` means that global average pooling 354 will be applied to the output of the 355 last convolutional layer, and thus 356 the output of the model will be a 2D tensor. 357 - `max` means that global max pooling will 359 Returns: a Keras Model 361 channel_axis = 1
if K.image_data_format() ==
'channels_first' else -1
365 x = Conv2D(initial_conv_filters, (7, 7), padding=
'same', use_bias=
False, strides=(2, 2),
366 kernel_initializer=
'he_normal', kernel_regularizer=l2(weight_decay))(img_input)
368 x = MaxPooling2D((3, 3), strides=(2, 2), padding=
'same')(x)
371 for i
in range(N[0]):
378 for k
in range(1, len(N)):
384 for i
in range(N[k] - 1):
390 x = BatchNormalization(axis=channel_axis)(x)
391 x = Activation(
'relu')(x)
394 x = GlobalAveragePooling2D()(x)
395 x = Dense(classes, use_bias=
False, kernel_regularizer=l2(weight_decay),
396 activation=
'sigmoid', name=
'neutrino')(x)
399 x = GlobalAveragePooling2D()(x)
400 elif pooling ==
'max':
401 x = GlobalMaxPooling2D()(x)
404 def _resnet_block(input, filters, k=1, strides=(1, 1))
def _resnet_bottleneck_block(input, filters, k=1, strides=(1, 1))
def se_resnet._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 255 of file se_resnet.py.
256 ''' Adds a pre-activation resnet block without bottleneck layers 260 filters: number of output filters 262 strides: strides of the convolution layer 264 Returns: a keras tensor 267 channel_axis = 1
if K.image_data_format() ==
"channels_first" else -1
269 x = BatchNormalization(axis=channel_axis)(input)
270 x = Activation(
'relu')(x)
272 if strides != (1, 1)
or init._keras_shape[channel_axis] != filters * k:
273 init = Conv2D(filters * k, (1, 1), padding=
'same', kernel_initializer=
'he_normal',
274 use_bias=
False, strides=strides)(x)
276 x = Conv2D(filters * k, (3, 3), padding=
'same', kernel_initializer=
'he_normal',
277 use_bias=
False, strides=strides)(x)
278 x = BatchNormalization(axis=channel_axis)(x)
279 x = Activation(
'relu')(x)
281 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._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 291 of file se_resnet.py.
292 ''' Adds a pre-activation resnet block with bottleneck layers 296 filters: number of output filters 298 strides: strides of the convolution layer 300 Returns: a keras tensor 303 channel_axis = 1
if K.image_data_format() ==
"channels_first" else -1
304 bottleneck_expand = 4
306 x = BatchNormalization(axis=channel_axis)(input)
307 x = Activation(
'relu')(x)
309 if strides != (1, 1)
or init._keras_shape[channel_axis] != bottleneck_expand * filters * k:
310 init = Conv2D(bottleneck_expand * filters * k, (1, 1), padding=
'same', kernel_initializer=
'he_normal',
311 use_bias=
False, strides=strides)(x)
313 x = Conv2D(filters * k, (1, 1), padding=
'same', kernel_initializer=
'he_normal',
315 x = BatchNormalization(axis=channel_axis)(x)
316 x = Activation(
'relu')(x)
318 x = Conv2D(filters * k, (3, 3), padding=
'same', kernel_initializer=
'he_normal',
319 use_bias=
False, strides=strides)(x)
320 x = BatchNormalization(axis=channel_axis)(x)
321 x = Activation(
'relu')(x)
323 x = Conv2D(bottleneck_expand * filters * k, (1, 1), padding=
'same', kernel_initializer=
'he_normal',
Coord add(Coord c1, Coord c2)
def squeeze_excite_block(input, ratio=16)
def _resnet_bottleneck_block(input, filters, k=1, strides=(1, 1))
def se_resnet.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.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:
127 img_input = Input(shape=input_shape)
129 if not K.is_keras_tensor(input_tensor):
130 img_input = Input(tensor=input_tensor, shape=input_shape)
132 img_input = input_tensor
135 filters, depth, width, bottleneck, weight_decay, pooling)
139 if input_tensor
is not None:
140 inputs = get_source_inputs(input_tensor)
144 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.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 221 of file se_resnet.py.
225 bottleneck=bottleneck,
226 weight_decay=weight_decay,
227 include_top=include_top,
229 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.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 242 of file se_resnet.py.
246 bottleneck=bottleneck,
247 weight_decay=weight_decay,
248 include_top=include_top,
250 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.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 159 of file se_resnet.py.
163 bottleneck=bottleneck,
164 weight_decay=weight_decay,
165 include_top=include_top,
167 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.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 180 of file se_resnet.py.
184 bottleneck=bottleneck,
185 weight_decay=weight_decay,
186 include_top=include_top,
188 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.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 201 of file se_resnet.py.
204 bottleneck=bottleneck,
205 weight_decay=weight_decay,
206 include_top=include_top,
208 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.WEIGHTS_PATH = "" |
string se_resnet.WEIGHTS_PATH_NO_TOP = "" |