本文整理汇总了Python中tensorflow.keras.layers.Layer方法的典型用法代码示例。如果您正苦于以下问题:Python layers.Layer方法的具体用法?Python layers.Layer怎么用?Python layers.Layer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.keras.layers
的用法示例。
在下文中一共展示了layers.Layer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dla102x2
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def dla102x2(**kwargs):
"""
DLA-X2-102 model from 'Deep Layer Aggregation,' https://arxiv.org/abs/1707.06484.
Parameters:
----------
pretrained : bool, default False
Whether to load the pretrained weights for model.
root : str, default '~/.tensorflow/models'
Location for keeping the model parameters.
"""
class DLABottleneckX64(DLABottleneckX):
def __init__(self, in_channels, out_channels, strides, **kwargs):
super(DLABottleneckX64, self).__init__(in_channels, out_channels, strides, cardinality=64, **kwargs)
return get_dla(levels=[1, 3, 4, 1], channels=[128, 256, 512, 1024], res_body_class=DLABottleneckX64,
residual_root=True, model_name="dla102x2", **kwargs)
示例2: dla34
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def dla34(**kwargs):
"""
DLA-34 model from 'Deep Layer Aggregation,' https://arxiv.org/abs/1707.06484.
Parameters:
----------
pretrained : bool, default False
Whether to load the pretrained weights for model.
root : str, default '~/.tensorflow/models'
Location for keeping the model parameters.
"""
return get_dla(levels=[1, 2, 2, 1], channels=[64, 128, 256, 512], res_body_class=ResBlock, model_name="dla34",
**kwargs)
示例3: dla46c
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def dla46c(**kwargs):
"""
DLA-46-C model from 'Deep Layer Aggregation,' https://arxiv.org/abs/1707.06484.
Parameters:
----------
pretrained : bool, default False
Whether to load the pretrained weights for model.
root : str, default '~/.tensorflow/models'
Location for keeping the model parameters.
"""
return get_dla(levels=[1, 2, 2, 1], channels=[64, 64, 128, 256], res_body_class=DLABottleneck, model_name="dla46c",
**kwargs)
示例4: dla46xc
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def dla46xc(**kwargs):
"""
DLA-X-46-C model from 'Deep Layer Aggregation,' https://arxiv.org/abs/1707.06484.
Parameters:
----------
pretrained : bool, default False
Whether to load the pretrained weights for model.
root : str, default '~/.tensorflow/models'
Location for keeping the model parameters.
"""
return get_dla(levels=[1, 2, 2, 1], channels=[64, 64, 128, 256], res_body_class=DLABottleneckX,
model_name="dla46xc", **kwargs)
示例5: dla60
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def dla60(**kwargs):
"""
DLA-60 model from 'Deep Layer Aggregation,' https://arxiv.org/abs/1707.06484.
Parameters:
----------
pretrained : bool, default False
Whether to load the pretrained weights for model.
root : str, default '~/.tensorflow/models'
Location for keeping the model parameters.
"""
return get_dla(levels=[1, 2, 3, 1], channels=[128, 256, 512, 1024], res_body_class=DLABottleneck,
model_name="dla60", **kwargs)
示例6: dla60x
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def dla60x(**kwargs):
"""
DLA-X-60 model from 'Deep Layer Aggregation,' https://arxiv.org/abs/1707.06484.
Parameters:
----------
pretrained : bool, default False
Whether to load the pretrained weights for model.
root : str, default '~/.tensorflow/models'
Location for keeping the model parameters.
"""
return get_dla(levels=[1, 2, 3, 1], channels=[128, 256, 512, 1024], res_body_class=DLABottleneckX,
model_name="dla60x", **kwargs)
示例7: dla102
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def dla102(**kwargs):
"""
DLA-102 model from 'Deep Layer Aggregation,' https://arxiv.org/abs/1707.06484.
Parameters:
----------
pretrained : bool, default False
Whether to load the pretrained weights for model.
root : str, default '~/.tensorflow/models'
Location for keeping the model parameters.
"""
return get_dla(levels=[1, 3, 4, 1], channels=[128, 256, 512, 1024], res_body_class=DLABottleneck,
residual_root=True, model_name="dla102", **kwargs)
示例8: dla102x
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def dla102x(**kwargs):
"""
DLA-X-102 model from 'Deep Layer Aggregation,' https://arxiv.org/abs/1707.06484.
Parameters:
----------
pretrained : bool, default False
Whether to load the pretrained weights for model.
root : str, default '~/.tensorflow/models'
Location for keeping the model parameters.
"""
return get_dla(levels=[1, 3, 4, 1], channels=[128, 256, 512, 1024], res_body_class=DLABottleneckX,
residual_root=True, model_name="dla102x", **kwargs)
示例9: dla169
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def dla169(**kwargs):
"""
DLA-169 model from 'Deep Layer Aggregation,' https://arxiv.org/abs/1707.06484.
Parameters:
----------
pretrained : bool, default False
Whether to load the pretrained weights for model.
root : str, default '~/.tensorflow/models'
Location for keeping the model parameters.
"""
return get_dla(levels=[2, 3, 5, 1], channels=[128, 256, 512, 1024], res_body_class=DLABottleneck,
residual_root=True, model_name="dla169", **kwargs)
示例10: get_activation_layer
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def get_activation_layer(activation,
**kwargs):
"""
Create activation layer from string/function.
Parameters:
----------
activation : function, or str, or nn.Layer
Activation function or name of activation function.
Returns
-------
nn.Layer
Activation layer.
"""
assert (activation is not None)
if isfunction(activation):
return activation()
elif isinstance(activation, str):
if activation == "relu":
return nn.ReLU(**kwargs)
elif activation == "relu6":
return ReLU6(**kwargs)
elif activation == "prelu2":
return PReLU2(**kwargs)
elif activation == "swish":
return Swish(**kwargs)
elif activation == "hswish":
return HSwish(**kwargs)
elif activation == "sigmoid":
return tf.nn.sigmoid
elif activation == "hsigmoid":
return HSigmoid(**kwargs)
else:
raise NotImplementedError()
else:
assert (isinstance(activation, nn.Layer))
return activation
示例11: _layer_from_dict
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def _layer_from_dict(layer_type: str, *args, **kwargs) -> Layer:
from tensorflow.keras import layers
cls = getattr(layers, layer_type)
assert issubclass(cls, Layer)
return cls(*args, **kwargs)
示例12: __str__
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def __str__(self):
detail = "<Quantum Keras Layer: func={}>"
return detail.format(self.qnode.func.__name__)
示例13: input_arg
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def input_arg(self):
"""Name of the argument to be used as the input to the Keras
`Layer <https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer>`__. Set to
``"inputs"``."""
return self._input_arg
示例14: get_activation_layer
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def get_activation_layer(activation):
"""
Create activation layer from string/function.
Parameters:
----------
activation : function, or str, or nn.Layer
Activation function or name of activation function.
Returns
-------
nn.Layer
Activation layer.
"""
assert (activation is not None)
if isfunction(activation):
return activation()
elif isinstance(activation, str):
if activation == "relu":
return nn.ReLU()
elif activation == "relu6":
return ReLU6()
elif activation == "swish":
return Swish()
elif activation == "hswish":
return HSwish()
elif activation == "sigmoid":
return tf.nn.sigmoid
elif activation == "hsigmoid":
return HSigmoid()
else:
raise NotImplementedError()
else:
assert (isinstance(activation, nn.Layer))
return activation
示例15: _get_nodes
# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Layer [as 别名]
def _get_nodes(module, output_format, nested=False, layer_names=[]):
is_model_or_layer = isinstance(module, Model) or isinstance(module, Layer)
has_layers = hasattr(module, '_layers') and bool(module._layers)
assert is_model_or_layer, 'Not a model or layer!'
module_name = n_(module.output, output_format_=output_format, nested=nested)
if has_layers:
node_dict = OrderedDict()
# print('Layers:', module._layers)
for m in module._layers:
key = n_(m.output, output_format_=output_format, nested=nested)
if nested:
nodes = _get_nodes(m, output_format,
nested=nested,
layer_names=layer_names)
else:
if bool(layer_names) and key in layer_names:
nodes = OrderedDict([(key, m.output)])
elif not bool(layer_names):
nodes = OrderedDict([(key, m.output)])
else:
nodes = OrderedDict()
node_dict.update(nodes)
return node_dict
elif bool(layer_names) and module_name in layer_names:
print("1", module_name, module)
return OrderedDict({module_name: module.output})
elif not bool(layer_names):
print("2", module_name, module)
return OrderedDict({module_name: module.output})
else:
print("3", module_name, module)
return OrderedDict()