本文整理汇总了Python中keras.layers.ReLU方法的典型用法代码示例。如果您正苦于以下问题:Python layers.ReLU方法的具体用法?Python layers.ReLU怎么用?Python layers.ReLU使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.layers
的用法示例。
在下文中一共展示了layers.ReLU方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emit_Relu6
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def emit_Relu6(self, IR_node, in_scope=False):
try:
# Keras == 2.1.6
from keras.applications.mobilenet import relu6
str_relu6 = 'keras.applications.mobilenet.relu6'
code = "{:<15} = layers.Activation({}, name = '{}')({})".format(
IR_node.variable_name,
str_relu6,
IR_node.name,
self.IR_graph.get_node(IR_node.in_edges[0]).real_variable_name)
return code
except:
# Keras == 2.2.2
from keras.layers import ReLU
code = "{:<15} = layers.ReLU(6, name = '{}')({})".format(
IR_node.variable_name,
IR_node.name,
self.IR_graph.get_node(IR_node.in_edges[0]).real_variable_name)
return code
示例2: shortcut_pool
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def shortcut_pool(inputs, output, filters=256, pool_type='max', shortcut=True):
"""
ResNet(shortcut连接|skip连接|residual连接),
这里是用shortcut连接. 恒等映射, block+f(block)
再加上 downsampling实现
参考: https://github.com/zonetrooper32/VDCNN/blob/keras_version/vdcnn.py
:param inputs: tensor
:param output: tensor
:param filters: int
:param pool_type: str, 'max'、'k-max' or 'conv' or other
:param shortcut: boolean
:return: tensor
"""
if shortcut:
conv_2 = Conv1D(filters=filters, kernel_size=1, strides=2, padding='SAME')(inputs)
conv_2 = BatchNormalization()(conv_2)
output = downsampling(output, pool_type=pool_type)
out = Add()([output, conv_2])
else:
out = ReLU(inputs)
out = downsampling(out, pool_type=pool_type)
if pool_type is not None: # filters翻倍
out = Conv1D(filters=filters*2, kernel_size=1, strides=1, padding='SAME')(out)
out = BatchNormalization()(out)
return out
示例3: initial_oct_conv_bn_relu
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def initial_oct_conv_bn_relu(ip, filters, kernel_size=(3, 3), strides=(1, 1),
alpha=0.5, padding='same', dilation=None, bias=False,
activation=True):
channel_axis = 1 if K.image_data_format() == 'channels_first' else -1
x_high, x_low = initial_octconv(ip, filters, kernel_size, strides, alpha,
padding, dilation, bias)
relu = ReLU()
x_high = BatchNormalization(axis=channel_axis)(x_high)
if activation:
x_high = relu(x_high)
x_low = BatchNormalization(axis=channel_axis)(x_low)
if activation:
x_low = relu(x_low)
return x_high, x_low
示例4: oct_conv_bn_relu
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def oct_conv_bn_relu(ip_high, ip_low, filters, kernel_size=(3, 3), strides=(1, 1),
alpha=0.5, padding='same', dilation=None, bias=False, activation=True):
channel_axis = 1 if K.image_data_format() == 'channels_first' else -1
x_high, x_low = octconv_block(ip_high, ip_low, filters, kernel_size, strides, alpha,
padding, dilation, bias)
relu = ReLU()
x_high = BatchNormalization(axis=channel_axis)(x_high)
if activation:
x_high = relu(x_high)
x_low = BatchNormalization(axis=channel_axis)(x_low)
if activation:
x_low = relu(x_low)
return x_high, x_low
示例5: _bottleneck_original
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def _bottleneck_original(ip, filters, strides=(1, 1), downsample_shortcut=False,
expansion=4):
final_filters = int(filters * expansion)
shortcut = ip
x = _conv_bn_relu(ip, filters, kernel_size=(1, 1))
x = _conv_bn_relu(x, filters, kernel_size=(3, 3), strides=strides)
x = _conv_bn_relu(x, final_filters, kernel_size=(1, 1), activation=False)
if downsample_shortcut:
shortcut = _conv_block(shortcut, final_filters, kernel_size=(1, 1),
strides=strides)
x = add([x, shortcut])
x = ReLU()(x)
return x
示例6: build_generator
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def build_generator():
gen_model = Sequential()
gen_model.add(Dense(input_dim=100, output_dim=2048))
gen_model.add(ReLU())
gen_model.add(Dense(256 * 8 * 8))
gen_model.add(BatchNormalization())
gen_model.add(ReLU())
gen_model.add(Reshape((8, 8, 256), input_shape=(256 * 8 * 8,)))
gen_model.add(UpSampling2D(size=(2, 2)))
gen_model.add(Conv2D(128, (5, 5), padding='same'))
gen_model.add(ReLU())
gen_model.add(UpSampling2D(size=(2, 2)))
gen_model.add(Conv2D(64, (5, 5), padding='same'))
gen_model.add(ReLU())
gen_model.add(UpSampling2D(size=(2, 2)))
gen_model.add(Conv2D(3, (5, 5), padding='same'))
gen_model.add(Activation('tanh'))
return gen_model
示例7: call
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def call(self, x):
return nn.ReLU(max_value=6.0)(x)
示例8: get_activation_layer
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def get_activation_layer(x,
activation,
name="activ"):
"""
Create activation layer from string/function.
Parameters:
----------
x : keras.backend tensor/variable/symbol
Input tensor/variable/symbol.
activation : function or str
Activation function or name of activation function.
name : str, default 'activ'
Block name.
Returns
-------
keras.backend tensor/variable/symbol
Resulted tensor/variable/symbol.
"""
assert (activation is not None)
if isfunction(activation):
x = activation()(x)
elif isinstance(activation, str):
if activation == "relu":
x = nn.Activation("relu", name=name)(x)
elif activation == "relu6":
x = nn.ReLU(max_value=6.0, name=name)(x)
elif activation == "swish":
x = swish(x=x, name=name)
elif activation == "hswish":
x = HSwish(name=name)(x)
else:
raise NotImplementedError()
else:
x = activation(x)
return x
示例9: ResidualBlock
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def ResidualBlock(self, inp, dim_out):
"""Residual Block with instance normalization."""
x = ZeroPadding2D(padding = 1)(inp)
x = Conv2D(filters = dim_out, kernel_size=3, strides=1, padding='valid', use_bias = False)(x)
x = InstanceNormalization(axis = -1)(x)
x = ReLU()(x)
x = ZeroPadding2D(padding = 1)(x)
x = Conv2D(filters = dim_out, kernel_size=3, strides=1, padding='valid', use_bias = False)(x)
x = InstanceNormalization(axis = -1)(x)
return Add()([inp, x])
示例10: __init__
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def __init__(self, model):
super(Keras2Parser, self).__init__()
# load model files into Keras graph
if isinstance(model, _string_types):
try:
# Keras 2.1.6
from keras.applications.mobilenet import relu6
from keras.applications.mobilenet import DepthwiseConv2D
model = _keras.models.load_model(
model,
custom_objects={
'relu6': _keras.applications.mobilenet.relu6,
'DepthwiseConv2D': _keras.applications.mobilenet.DepthwiseConv2D
}
)
except:
# Keras. 2.2.2
import keras.layers as layers
model = _keras.models.load_model(
model,
custom_objects={
'relu6': layers.ReLU(6, name='relu6'),
'DepthwiseConv2D': layers.DepthwiseConv2D
}
)
self.weight_loaded = True
elif isinstance(model, tuple):
model = self._load_model(model[0], model[1])
else:
assert False
# _keras.utils.plot_model(model, "model.png", show_shapes = True)
# Build network graph
self.data_format = _keras.backend.image_data_format()
self.keras_graph = Keras2Graph(model)
self.keras_graph.build()
self.lambda_layer_count = 0
示例11: create_model
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def create_model(self, hyper_parameters):
"""
构建神经网络
:param hyper_parameters:json, hyper parameters of network
:return: tensor, moedl
"""
super().create_model(hyper_parameters)
embedding_output = self.word_embedding.output
embedding_output_spatial = SpatialDropout1D(self.dropout_spatial)(embedding_output)
# 首先是 region embedding 层
conv_1 = Conv1D(self.filters[0][0],
kernel_size=1,
strides=1,
padding='SAME',
kernel_regularizer=l2(self.l2),
bias_regularizer=l2(self.l2),
activation=self.activation_conv,
)(embedding_output_spatial)
block = ReLU()(conv_1)
for filters_block in self.filters:
for j in range(filters_block[1]-1):
# conv + short-cut
block_mid = self.convolutional_block(block, units=filters_block[0])
block = shortcut_conv(block, block_mid, shortcut=True)
# 这里是conv + max-pooling
block_mid = self.convolutional_block(block, units=filters_block[0])
block = shortcut_pool(block, block_mid, filters=filters_block[0], pool_type=self.pool_type, shortcut=True)
block = k_max_pooling(top_k=self.top_k)(block)
block = Flatten()(block)
block = Dropout(self.dropout)(block)
# 全连接层
# block_fully = Dense(2048, activation='tanh')(block)
# output = Dense(2048, activation='tanh')(block_fully)
output = Dense(self.label, activation=self.activate_classify)(block)
self.model = Model(inputs=self.word_embedding.input, outputs=output)
self.model.summary(120)
示例12: convolutional_block
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def convolutional_block(self, inputs, units=256):
"""
Each convolutional block (see Figure 2) is a sequence of two convolutional layers,
each one followed by a temporal BatchNorm (Ioffe and Szegedy, 2015) layer and an ReLU activation.
The kernel size of all the temporal convolutions is 3,
with padding such that the temporal resolution is preserved
(or halved in the case of the convolutional pooling with stride 2, see below).
:param inputs: tensor, input
:param units: int, units
:return: tensor, result of convolutional block
"""
x = Conv1D(units,
kernel_size=3,
padding='SAME',
strides=1,
kernel_regularizer=l2(self.l2),
bias_regularizer=l2(self.l2),
activation=self.activation_conv,
)(inputs)
x = BatchNormalization()(x)
x = ReLU()(x)
x = Conv1D(units,
kernel_size=3,
strides=1,
padding='SAME',
kernel_regularizer=l2(self.l2),
bias_regularizer=l2(self.l2),
activation=self.activation_conv,
)(x)
x = BatchNormalization()(x)
x = ReLU()(x)
return x
示例13: final_oct_conv_bn_relu
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def final_oct_conv_bn_relu(ip_high, ip_low, filters, kernel_size=(3, 3), strides=(1, 1),
padding='same', dilation=None, bias=False, activation=True):
channel_axis = 1 if K.image_data_format() == 'channels_first' else -1
x = final_octconv(ip_high, ip_low, filters, kernel_size, strides,
padding, dilation, bias)
x = BatchNormalization(axis=channel_axis)(x)
if activation:
x = ReLU()(x)
return x
示例14: _conv_bn_relu
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def _conv_bn_relu(ip, filters, kernel_size=(3, 3), strides=(1, 1),
padding='same', bias=False, activation=True):
channel_axis = 1 if K.image_data_format() == 'channels_first' else -1
x = _conv_block(ip, filters, kernel_size, strides, padding, bias)
x = BatchNormalization(axis=channel_axis)(x)
if activation:
x = ReLU()(x)
return x
示例15: _octresnet_bottleneck_block
# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import ReLU [as 别名]
def _octresnet_bottleneck_block(ip, filters, alpha=0.5, strides=(1, 1),
downsample_shortcut=False, first_block=False,
expansion=4):
if first_block:
x_high_res, x_low_res = initial_oct_conv_bn_relu(ip, filters, kernel_size=(1, 1),
alpha=alpha)
x_high, x_low = oct_conv_bn_relu(x_high_res, x_low_res, filters, kernel_size=(3, 3),
strides=strides, alpha=alpha)
else:
x_high_res, x_low_res = ip
x_high, x_low = oct_conv_bn_relu(x_high_res, x_low_res, filters, kernel_size=(1, 1),
alpha=alpha)
x_high, x_low = oct_conv_bn_relu(x_high, x_low, filters, kernel_size=(3, 3),
strides=strides, alpha=alpha)
final_out_filters = int(filters * expansion)
x_high, x_low = oct_conv_bn_relu(x_high, x_low, filters=final_out_filters,
kernel_size=(1, 1), alpha=alpha, activation=False)
if downsample_shortcut:
x_high_res, x_low_res = oct_conv_bn_relu(x_high_res, x_low_res,
final_out_filters, kernel_size=(1, 1),
strides=strides, alpha=alpha,
activation=False)
x_high = add([x_high, x_high_res])
x_low = add([x_low, x_low_res])
x_high = ReLU()(x_high)
x_low = ReLU()(x_low)
return x_high, x_low