本文整理汇总了Python中tensorflow.keras.layers.SeparableConv2D方法的典型用法代码示例。如果您正苦于以下问题:Python layers.SeparableConv2D方法的具体用法?Python layers.SeparableConv2D怎么用?Python layers.SeparableConv2D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.keras.layers
的用法示例。
在下文中一共展示了layers.SeparableConv2D方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SeparableConvBlock
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import SeparableConv2D [as 别名]
def SeparableConvBlock(num_channels, kernel_size, strides, name, freeze_bn=False):
f1 = layers.SeparableConv2D(num_channels, kernel_size=kernel_size, strides=strides, padding='same',
use_bias=True, name=f'{name}/conv')
f2 = layers.BatchNormalization(momentum=MOMENTUM, epsilon=EPSILON, name=f'{name}/bn')
# f2 = BatchNormalization(freeze=freeze_bn, name=f'{name}/bn')
return reduce(lambda f, g: lambda *args, **kwargs: g(f(*args, **kwargs)), (f1, f2))
示例2: __init__
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import SeparableConv2D [as 别名]
def __init__(self, width, depth, num_anchors=9, separable_conv=True, freeze_bn=False, detect_quadrangle=False, **kwargs):
super(BoxNet, self).__init__(**kwargs)
self.width = width
self.depth = depth
self.num_anchors = num_anchors
self.separable_conv = separable_conv
self.detect_quadrangle = detect_quadrangle
num_values = 9 if detect_quadrangle else 4
options = {
'kernel_size': 3,
'strides': 1,
'padding': 'same',
'bias_initializer': 'zeros',
}
if separable_conv:
kernel_initializer = {
'depthwise_initializer': initializers.VarianceScaling(),
'pointwise_initializer': initializers.VarianceScaling(),
}
options.update(kernel_initializer)
self.convs = [layers.SeparableConv2D(filters=width, name=f'{self.name}/box-{i}', **options) for i in
range(depth)]
self.head = layers.SeparableConv2D(filters=num_anchors * num_values,
name=f'{self.name}/box-predict', **options)
else:
kernel_initializer = {
'kernel_initializer': initializers.RandomNormal(mean=0.0, stddev=0.01, seed=None)
}
options.update(kernel_initializer)
self.convs = [layers.Conv2D(filters=width, name=f'{self.name}/box-{i}', **options) for i in range(depth)]
self.head = layers.Conv2D(filters=num_anchors * num_values, name=f'{self.name}/box-predict', **options)
self.bns = [
[layers.BatchNormalization(momentum=MOMENTUM, epsilon=EPSILON, name=f'{self.name}/box-{i}-bn-{j}') for j in
range(3, 8)]
for i in range(depth)]
# self.bns = [[BatchNormalization(freeze=freeze_bn, name=f'{self.name}/box-{i}-bn-{j}') for j in range(3, 8)]
# for i in range(depth)]
self.relu = layers.Lambda(lambda x: tf.nn.swish(x))
self.reshape = layers.Reshape((-1, num_values))
self.level = 0
示例3: sep_conv
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import SeparableConv2D [as 别名]
def sep_conv(x, num_filters, kernel_size=(3, 3), activation='relu'):
if activation == 'selu':
x = layers.SeparableConv2D(num_filters, kernel_size,
activation='selu',
padding='same',
kernel_initializer='lecun_normal')(x)
elif activation == 'relu':
x = layers.SeparableConv2D(num_filters, kernel_size,
padding='same',
use_bias=False)(x)
x = layers.BatchNormalization()(x)
x = layers.Activation('relu')(x)
else:
ValueError('Unknown activation function: %s' % (activation,))
return x
示例4: separableConv
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import SeparableConv2D [as 别名]
def separableConv(filters, kernel_size, strides=1, dilation_rate=1, use_bias=True):
return layers.SeparableConv2D(filters, kernel_size, strides=strides, padding='same', use_bias=use_bias,
depthwise_regularizer=regularizers.l2(l=0.0003),
pointwise_regularizer=regularizers.l2(l=0.0003), dilation_rate=dilation_rate)