Python tensorflow.keras.layers.Layer() Examples

The following are 16 code examples of tensorflow.keras.layers.Layer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorflow.keras.layers , or try the search function .
Example #1
Source File: dla.py    From imgclsmob with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: dla.py    From imgclsmob with MIT License 5 votes vote down vote up
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) 
Example #3
Source File: dla.py    From imgclsmob with MIT License 5 votes vote down vote up
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) 
Example #4
Source File: dla.py    From imgclsmob with MIT License 5 votes vote down vote up
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) 
Example #5
Source File: dla.py    From imgclsmob with MIT License 5 votes vote down vote up
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) 
Example #6
Source File: dla.py    From imgclsmob with MIT License 5 votes vote down vote up
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) 
Example #7
Source File: dla.py    From imgclsmob with MIT License 5 votes vote down vote up
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) 
Example #8
Source File: dla.py    From imgclsmob with MIT License 5 votes vote down vote up
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) 
Example #9
Source File: dla.py    From imgclsmob with MIT License 5 votes vote down vote up
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) 
Example #10
Source File: common.py    From imgclsmob with MIT License 5 votes vote down vote up
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 
Example #11
Source File: __init__.py    From platypush with MIT License 5 votes vote down vote up
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) 
Example #12
Source File: keras.py    From pennylane with Apache License 2.0 5 votes vote down vote up
def __str__(self):
        detail = "<Quantum Keras Layer: func={}>"
        return detail.format(self.qnode.func.__name__) 
Example #13
Source File: keras.py    From pennylane with Apache License 2.0 5 votes vote down vote up
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 
Example #14
Source File: common.py    From tf2-mobile-pose-estimation with Apache License 2.0 5 votes vote down vote up
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 
Example #15
Source File: keract.py    From keract with MIT License 5 votes vote down vote up
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() 
Example #16
Source File: custom_activation.py    From Echo with MIT License 5 votes vote down vote up
def build(self, input_shape):
        # Trainable Beta Parameter for the Layer.
        self._beta = self.add_weight(name='beta', 
                                    shape=(1,),
                                    initializer='uniform',
                                    trainable=True)
        super(Swish, self).build(input_shape)