RAMjET

ramjet.models.components.residual_light_curve_network_block

Code for a residual light curve network block.

Module Contents

Classes

ResidualLightCurveNetworkBlock This is the class from which all layers inherit.
BottleNeckResidualLightCurveNetworkBlock This is the class from which all layers inherit.
BottleNeckResidualLightCurveNetworkBlockMainPathRepeat This is the class from which all layers inherit.
BottleNeckResidualLightCurveNetworkBlockMainPathRepeatMainPathDropout This is the class from which all layers inherit.
BottleNeckResidualLightCurveNetworkBlockEveryWeightBatchNorm This is the class from which all layers inherit.
BottleNeckResidualLightCurveNetworkBlockEveryWeightBatchNormBnAfterActivations This is the class from which all layers inherit.
class ResidualLightCurveNetworkBlock(output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Bases: tensorflow.keras.layers.Layer

This is the class from which all layers inherit.

A layer is a callable object that takes as input one or more tensors and that outputs one or more tensors. It involves computation, defined in the call() method, and a state (weight variables), defined either in the constructor __init__() or in the build() method.

Users will just instantiate a layer and then treat it as a callable.

Parameters:
  • trainable – Boolean, whether the layer’s variables should be trainable.
  • name – String name of the layer.
  • dtype – The dtype of the layer’s computations and weights. Can also be a tf.keras.mixed_precision.Policy, which allows the computation and weight dtype to differ. Default of None means to use tf.keras.mixed_precision.global_policy(), which is a float32 policy unless set to different value.
  • dynamic – Set this to True if your layer should only be run eagerly, and should not be used to generate a static computation graph. This would be the case for a Tree-RNN or a recursive network, for example, or generally for any layer that manipulates tensors using Python control flow. If False, we assume that the layer can safely be used to generate a static computation graph.
name

The name of the layer (string).

dtype

The dtype of the layer’s weights.

variable_dtype

Alias of dtype.

compute_dtype

The dtype of the layer’s computations. Layers automatically cast inputs to this dtype which causes the computations and output to also be in this dtype. When mixed precision is used with a tf.keras.mixed_precision.Policy, this will be different than variable_dtype.

dtype_policy

The layer’s dtype policy. See the tf.keras.mixed_precision.Policy documentation for details.

trainable_weights

List of variables to be included in backprop.

non_trainable_weights

List of variables that should not be included in backprop.

weights

The concatenation of the lists trainable_weights and non_trainable_weights (in this order).

trainable

Whether the layer should be trained (boolean), i.e. whether its potentially-trainable weights should be returned as part of layer.trainable_weights.

input_spec

Optional (list of) InputSpec object(s) specifying the constraints on inputs that can be accepted by the layer.

We recommend that descendants of Layer implement the following methods:

  • __init__(): Defines custom layer attributes, and creates layer state variables that do not depend on input shapes, using add_weight().

  • build(self, input_shape): This method can be used to create weights that depend on the shape(s) of the input(s), using add_weight(). __call__() will automatically build the layer (if it has not been built yet) by calling build().

  • call(self, inputs, *args, **kwargs): Called in __call__ after making sure build() has been called. call() performs the logic of applying the layer to the input tensors (which should be passed in as argument). Two reserved keyword arguments you can optionally use in call() are:

    A typical signature for this method is call(self, inputs), and user could optionally add training and mask if the layer need them. *args and **kwargs is only useful for future extension when more input parameters are planned to be added.

  • get_config(self): Returns a dictionary containing the configuration used to initialize this layer. If the keys differ from the arguments in __init__, then override from_config(self) as well. This method is used when saving the layer or a model that contains this layer.

Examples:

Here’s a basic example: a layer with two variables, w and b, that returns y = w . x + b. It shows how to implement build() and call(). Variables set as attributes of a layer are tracked as weights of the layers (in layer.weights).

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape): # Create the state of the layer (weights)

w_init = tf.random_normal_initializer() self.w = tf.Variable(

initial_value=w_init(shape=(input_shape[-1], self.units),
dtype=’float32’),

trainable=True)

b_init = tf.zeros_initializer() self.b = tf.Variable(

initial_value=b_init(shape=(self.units,), dtype=’float32’), trainable=True)
def call(self, inputs): # Defines the computation from inputs to outputs
return tf.matmul(inputs, self.w) + self.b

# Instantiates the layer. linear_layer = SimpleDense(4)

# This will also call build(input_shape) and create the weights. y = linear_layer(tf.ones((2, 2))) assert len(linear_layer.weights) == 2

# These weights are trainable, so they’re listed in trainable_weights: assert len(linear_layer.trainable_weights) == 2 ```

Note that the method add_weight() offers a shortcut to create weights:

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape):
self.w = self.add_weight(shape=(input_shape[-1], self.units),
initializer=’random_normal’, trainable=True)
self.b = self.add_weight(shape=(self.units,),
initializer=’random_normal’, trainable=True)
def call(self, inputs):
return tf.matmul(inputs, self.w) + self.b

```

Besides trainable weights, updated via backpropagation during training, layers can also have non-trainable weights. These weights are meant to be updated manually during call(). Here’s a example layer that computes the running sum of its inputs:

```python class ComputeSum(Layer):

def __init__(self, input_dim):

super(ComputeSum, self).__init__() # Create a non-trainable weight. self.total = tf.Variable(initial_value=tf.zeros((input_dim,)),

trainable=False)
def call(self, inputs):
self.total.assign_add(tf.reduce_sum(inputs, axis=0)) return self.total

my_sum = ComputeSum(2) x = tf.ones((2, 2))

y = my_sum(x) print(y.numpy()) # [2. 2.]

y = my_sum(x) print(y.numpy()) # [4. 4.]

assert my_sum.weights == [my_sum.total] assert my_sum.non_trainable_weights == [my_sum.total] assert my_sum.trainable_weights == [] ```

For more information about creating layers, see the guide [Making new Layers and Models via subclassing](

__init__(self, output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Initialize self. See help(type(self)) for accurate signature.

call(self, inputs, training=False, mask=None)[source]

The forward pass of the block.

Parameters:
  • inputs – The input tensor.
  • training – A boolean specifying if the layer should be in training mode.
  • mask – A mask for the input tensor.
Returns:

The output tensor of the layer.

class BottleNeckResidualLightCurveNetworkBlock(output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Bases: tensorflow.keras.layers.Layer

This is the class from which all layers inherit.

A layer is a callable object that takes as input one or more tensors and that outputs one or more tensors. It involves computation, defined in the call() method, and a state (weight variables), defined either in the constructor __init__() or in the build() method.

Users will just instantiate a layer and then treat it as a callable.

Parameters:
  • trainable – Boolean, whether the layer’s variables should be trainable.
  • name – String name of the layer.
  • dtype – The dtype of the layer’s computations and weights. Can also be a tf.keras.mixed_precision.Policy, which allows the computation and weight dtype to differ. Default of None means to use tf.keras.mixed_precision.global_policy(), which is a float32 policy unless set to different value.
  • dynamic – Set this to True if your layer should only be run eagerly, and should not be used to generate a static computation graph. This would be the case for a Tree-RNN or a recursive network, for example, or generally for any layer that manipulates tensors using Python control flow. If False, we assume that the layer can safely be used to generate a static computation graph.
name

The name of the layer (string).

dtype

The dtype of the layer’s weights.

variable_dtype

Alias of dtype.

compute_dtype

The dtype of the layer’s computations. Layers automatically cast inputs to this dtype which causes the computations and output to also be in this dtype. When mixed precision is used with a tf.keras.mixed_precision.Policy, this will be different than variable_dtype.

dtype_policy

The layer’s dtype policy. See the tf.keras.mixed_precision.Policy documentation for details.

trainable_weights

List of variables to be included in backprop.

non_trainable_weights

List of variables that should not be included in backprop.

weights

The concatenation of the lists trainable_weights and non_trainable_weights (in this order).

trainable

Whether the layer should be trained (boolean), i.e. whether its potentially-trainable weights should be returned as part of layer.trainable_weights.

input_spec

Optional (list of) InputSpec object(s) specifying the constraints on inputs that can be accepted by the layer.

We recommend that descendants of Layer implement the following methods:

  • __init__(): Defines custom layer attributes, and creates layer state variables that do not depend on input shapes, using add_weight().

  • build(self, input_shape): This method can be used to create weights that depend on the shape(s) of the input(s), using add_weight(). __call__() will automatically build the layer (if it has not been built yet) by calling build().

  • call(self, inputs, *args, **kwargs): Called in __call__ after making sure build() has been called. call() performs the logic of applying the layer to the input tensors (which should be passed in as argument). Two reserved keyword arguments you can optionally use in call() are:

    A typical signature for this method is call(self, inputs), and user could optionally add training and mask if the layer need them. *args and **kwargs is only useful for future extension when more input parameters are planned to be added.

  • get_config(self): Returns a dictionary containing the configuration used to initialize this layer. If the keys differ from the arguments in __init__, then override from_config(self) as well. This method is used when saving the layer or a model that contains this layer.

Examples:

Here’s a basic example: a layer with two variables, w and b, that returns y = w . x + b. It shows how to implement build() and call(). Variables set as attributes of a layer are tracked as weights of the layers (in layer.weights).

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape): # Create the state of the layer (weights)

w_init = tf.random_normal_initializer() self.w = tf.Variable(

initial_value=w_init(shape=(input_shape[-1], self.units),
dtype=’float32’),

trainable=True)

b_init = tf.zeros_initializer() self.b = tf.Variable(

initial_value=b_init(shape=(self.units,), dtype=’float32’), trainable=True)
def call(self, inputs): # Defines the computation from inputs to outputs
return tf.matmul(inputs, self.w) + self.b

# Instantiates the layer. linear_layer = SimpleDense(4)

# This will also call build(input_shape) and create the weights. y = linear_layer(tf.ones((2, 2))) assert len(linear_layer.weights) == 2

# These weights are trainable, so they’re listed in trainable_weights: assert len(linear_layer.trainable_weights) == 2 ```

Note that the method add_weight() offers a shortcut to create weights:

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape):
self.w = self.add_weight(shape=(input_shape[-1], self.units),
initializer=’random_normal’, trainable=True)
self.b = self.add_weight(shape=(self.units,),
initializer=’random_normal’, trainable=True)
def call(self, inputs):
return tf.matmul(inputs, self.w) + self.b

```

Besides trainable weights, updated via backpropagation during training, layers can also have non-trainable weights. These weights are meant to be updated manually during call(). Here’s a example layer that computes the running sum of its inputs:

```python class ComputeSum(Layer):

def __init__(self, input_dim):

super(ComputeSum, self).__init__() # Create a non-trainable weight. self.total = tf.Variable(initial_value=tf.zeros((input_dim,)),

trainable=False)
def call(self, inputs):
self.total.assign_add(tf.reduce_sum(inputs, axis=0)) return self.total

my_sum = ComputeSum(2) x = tf.ones((2, 2))

y = my_sum(x) print(y.numpy()) # [2. 2.]

y = my_sum(x) print(y.numpy()) # [4. 4.]

assert my_sum.weights == [my_sum.total] assert my_sum.non_trainable_weights == [my_sum.total] assert my_sum.trainable_weights == [] ```

For more information about creating layers, see the guide [Making new Layers and Models via subclassing](

__init__(self, output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Initialize self. See help(type(self)) for accurate signature.

call(self, inputs, training=False, mask=None)[source]

The forward pass of the block.

Parameters:
  • inputs – The input tensor.
  • training – A boolean specifying if the layer should be in training mode.
  • mask – A mask for the input tensor.
Returns:

The output tensor of the layer.

class BottleNeckResidualLightCurveNetworkBlockMainPathRepeat(output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Bases: tensorflow.keras.layers.Layer

This is the class from which all layers inherit.

A layer is a callable object that takes as input one or more tensors and that outputs one or more tensors. It involves computation, defined in the call() method, and a state (weight variables), defined either in the constructor __init__() or in the build() method.

Users will just instantiate a layer and then treat it as a callable.

Parameters:
  • trainable – Boolean, whether the layer’s variables should be trainable.
  • name – String name of the layer.
  • dtype – The dtype of the layer’s computations and weights. Can also be a tf.keras.mixed_precision.Policy, which allows the computation and weight dtype to differ. Default of None means to use tf.keras.mixed_precision.global_policy(), which is a float32 policy unless set to different value.
  • dynamic – Set this to True if your layer should only be run eagerly, and should not be used to generate a static computation graph. This would be the case for a Tree-RNN or a recursive network, for example, or generally for any layer that manipulates tensors using Python control flow. If False, we assume that the layer can safely be used to generate a static computation graph.
name

The name of the layer (string).

dtype

The dtype of the layer’s weights.

variable_dtype

Alias of dtype.

compute_dtype

The dtype of the layer’s computations. Layers automatically cast inputs to this dtype which causes the computations and output to also be in this dtype. When mixed precision is used with a tf.keras.mixed_precision.Policy, this will be different than variable_dtype.

dtype_policy

The layer’s dtype policy. See the tf.keras.mixed_precision.Policy documentation for details.

trainable_weights

List of variables to be included in backprop.

non_trainable_weights

List of variables that should not be included in backprop.

weights

The concatenation of the lists trainable_weights and non_trainable_weights (in this order).

trainable

Whether the layer should be trained (boolean), i.e. whether its potentially-trainable weights should be returned as part of layer.trainable_weights.

input_spec

Optional (list of) InputSpec object(s) specifying the constraints on inputs that can be accepted by the layer.

We recommend that descendants of Layer implement the following methods:

  • __init__(): Defines custom layer attributes, and creates layer state variables that do not depend on input shapes, using add_weight().

  • build(self, input_shape): This method can be used to create weights that depend on the shape(s) of the input(s), using add_weight(). __call__() will automatically build the layer (if it has not been built yet) by calling build().

  • call(self, inputs, *args, **kwargs): Called in __call__ after making sure build() has been called. call() performs the logic of applying the layer to the input tensors (which should be passed in as argument). Two reserved keyword arguments you can optionally use in call() are:

    A typical signature for this method is call(self, inputs), and user could optionally add training and mask if the layer need them. *args and **kwargs is only useful for future extension when more input parameters are planned to be added.

  • get_config(self): Returns a dictionary containing the configuration used to initialize this layer. If the keys differ from the arguments in __init__, then override from_config(self) as well. This method is used when saving the layer or a model that contains this layer.

Examples:

Here’s a basic example: a layer with two variables, w and b, that returns y = w . x + b. It shows how to implement build() and call(). Variables set as attributes of a layer are tracked as weights of the layers (in layer.weights).

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape): # Create the state of the layer (weights)

w_init = tf.random_normal_initializer() self.w = tf.Variable(

initial_value=w_init(shape=(input_shape[-1], self.units),
dtype=’float32’),

trainable=True)

b_init = tf.zeros_initializer() self.b = tf.Variable(

initial_value=b_init(shape=(self.units,), dtype=’float32’), trainable=True)
def call(self, inputs): # Defines the computation from inputs to outputs
return tf.matmul(inputs, self.w) + self.b

# Instantiates the layer. linear_layer = SimpleDense(4)

# This will also call build(input_shape) and create the weights. y = linear_layer(tf.ones((2, 2))) assert len(linear_layer.weights) == 2

# These weights are trainable, so they’re listed in trainable_weights: assert len(linear_layer.trainable_weights) == 2 ```

Note that the method add_weight() offers a shortcut to create weights:

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape):
self.w = self.add_weight(shape=(input_shape[-1], self.units),
initializer=’random_normal’, trainable=True)
self.b = self.add_weight(shape=(self.units,),
initializer=’random_normal’, trainable=True)
def call(self, inputs):
return tf.matmul(inputs, self.w) + self.b

```

Besides trainable weights, updated via backpropagation during training, layers can also have non-trainable weights. These weights are meant to be updated manually during call(). Here’s a example layer that computes the running sum of its inputs:

```python class ComputeSum(Layer):

def __init__(self, input_dim):

super(ComputeSum, self).__init__() # Create a non-trainable weight. self.total = tf.Variable(initial_value=tf.zeros((input_dim,)),

trainable=False)
def call(self, inputs):
self.total.assign_add(tf.reduce_sum(inputs, axis=0)) return self.total

my_sum = ComputeSum(2) x = tf.ones((2, 2))

y = my_sum(x) print(y.numpy()) # [2. 2.]

y = my_sum(x) print(y.numpy()) # [4. 4.]

assert my_sum.weights == [my_sum.total] assert my_sum.non_trainable_weights == [my_sum.total] assert my_sum.trainable_weights == [] ```

For more information about creating layers, see the guide [Making new Layers and Models via subclassing](

__init__(self, output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Initialize self. See help(type(self)) for accurate signature.

call(self, inputs, training=False, mask=None)[source]

The forward pass of the block.

Parameters:
  • inputs – The input tensor.
  • training – A boolean specifying if the layer should be in training mode.
  • mask – A mask for the input tensor.
Returns:

The output tensor of the layer.

class BottleNeckResidualLightCurveNetworkBlockMainPathRepeatMainPathDropout(output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Bases: tensorflow.keras.layers.Layer

This is the class from which all layers inherit.

A layer is a callable object that takes as input one or more tensors and that outputs one or more tensors. It involves computation, defined in the call() method, and a state (weight variables), defined either in the constructor __init__() or in the build() method.

Users will just instantiate a layer and then treat it as a callable.

Parameters:
  • trainable – Boolean, whether the layer’s variables should be trainable.
  • name – String name of the layer.
  • dtype – The dtype of the layer’s computations and weights. Can also be a tf.keras.mixed_precision.Policy, which allows the computation and weight dtype to differ. Default of None means to use tf.keras.mixed_precision.global_policy(), which is a float32 policy unless set to different value.
  • dynamic – Set this to True if your layer should only be run eagerly, and should not be used to generate a static computation graph. This would be the case for a Tree-RNN or a recursive network, for example, or generally for any layer that manipulates tensors using Python control flow. If False, we assume that the layer can safely be used to generate a static computation graph.
name

The name of the layer (string).

dtype

The dtype of the layer’s weights.

variable_dtype

Alias of dtype.

compute_dtype

The dtype of the layer’s computations. Layers automatically cast inputs to this dtype which causes the computations and output to also be in this dtype. When mixed precision is used with a tf.keras.mixed_precision.Policy, this will be different than variable_dtype.

dtype_policy

The layer’s dtype policy. See the tf.keras.mixed_precision.Policy documentation for details.

trainable_weights

List of variables to be included in backprop.

non_trainable_weights

List of variables that should not be included in backprop.

weights

The concatenation of the lists trainable_weights and non_trainable_weights (in this order).

trainable

Whether the layer should be trained (boolean), i.e. whether its potentially-trainable weights should be returned as part of layer.trainable_weights.

input_spec

Optional (list of) InputSpec object(s) specifying the constraints on inputs that can be accepted by the layer.

We recommend that descendants of Layer implement the following methods:

  • __init__(): Defines custom layer attributes, and creates layer state variables that do not depend on input shapes, using add_weight().

  • build(self, input_shape): This method can be used to create weights that depend on the shape(s) of the input(s), using add_weight(). __call__() will automatically build the layer (if it has not been built yet) by calling build().

  • call(self, inputs, *args, **kwargs): Called in __call__ after making sure build() has been called. call() performs the logic of applying the layer to the input tensors (which should be passed in as argument). Two reserved keyword arguments you can optionally use in call() are:

    A typical signature for this method is call(self, inputs), and user could optionally add training and mask if the layer need them. *args and **kwargs is only useful for future extension when more input parameters are planned to be added.

  • get_config(self): Returns a dictionary containing the configuration used to initialize this layer. If the keys differ from the arguments in __init__, then override from_config(self) as well. This method is used when saving the layer or a model that contains this layer.

Examples:

Here’s a basic example: a layer with two variables, w and b, that returns y = w . x + b. It shows how to implement build() and call(). Variables set as attributes of a layer are tracked as weights of the layers (in layer.weights).

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape): # Create the state of the layer (weights)

w_init = tf.random_normal_initializer() self.w = tf.Variable(

initial_value=w_init(shape=(input_shape[-1], self.units),
dtype=’float32’),

trainable=True)

b_init = tf.zeros_initializer() self.b = tf.Variable(

initial_value=b_init(shape=(self.units,), dtype=’float32’), trainable=True)
def call(self, inputs): # Defines the computation from inputs to outputs
return tf.matmul(inputs, self.w) + self.b

# Instantiates the layer. linear_layer = SimpleDense(4)

# This will also call build(input_shape) and create the weights. y = linear_layer(tf.ones((2, 2))) assert len(linear_layer.weights) == 2

# These weights are trainable, so they’re listed in trainable_weights: assert len(linear_layer.trainable_weights) == 2 ```

Note that the method add_weight() offers a shortcut to create weights:

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape):
self.w = self.add_weight(shape=(input_shape[-1], self.units),
initializer=’random_normal’, trainable=True)
self.b = self.add_weight(shape=(self.units,),
initializer=’random_normal’, trainable=True)
def call(self, inputs):
return tf.matmul(inputs, self.w) + self.b

```

Besides trainable weights, updated via backpropagation during training, layers can also have non-trainable weights. These weights are meant to be updated manually during call(). Here’s a example layer that computes the running sum of its inputs:

```python class ComputeSum(Layer):

def __init__(self, input_dim):

super(ComputeSum, self).__init__() # Create a non-trainable weight. self.total = tf.Variable(initial_value=tf.zeros((input_dim,)),

trainable=False)
def call(self, inputs):
self.total.assign_add(tf.reduce_sum(inputs, axis=0)) return self.total

my_sum = ComputeSum(2) x = tf.ones((2, 2))

y = my_sum(x) print(y.numpy()) # [2. 2.]

y = my_sum(x) print(y.numpy()) # [4. 4.]

assert my_sum.weights == [my_sum.total] assert my_sum.non_trainable_weights == [my_sum.total] assert my_sum.trainable_weights == [] ```

For more information about creating layers, see the guide [Making new Layers and Models via subclassing](

__init__(self, output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Initialize self. See help(type(self)) for accurate signature.

call(self, inputs, training=False, mask=None)[source]

The forward pass of the block.

Parameters:
  • inputs – The input tensor.
  • training – A boolean specifying if the layer should be in training mode.
  • mask – A mask for the input tensor.
Returns:

The output tensor of the layer.

class BottleNeckResidualLightCurveNetworkBlockEveryWeightBatchNorm(output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Bases: tensorflow.keras.layers.Layer

This is the class from which all layers inherit.

A layer is a callable object that takes as input one or more tensors and that outputs one or more tensors. It involves computation, defined in the call() method, and a state (weight variables), defined either in the constructor __init__() or in the build() method.

Users will just instantiate a layer and then treat it as a callable.

Parameters:
  • trainable – Boolean, whether the layer’s variables should be trainable.
  • name – String name of the layer.
  • dtype – The dtype of the layer’s computations and weights. Can also be a tf.keras.mixed_precision.Policy, which allows the computation and weight dtype to differ. Default of None means to use tf.keras.mixed_precision.global_policy(), which is a float32 policy unless set to different value.
  • dynamic – Set this to True if your layer should only be run eagerly, and should not be used to generate a static computation graph. This would be the case for a Tree-RNN or a recursive network, for example, or generally for any layer that manipulates tensors using Python control flow. If False, we assume that the layer can safely be used to generate a static computation graph.
name

The name of the layer (string).

dtype

The dtype of the layer’s weights.

variable_dtype

Alias of dtype.

compute_dtype

The dtype of the layer’s computations. Layers automatically cast inputs to this dtype which causes the computations and output to also be in this dtype. When mixed precision is used with a tf.keras.mixed_precision.Policy, this will be different than variable_dtype.

dtype_policy

The layer’s dtype policy. See the tf.keras.mixed_precision.Policy documentation for details.

trainable_weights

List of variables to be included in backprop.

non_trainable_weights

List of variables that should not be included in backprop.

weights

The concatenation of the lists trainable_weights and non_trainable_weights (in this order).

trainable

Whether the layer should be trained (boolean), i.e. whether its potentially-trainable weights should be returned as part of layer.trainable_weights.

input_spec

Optional (list of) InputSpec object(s) specifying the constraints on inputs that can be accepted by the layer.

We recommend that descendants of Layer implement the following methods:

  • __init__(): Defines custom layer attributes, and creates layer state variables that do not depend on input shapes, using add_weight().

  • build(self, input_shape): This method can be used to create weights that depend on the shape(s) of the input(s), using add_weight(). __call__() will automatically build the layer (if it has not been built yet) by calling build().

  • call(self, inputs, *args, **kwargs): Called in __call__ after making sure build() has been called. call() performs the logic of applying the layer to the input tensors (which should be passed in as argument). Two reserved keyword arguments you can optionally use in call() are:

    A typical signature for this method is call(self, inputs), and user could optionally add training and mask if the layer need them. *args and **kwargs is only useful for future extension when more input parameters are planned to be added.

  • get_config(self): Returns a dictionary containing the configuration used to initialize this layer. If the keys differ from the arguments in __init__, then override from_config(self) as well. This method is used when saving the layer or a model that contains this layer.

Examples:

Here’s a basic example: a layer with two variables, w and b, that returns y = w . x + b. It shows how to implement build() and call(). Variables set as attributes of a layer are tracked as weights of the layers (in layer.weights).

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape): # Create the state of the layer (weights)

w_init = tf.random_normal_initializer() self.w = tf.Variable(

initial_value=w_init(shape=(input_shape[-1], self.units),
dtype=’float32’),

trainable=True)

b_init = tf.zeros_initializer() self.b = tf.Variable(

initial_value=b_init(shape=(self.units,), dtype=’float32’), trainable=True)
def call(self, inputs): # Defines the computation from inputs to outputs
return tf.matmul(inputs, self.w) + self.b

# Instantiates the layer. linear_layer = SimpleDense(4)

# This will also call build(input_shape) and create the weights. y = linear_layer(tf.ones((2, 2))) assert len(linear_layer.weights) == 2

# These weights are trainable, so they’re listed in trainable_weights: assert len(linear_layer.trainable_weights) == 2 ```

Note that the method add_weight() offers a shortcut to create weights:

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape):
self.w = self.add_weight(shape=(input_shape[-1], self.units),
initializer=’random_normal’, trainable=True)
self.b = self.add_weight(shape=(self.units,),
initializer=’random_normal’, trainable=True)
def call(self, inputs):
return tf.matmul(inputs, self.w) + self.b

```

Besides trainable weights, updated via backpropagation during training, layers can also have non-trainable weights. These weights are meant to be updated manually during call(). Here’s a example layer that computes the running sum of its inputs:

```python class ComputeSum(Layer):

def __init__(self, input_dim):

super(ComputeSum, self).__init__() # Create a non-trainable weight. self.total = tf.Variable(initial_value=tf.zeros((input_dim,)),

trainable=False)
def call(self, inputs):
self.total.assign_add(tf.reduce_sum(inputs, axis=0)) return self.total

my_sum = ComputeSum(2) x = tf.ones((2, 2))

y = my_sum(x) print(y.numpy()) # [2. 2.]

y = my_sum(x) print(y.numpy()) # [4. 4.]

assert my_sum.weights == [my_sum.total] assert my_sum.non_trainable_weights == [my_sum.total] assert my_sum.trainable_weights == [] ```

For more information about creating layers, see the guide [Making new Layers and Models via subclassing](

__init__(self, output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Initialize self. See help(type(self)) for accurate signature.

call(self, inputs, training=False, mask=None)[source]

The forward pass of the block.

Parameters:
  • inputs – The input tensor.
  • training – A boolean specifying if the layer should be in training mode.
  • mask – A mask for the input tensor.
Returns:

The output tensor of the layer.

class BottleNeckResidualLightCurveNetworkBlockEveryWeightBatchNormBnAfterActivations(output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Bases: tensorflow.keras.layers.Layer

This is the class from which all layers inherit.

A layer is a callable object that takes as input one or more tensors and that outputs one or more tensors. It involves computation, defined in the call() method, and a state (weight variables), defined either in the constructor __init__() or in the build() method.

Users will just instantiate a layer and then treat it as a callable.

Parameters:
  • trainable – Boolean, whether the layer’s variables should be trainable.
  • name – String name of the layer.
  • dtype – The dtype of the layer’s computations and weights. Can also be a tf.keras.mixed_precision.Policy, which allows the computation and weight dtype to differ. Default of None means to use tf.keras.mixed_precision.global_policy(), which is a float32 policy unless set to different value.
  • dynamic – Set this to True if your layer should only be run eagerly, and should not be used to generate a static computation graph. This would be the case for a Tree-RNN or a recursive network, for example, or generally for any layer that manipulates tensors using Python control flow. If False, we assume that the layer can safely be used to generate a static computation graph.
name

The name of the layer (string).

dtype

The dtype of the layer’s weights.

variable_dtype

Alias of dtype.

compute_dtype

The dtype of the layer’s computations. Layers automatically cast inputs to this dtype which causes the computations and output to also be in this dtype. When mixed precision is used with a tf.keras.mixed_precision.Policy, this will be different than variable_dtype.

dtype_policy

The layer’s dtype policy. See the tf.keras.mixed_precision.Policy documentation for details.

trainable_weights

List of variables to be included in backprop.

non_trainable_weights

List of variables that should not be included in backprop.

weights

The concatenation of the lists trainable_weights and non_trainable_weights (in this order).

trainable

Whether the layer should be trained (boolean), i.e. whether its potentially-trainable weights should be returned as part of layer.trainable_weights.

input_spec

Optional (list of) InputSpec object(s) specifying the constraints on inputs that can be accepted by the layer.

We recommend that descendants of Layer implement the following methods:

  • __init__(): Defines custom layer attributes, and creates layer state variables that do not depend on input shapes, using add_weight().

  • build(self, input_shape): This method can be used to create weights that depend on the shape(s) of the input(s), using add_weight(). __call__() will automatically build the layer (if it has not been built yet) by calling build().

  • call(self, inputs, *args, **kwargs): Called in __call__ after making sure build() has been called. call() performs the logic of applying the layer to the input tensors (which should be passed in as argument). Two reserved keyword arguments you can optionally use in call() are:

    A typical signature for this method is call(self, inputs), and user could optionally add training and mask if the layer need them. *args and **kwargs is only useful for future extension when more input parameters are planned to be added.

  • get_config(self): Returns a dictionary containing the configuration used to initialize this layer. If the keys differ from the arguments in __init__, then override from_config(self) as well. This method is used when saving the layer or a model that contains this layer.

Examples:

Here’s a basic example: a layer with two variables, w and b, that returns y = w . x + b. It shows how to implement build() and call(). Variables set as attributes of a layer are tracked as weights of the layers (in layer.weights).

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape): # Create the state of the layer (weights)

w_init = tf.random_normal_initializer() self.w = tf.Variable(

initial_value=w_init(shape=(input_shape[-1], self.units),
dtype=’float32’),

trainable=True)

b_init = tf.zeros_initializer() self.b = tf.Variable(

initial_value=b_init(shape=(self.units,), dtype=’float32’), trainable=True)
def call(self, inputs): # Defines the computation from inputs to outputs
return tf.matmul(inputs, self.w) + self.b

# Instantiates the layer. linear_layer = SimpleDense(4)

# This will also call build(input_shape) and create the weights. y = linear_layer(tf.ones((2, 2))) assert len(linear_layer.weights) == 2

# These weights are trainable, so they’re listed in trainable_weights: assert len(linear_layer.trainable_weights) == 2 ```

Note that the method add_weight() offers a shortcut to create weights:

```python class SimpleDense(Layer):

def __init__(self, units=32):
super(SimpleDense, self).__init__() self.units = units
def build(self, input_shape):
self.w = self.add_weight(shape=(input_shape[-1], self.units),
initializer=’random_normal’, trainable=True)
self.b = self.add_weight(shape=(self.units,),
initializer=’random_normal’, trainable=True)
def call(self, inputs):
return tf.matmul(inputs, self.w) + self.b

```

Besides trainable weights, updated via backpropagation during training, layers can also have non-trainable weights. These weights are meant to be updated manually during call(). Here’s a example layer that computes the running sum of its inputs:

```python class ComputeSum(Layer):

def __init__(self, input_dim):

super(ComputeSum, self).__init__() # Create a non-trainable weight. self.total = tf.Variable(initial_value=tf.zeros((input_dim,)),

trainable=False)
def call(self, inputs):
self.total.assign_add(tf.reduce_sum(inputs, axis=0)) return self.total

my_sum = ComputeSum(2) x = tf.ones((2, 2))

y = my_sum(x) print(y.numpy()) # [2. 2.]

y = my_sum(x) print(y.numpy()) # [4. 4.]

assert my_sum.weights == [my_sum.total] assert my_sum.non_trainable_weights == [my_sum.total] assert my_sum.trainable_weights == [] ```

For more information about creating layers, see the guide [Making new Layers and Models via subclassing](

__init__(self, output_channels: int, input_channels: Optional[int] = None, kernel_size: int = 3, pooling_size: int = 1, batch_normalization: bool = True, dropout_rate: float = 0.0, l2_regularization: float = 0.0)[source]

Initialize self. See help(type(self)) for accurate signature.

call(self, inputs, training=False, mask=None)[source]

The forward pass of the block.

Parameters:
  • inputs – The input tensor.
  • training – A boolean specifying if the layer should be in training mode.
  • mask – A mask for the input tensor.
Returns:

The output tensor of the layer.