本文整理汇总了Python中keras.layers.SeparableConv2D方法的典型用法代码示例。如果您正苦于以下问题:Python layers.SeparableConv2D方法的具体用法?Python layers.SeparableConv2D怎么用?Python layers.SeparableConv2D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.layers
的用法示例。
在下文中一共展示了layers.SeparableConv2D方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: classifier_layers
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def classifier_layers(x, input_shape, trainable=False):
# compile times on theano tend to be very high, so we use smaller ROI pooling regions to workaround
# (hence a smaller stride in the region that follows the ROI pool)
x = TimeDistributed(SeparableConv2D(1536, (3, 3),
padding='same',
use_bias=False),
name='block14_sepconv1')(x)
x = TimeDistributed(BatchNormalization(), name='block14_sepconv1_bn')(x)
x = Activation('relu', name='block14_sepconv1_act')(x)
x = TimeDistributed(SeparableConv2D(2048, (3, 3),
padding='same',
use_bias=False),
name='block14_sepconv2')(x)
x = TimeDistributed(BatchNormalization(), name='block14_sepconv2_bn')(x)
x = Activation('relu', name='block14_sepconv2_act')(x)
TimeDistributed(GlobalAveragePooling2D(), name='avg_pool')(x)
return x
示例2: lin_interpolation_2d
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def lin_interpolation_2d(inp, dim):
num_rows, num_cols, num_filters = K.int_shape(inp)[1:]
conv = SeparableConv2D(num_filters, (num_rows, num_cols), use_bias=False)
x = conv(inp)
w = conv.get_weights()
w[0].fill(0)
w[1].fill(0)
linspace = linspace_2d(num_rows, num_cols, dim=dim)
for i in range(num_filters):
w[0][:,:, i, 0] = linspace[:,:]
w[1][0, 0, i, i] = 1.
conv.set_weights(w)
conv.trainable = False
x = Lambda(lambda x: K.squeeze(x, axis=1))(x)
x = Lambda(lambda x: K.squeeze(x, axis=1))(x)
x = Lambda(lambda x: K.expand_dims(x, axis=-1))(x)
return x
示例3: test_tiny_separable_conv_valid_depth_multiplier
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def test_tiny_separable_conv_valid_depth_multiplier(self):
np.random.seed(1988)
input_dim = 16
input_shape = (input_dim, input_dim, 3)
depth_multiplier = 5
kernel_height = 3
kernel_width = 3
num_kernels = 40
# Define a model
model = Sequential()
model.add(SeparableConv2D(filters=num_kernels, kernel_size=(kernel_height, kernel_width),
padding='valid', strides=(1, 1), depth_multiplier=depth_multiplier,
input_shape=input_shape))
# Set some random weights
model.set_weights([np.random.rand(*w.shape) for w in model.get_weights()])
# Test the keras model
self._test_keras_model(model)
示例4: test_tiny_separable_conv_same_fancy_depth_multiplier
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def test_tiny_separable_conv_same_fancy_depth_multiplier(self):
np.random.seed(1988)
input_dim = 16
input_shape = (input_dim, input_dim, 3)
depth_multiplier = 2
kernel_height = 3
kernel_width = 3
num_kernels = 40
# Define a model
model = Sequential()
model.add(SeparableConv2D(filters=num_kernels, kernel_size=(kernel_height, kernel_width),
padding='same', strides=(2, 2), activation='relu', depth_multiplier=depth_multiplier,
input_shape=input_shape))
# Set some random weights
model.set_weights([np.random.rand(*w.shape) for w in model.get_weights()])
# Test the keras model
self._test_keras_model(model)
示例5: _convBlock
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def _convBlock(self, x, num_filters, activation, kernel_size=(3,3)):
x = SeparableConv2D(num_filters,kernel_size,padding='same')(x)
x = BatchNormalization(axis=-1)(x)
x = Activation(activation)(x)
return x
示例6: _separable_conv_block
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def _separable_conv_block(ip, filters, kernel_size=(3, 3), strides=(1, 1), weight_decay=5e-5, id=None, weights=None):
'''Adds 2 blocks of [relu-separable conv-batchnorm]
# Arguments:
ip: input tensor
filters: number of output filters per layer
kernel_size: kernel size of separable convolutions
strides: strided convolution for downsampling
weight_decay: l2 regularization weight
id: string id
# Returns:
a Keras tensor
'''
channel_dim = 1 if K.image_data_format() == 'channels_first' else -1
with K.name_scope('separable_conv_block_%s' % id):
x = Activation('relu')(ip)
x = SeparableConv2D(filters, kernel_size, strides=strides, name='separable_conv_1_%s' % id,
padding='same', use_bias=False, kernel_initializer='he_normal',
kernel_regularizer=l2(weight_decay),
weights=[weights['d1'], weights['p1']])(x)
x = BatchNormalization(axis=channel_dim, momentum=_BN_DECAY, epsilon=_BN_EPSILON,
name="separable_conv_1_bn_%s" % (id),
weights=weights['bn1'])(x)
x = Activation('relu')(x)
x = SeparableConv2D(filters, kernel_size, name='separable_conv_2_%s' % id,
padding='same', use_bias=False, kernel_initializer='he_normal',
kernel_regularizer=l2(weight_decay),
weights=[weights['d2'], weights['p2']])(x)
x = BatchNormalization(axis=channel_dim, momentum=_BN_DECAY, epsilon=_BN_EPSILON,
name="separable_conv_2_bn_%s" % (id),
weights=weights['bn2'])(x)
return x
示例7: _separable_conv_block
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def _separable_conv_block(ip, filters, kernel_size=(3, 3), strides=(1, 1), weight_decay=5e-5, id=None):
'''Adds 2 blocks of [relu-separable conv-batchnorm]
# Arguments:
ip: input tensor
filters: number of output filters per layer
kernel_size: kernel size of separable convolutions
strides: strided convolution for downsampling
weight_decay: l2 regularization weight
id: string id
# Returns:
a Keras tensor
'''
channel_dim = 1 if K.image_data_format() == 'channels_first' else -1
with K.name_scope('separable_conv_block_%s' % id):
x = Activation('relu')(ip)
x = SeparableConv2D(filters, kernel_size, strides=strides, name='separable_conv_1_%s' % id,
padding='same', use_bias=False, kernel_initializer='he_normal',
kernel_regularizer=l2(weight_decay))(x)
x = BatchNormalization(axis=channel_dim, momentum=_BN_DECAY, epsilon=_BN_EPSILON,
name="separable_conv_1_bn_%s" % (id))(x)
x = Activation('relu')(x)
x = SeparableConv2D(filters, kernel_size, name='separable_conv_2_%s' % id,
padding='same', use_bias=False, kernel_initializer='he_normal',
kernel_regularizer=l2(weight_decay))(x)
x = BatchNormalization(axis=channel_dim, momentum=_BN_DECAY, epsilon=_BN_EPSILON,
name="separable_conv_2_bn_%s" % (id))(x)
return x
示例8: _separable_conv_block
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def _separable_conv_block(ip, filters, kernel_size=(3, 3), strides=(1, 1),
weight_decay=5e-5, id=None):
'''Adds 2 blocks of [relu-separable conv-batchnorm]
# Arguments:
ip: input tensor
filters: number of output filters per layer
kernel_size: kernel size of separable convolutions
strides: strided convolution for downsampling
weight_decay: l2 regularization weight
id: string id
# Returns:
a Keras tensor
'''
channel_dim = 1 if K.image_data_format() == 'channels_first' else -1
with K.name_scope('separable_conv_block_%s' % id):
x = Activation('relu')(ip)
x = SeparableConv2D(filters, kernel_size, strides=strides,
name='separable_conv_1_%s' % id, padding='same',
use_bias=False, kernel_initializer='he_normal',
kernel_regularizer=l2(weight_decay))(x)
x = BatchNormalization(axis=channel_dim, momentum=_BN_DECAY,
epsilon=_BN_EPSILON,
name="separable_conv_1_bn_%s" % id)(x)
x = Activation('relu')(x)
x = SeparableConv2D(filters, kernel_size, name='separable_conv_2_%s' % id,
padding='same', use_bias=False,
kernel_initializer='he_normal',
kernel_regularizer=l2(weight_decay))(x)
x = BatchNormalization(axis=channel_dim, momentum=_BN_DECAY,
epsilon=_BN_EPSILON,
name="separable_conv_2_bn_%s" % id)(x)
return x
示例9: conv_sep
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def conv_sep(self, input_tensor, filters, kernel_size=5, strides=2, **kwargs):
""" Seperable Convolution Layer.
Parameters
----------
input_tensor: tensor
The input tensor to the layer
filters: int
The dimensionality of the output space (i.e. the number of output filters in the
convolution)
kernel_size: int, optional
An integer or tuple/list of 2 integers, specifying the height and width of the 2D
convolution window. Can be a single integer to specify the same value for all spatial
dimensions. Default: 5
strides: tuple or int, optional
An integer or tuple/list of 2 integers, specifying the strides of the convolution along
the height and width. Can be a single integer to specify the same value for all spatial
dimensions. Default: `2`
kwargs: dict
Any additional Keras standard layer keyword arguments
Returns
-------
tensor
The output tensor from the Upscale layer
"""
logger.debug("input_tensor: %s, filters: %s, kernel_size: %s, strides: %s, kwargs: %s)",
input_tensor, filters, kernel_size, strides, kwargs)
name = self._get_name("separableconv2d_{}".format(input_tensor.shape[1]))
kwargs = self._set_default_initializer(kwargs)
var_x = SeparableConv2D(filters,
kernel_size=kernel_size,
strides=strides,
padding="same",
name="{}_seperableconv2d".format(name),
**kwargs)(input_tensor)
var_x = Activation("relu", name="{}_relu".format(name))(var_x)
return var_x
示例10: separable_act_conv_bn
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def separable_act_conv_bn(x, filters, size, strides=(1, 1), padding='same',
name=None):
if name is not None:
conv_name = name + '_conv'
act_name = name + '_act'
else:
conv_name = None
act_name = None
x = Activation('relu', name=act_name)(x)
x = SeparableConv2D(filters, size, strides=strides, padding=padding,
use_bias=False, name=conv_name)(x)
x = BatchNormalization(axis=-1, scale=False, name=name)(x)
return x
示例11: sepconv2d
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def sepconv2d(x, filters, kernel_size, strides=(1, 1), padding='same',
name=None):
"""SeparableConv2D possibly wrapped by a TimeDistributed layer."""
f = SeparableConv2D(filters, kernel_size, strides=strides, padding=padding,
use_bias=False, name=name)
return TimeDistributed(f, name=name)(x) if K.ndim(x) == 5 else f(x)
示例12: lin_interpolation_2d
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def lin_interpolation_2d(x, axis, vmin=0., vmax=1., name=None):
"""Implements a 2D linear interpolation using a depth size separable
convolution (non trainable).
"""
assert K.ndim(x) in [4, 5], \
'Input tensor must have ndim 4 or 5 ({})'.format(K.ndim(x))
if 'global_sam_cnt' not in globals():
global global_sam_cnt
global_sam_cnt = 0
if name is None:
name = 'custom_sam_%d' % global_sam_cnt
global_sam_cnt += 1
if K.ndim(x) == 4:
num_rows, num_cols, num_filters = K.int_shape(x)[1:]
else:
num_rows, num_cols, num_filters = K.int_shape(x)[2:]
f = SeparableConv2D(num_filters, (num_rows, num_cols), use_bias=False,
name=name)
x = TimeDistributed(f, name=name)(x) if K.ndim(x) == 5 else f(x)
w = f.get_weights()
w[0].fill(0)
w[1].fill(0)
linspace = linspace_2d(num_rows, num_cols, dim=axis)
for i in range(num_filters):
w[0][:,:, i, 0] = linspace[:,:]
w[1][0, 0, i, i] = 1.
f.set_weights(w)
f.trainable = False
x = Lambda(lambda x: K.squeeze(x, axis=-2))(x)
x = Lambda(lambda x: K.squeeze(x, axis=-2))(x)
x = Lambda(lambda x: K.expand_dims(x, axis=-1))(x)
return x
示例13: separable_conv_bn_act
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def separable_conv_bn_act(x, filters, size, strides=(1, 1), padding='same',
name=None):
if name is not None:
conv_name = name + '_conv'
bn_name = name + '_bn'
else:
conv_name = None
bn_name = None
x = SeparableConv2D(filters, size, strides=strides, padding=padding,
use_bias=False, name=conv_name)(x)
x = BatchNormalization(axis=-1, scale=False, name=bn_name)(x)
x = Activation('relu', name=name)(x)
return x
示例14: separable_conv_bn
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def separable_conv_bn(x, filters, size, strides=(1, 1), padding='same',
name=None):
if name is not None:
conv_name = name + '_conv'
else:
conv_name = None
x = SeparableConv2D(filters, size, strides=strides, padding=padding,
use_bias=False, name=conv_name)(x)
x = BatchNormalization(axis=-1, scale=False, name=name)(x)
return x
示例15: a3c_sepconv
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import SeparableConv2D [as 别名]
def a3c_sepconv(x, params):
"""
Feed forward model used in a3c paper but with seperable convolutions
:param x: input tensor
:param params: {dict} hyperparams (sub-selection)
:return: output tensor
:raises ValueError: could not find parameter
"""
x = layers.SeparableConv2D(filters=16, kernel_size=8, strides=4, activation='relu')(x)
x = layers.SeparableConv2D(filters=32, kernel_size=4, strides=2, activation='relu')(x)
return x