mscale package

Submodules

mscale.activations module

mscale.activations.s2relu(x)

sin-srelu presented in 2009.14597

x_type_

_description_

_type_

_description_

mscale.activations.srelu(x)

srelu activation function defined in: 1910.11710

x_type_

_description_

_type_

_description_

mscale.activations.srelu2(x)

srelu squared

x_type_

_description_

_type_

_description_

mscale.activations.srelu3(x)

srelu cubed

x_type_

_description_

_type_

_description_

mscale.activations.srelun(x, n)

generalisation of srelu. Raises srelu to the power n.

x_type_

_description_

n_type_

_description_

_type_

_description_

mscale.example module

mscale.example.example_function(x: int)

Returns the input int.

This function just returns the input int.

arg1int

Any integer.

int

The same input

mscale.layers module

class mscale.layers.ScaleLayer(*args, **kwargs)

Bases: keras.engine.base_layer.Layer

A class to represent a neural network layer that does element-wise multiplication of the inputs with a scale tensor of the same dimension.

call(inputs)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state in __init__(), or the build() method that is called automatically before call() executes the first time.

Args:
inputs: Input tensor, or dict/list/tuple of input tensors.

The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

arguments, and inputs cannot be provided via the default value of a keyword argument.

  • NumPy array or Python scalar values in inputs get cast as tensors.

  • Keras mask metadata is only collected from inputs.

  • Layers are built (build(input_shape) method) using shape info from inputs only.

  • input_spec compatibility is only checked against inputs.

  • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

  • The SavedModel input specification is generated using inputs only.

  • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

*args: Additional positional arguments. May contain tensors, although

this is not recommended, for the reasons above.

**kwargs: Additional keyword arguments. May contain tensors, although

this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

whether the call is meant for training or inference.

  • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

mscale.layers.make_scale_tensor(input_shape, scale_dimension: int, scale, dtype=None)

Creates a 1D tensor of ones with shape ‘input_shape’. One of the dimensions of this tensor, given by ‘scale_dimension’, gets set to the value ‘scale’.

input_shape_type_

_description_

scale_dimensionint

_description_

scale_type_

_description_

dtype_type_, optional

_description_, by default None

_type_

_description_

mscale.mscalev5 module

mscale.mscalev5.build_model(input_shape=1, output_shape=1, units=[128], activation='relu', scale_activation='relu', n_blocks=[1], scales=[1], layers_per_block=3, scale_dimension=0, dtype=None, final_dense=False)

implementing something similar multi-scale DNN MscaleDNN version 2 e.g. 2007.11207, 2009.12729

But with one important difference, the scale is only applied to the time dimension which is assumed to be the 0-th dimension, other dimensions are left alone.

input_shapeint, optional

_description_, by default 1

output_shapeint, optional

_description_, by default 1

unitslist, optional

_description_, by default [128]

activationstr, optional

_description_, by default “relu”

scale_activationstr, optional

_description_, by default “relu”

n_blockslist, optional

_description_, by default [1]

scaleslist, optional

_description_, by default [1]

layers_per_blockint, optional

_description_, by default 3

scale_dimensionint, optional

_description_, by default 0

dtype_type_, optional

_description_, by default None

final_densebool, optional

_description_, by default False

_type_

_description_

mscale.mscalev5.build_subnetwork(input_tensor, output_shape, units, output_name, activation='relu', n_blocks=1, layers_per_block=3)

subnetwork with the option of skip-connections

n_blocks >= 1

input_tensor_type_

_description_

output_shape_type_

_description_

units_type_

_description_

output_name_type_

_description_

activationstr, optional

_description_, by default “relu”

n_blocksint, optional

_description_, by default 1

layers_per_blockint, optional

_description_, by default 3

_type_

_description_

Module contents