executor

The Executor.

An object that, given an ashpy.contexts.Context, carries a function and the way of executing it.

Classes

Executor Carry a function and the way of executing it.
SumExecutor The sum executor.
class ashpy.losses.executor.Executor(fn=None)[source]

Bases: object

Carry a function and the way of executing it. Given a context.

__init__(fn=None)[source]

Initialize the Executor.

Parameters:fn (tf.keras.losses.Loss) – A Keras Loss to execute.
Return type:None
Returns:None
call(context, **kwargs)[source]

Execute the function, using the information provided by the context.

Parameters:context (ashpy.contexts.Context) – The function execution Context.
Return type:Tensor
Returns:tf.Tensor – Output Tensor.
fn

Return the Keras loss function to execute.

Return type:Loss
Returns:tf.keras.losses.Loss – Keras Loss.
global_batch_size

Global batch size comprises the batch size for each cpu.

Calculated as batch_size_for_replica*replica_numbers.

Return type:int
Returns:int – Global Batch size value.
static reduce_loss(call_fn)[source]

Create a Decorator to reduce Losses. Used to simplify things.

Apply a reduce sum operation to the loss and divide the result by the batch size.

Parameters:call_fn (typing.Callable) – The executor call method.
Return type:Callable
Returns:typing.Callable – The decorated function.
weight

Return the loss weight.

This weight is multiplied by the loss value. This is useful when working with multiples losses.

Return type:Callable[…, float]
Returns:typing.Callable – Callable returning the weight (float).
class ashpy.losses.executor.SumExecutor(executors)[source]

Bases: ashpy.losses.executor.Executor

The sum executor. Executes the call of each fn and weights the losses.

Each Executor gets called (thus reducing its carried function), the results are then summed together.

__init__(executors)[source]

Initialize the SumExecutor.

Parameters:executors (list of [ashpy.executors.Executor]) – Array of ashpy.executors.Executor to sum evaluate and sum together.
Return type:None
Returns:None
call(*args, **kwargs)[source]

Evaluate and sum together the Executors.

Return type:Tensor
Returns::py:classes:`tf.Tensor` – Output Tensor.
executors

Return the List of Executors.

Return type:List[Executor]
global_batch_size

Global batch size comprises the batch size for each cpu.

Calculated as batch_size_for_replica*replica_numbers.

Return type:int
Returns:int – Global Batch size value.