TFGENZOO.flows.flatten module

class TFGENZOO.flows.flatten.Flatten(**kwargs)[source]

Bases: TFGENZOO.flows.flowbase.FlowComponent

Flatten Layer Sources:

Examples

>>> import tenosorflow as tf
>>> from TFGENZOO.flows import Flatten
>>> fl = Flatten()
>>> fl.build([None, 16, 16, 2])
>>> fl(inputs)
(<tf.Tensor 'flatten_2_2/Identity:0' shape=(None, 512) dtype=float32>,
 <tf.Tensor 'flatten_2_2/Identity_1:0' shape=(None,) dtype=float32>)
>>> tf.keras.Model(inputs, fl(inputs)).summary()
Model: "model"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
input_1 (InputLayer)         [(None, 16, 16, 2)]       0
_________________________________________________________________
flatten_2 (Flatten)          ((None, 512), (None,))    1
=================================================================
Total params: 1
Trainable params: 0
Non-trainable params: 1
_________________________________________________________________
>>> z, ldj = fl(tf.random.normal([1024, 16, 16, 2]))
>>> x, ildj = fl(z, invere=True)
>>> x.shape
TensorShape([1024, 16, 16, 2])
build(input_shape)[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, **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(x: tensorflow.python.framework.ops.Tensor, **kwargs)[source]