TFGENZOO.flows.flowbase module

class TFGENZOO.flows.flowbase.ConditionalFlowModule(components: List[TFGENZOO.flows.flowbase.FlowComponent], **kwargs)[source]

Bases: TFGENZOO.flows.flowbase.FlowBase

Sequential Layer for FlowBase’s Layer

Examples

>>> layers = [FlowBase() for _ in range(10)]
>>> module = FlowModule(layers)
>>> z = module(x, inverse=False)
>>> x_hat = module(z, inverse=True)
>>> assert ((x - x_hat)^2) << 1e-3
build(input_shape: tensorflow.python.framework.tensor_shape.TensorShape)[source]

Creates the variables of the layer (optional, for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call.

This is typically used to create the weights of Layer subclasses.

Parameters

input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).

forward(x: tensorflow.python.framework.ops.Tensor, cond: tensorflow.python.framework.ops.Tensor, **kwargs)[source]
get_config()[source]

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).

Returns

Python dictionary.

inverse(z: tensorflow.python.framework.ops.Tensor, cond: tensorflow.python.framework.ops.Tensor, **kwargs)[source]
class TFGENZOO.flows.flowbase.FactorOutBase(with_zaux: bool = False, **kwargs)[source]

Bases: TFGENZOO.flows.flowbase.FlowBase

Factor Out Layer in Flow-based Model

Examples

>>> fo = FactorOutBase(with_zaux=False)
>>> z, zaux = fo(x, zaux=None, inverse=False)
>>> x = fo(z, zaux=zaux, inverse=True)
>>> fo = FactorOutBase(with_zaux=True)
>>> z, zaux = fo(x, zaux=zaux, inverse=False)
>>> x, zaux = fo(z, zaux=zaux, inverse=True)
build(input_shape: tensorflow.python.framework.tensor_shape.TensorShape)[source]

Creates the variables of the layer (optional, for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call.

This is typically used to create the weights of Layer subclasses.

Parameters

input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).

call(x: tensorflow.python.framework.ops.Tensor, zaux: tensorflow.python.framework.ops.Tensor = None, inverse=False, **kwargs)[source]

This is where the layer’s logic lives.

Parameters
  • inputs – Input tensor, or list/tuple of input tensors.

  • **kwargs – Additional keyword arguments.

Returns

A tensor or list/tuple of tensors.

abstract forward(x: tensorflow.python.framework.ops.Tensor, zaux: tensorflow.python.framework.ops.Tensor, **kwargs)[source]
get_config()[source]

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).

Returns

Python dictionary.

abstract inverse(x: tensorflow.python.framework.ops.Tensor, zaux: tensorflow.python.framework.ops.Tensor, **kwargs)[source]
class TFGENZOO.flows.flowbase.FlowBase(**kwargs)[source]

Bases: tensorflow.python.keras.engine.base_layer.Layer

Flow-based model’s abstruct class

Examples

>>> layer = FlowBase()
>>> z = layer(x, inverse=False) # forward method
>>> x_hat = layer(z, inverse=True) # inverse method
>>> assert tf.reduce_sum((x - x_hat)^2) << 1e-3

Note

If you need data-dependent initialization (e.g. ActNorm), You can write it at #initialize_parameter.

This layer will be inheritanced by the invertible layer without log det jacobian

build(input_shape: tensorflow.python.framework.tensor_shape.TensorShape)[source]

Creates the variables of the layer (optional, for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call.

This is typically used to create the weights of Layer subclasses.

Parameters

input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).

call(x: tensorflow.python.framework.ops.Tensor, inverse=False, **kwargs)[source]

This is where the layer’s logic lives.

Parameters
  • inputs – Input tensor, or list/tuple of input tensors.

  • **kwargs – Additional keyword arguments.

Returns

A tensor or list/tuple of tensors.

data_dep_initialize(x: tensorflow.python.framework.ops.Tensor)[source]
abstract forward(inputs, **kwargs)[source]
abstract inverse(inputs, **kwargs)[source]
class TFGENZOO.flows.flowbase.FlowComponent(**kwargs)[source]

Bases: TFGENZOO.flows.flowbase.FlowBase

Flow-based model’s abstruct class

Note

This layer will be inheritanced by the invertible layer with log det jacobian

assert_log_det_jacobian(log_det_jacobian: tensorflow.python.framework.ops.Tensor)[source]

assert log_det_jacobian’s shape

Note

tf-2.0’s bug
tf.debugging.assert_shapes([(tf.constant(1.0), (None, ))])
# => None (true)
tf.debugging.assert_shapes([(tf.constant([1.0, 1.0]), (None, ))])
# => None (true)
tf.debugging.assert_shapes([(tf.constant([[1.0], [1.0]]), (None, ))])
# => Error
assert_tensor(x: tensorflow.python.framework.ops.Tensor, z: tensorflow.python.framework.ops.Tensor)[source]
abstract forward(x, **kwargs)[source]
abstract inverse(z, **kwargs)[source]
class TFGENZOO.flows.flowbase.FlowModule(components: List[TFGENZOO.flows.flowbase.FlowComponent], **kwargs)[source]

Bases: TFGENZOO.flows.flowbase.FlowBase

Sequential Layer for FlowBase’s Layer

Examples

>>> layers = [FlowBase() for _ in range(10)]
>>> module = FlowModule(layers)
>>> z = module(x, inverse=False)
>>> x_hat = module(z, inverse=True)
>>> assert ((x - x_hat)^2) << 1e-3
build(input_shape: tensorflow.python.framework.tensor_shape.TensorShape)[source]

Creates the variables of the layer (optional, for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call.

This is typically used to create the weights of Layer subclasses.

Parameters

input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).

forward(x, **kwargs)[source]
get_config()[source]

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).

Returns

Python dictionary.

inverse(z, **kwargs)[source]