ReshapeFlow¶
-
class
tfsnippet.layers.
ReshapeFlow
(x_value_ndims, y_value_shape, require_batch_dims=False, name=None, scope=None)¶ Bases:
tfsnippet.layers.flows.base.BaseFlow
A flow which reshapes the last x_value_ndims of x into y_value_shape.
Usage:
# to reshape a conv2d output into dense input flow = ReshapeFlow(x_value_ndims=3, y_value_shape=[-1]) x = tf.random_normal(shape=[2, 3, 4, 5]) y, log_det = flow.transform(x) # y == tf.reshape(x, [2, -1]) # log_det == tf.zeros([2])
Attributes Summary
explicitly_invertible
Whether or not this flow is explicitly invertible? name
Get the name of this object. require_batch_dims
Whether or not this flow requires batch dimensions. variable_scope
Get the variable scope of this object. x_value_ndims
Get the number of value dimensions in x. y_value_ndims
Get the number of value dimensions in y. Methods Summary
__call__
(…) <==> x(…)apply
(input)Apply the layer on input, to produce output. build
([input])Build the layer, creating all required variables. inverse_transform
(y[, compute_x, …])Transform y into x, and compute the log-determinant of f^{-1} at y (i.e., \(\log \det \frac{\partial f^{-1}(y)}{\partial y}\)). invert
()Get the inverted flow from this flow. transform
(x[, compute_y, compute_log_det, name])Transform x into y, and compute the log-determinant of f at x (i.e., \(\log \det \frac{\partial f(x)}{\partial x}\)). Attributes Documentation
-
explicitly_invertible
¶ Whether or not this flow is explicitly invertible?
If a flow is not explicitly invertible, then it only supports to transform x into y, and corresponding \(\log p(x)\) into \(\log p(y)\). It cannot compute \(\log p(y)\) directly without knowing x, nor can it transform x back into y.
Returns: - A boolean indicating whether or not the flow is explicitly
- invertible.
Return type: bool
-
name
¶ Get the name of this object.
-
require_batch_dims
¶ Whether or not this flow requires batch dimensions.
-
variable_scope
¶ Get the variable scope of this object.
-
x_value_ndims
¶ Get the number of value dimensions in x.
Returns: The number of value dimensions in x. Return type: int
-
y_value_ndims
¶ Get the number of value dimensions in y.
Returns: The number of value dimensions in y. Return type: int
Methods Documentation
-
__call__
(...) <==> x(...)¶
-
apply
(input)¶ Apply the layer on input, to produce output.
Parameters: input (Tensor or list[Tensor]) – The input tensor, or a list of input tensors. Returns: The output tensor, or a list of output tensors.
-
build
(input=None)¶ Build the layer, creating all required variables.
Parameters: input (Tensor or list[Tensor] or None) – If build()
is called withinapply()
, it will be the input tensor(s). Otherwise if it is called separately, it will beNone
.
-
inverse_transform
(y, compute_x=True, compute_log_det=True, name=None)¶ Transform y into x, and compute the log-determinant of f^{-1} at y (i.e., \(\log \det \frac{\partial f^{-1}(y)}{\partial y}\)).
Parameters: Returns: Return type: (tf.Tensor, tf.Tensor)
Raises: RuntimeError
– If both compute_x and compute_log_det are set toFalse
.RuntimeError
– If the flow is not explicitly invertible.
-
invert
()¶ Get the inverted flow from this flow.
The
transform()
will become theinverse_transform()
in the inverted flow, and theinverse_transform()
will become thetransform()
in the inverted flow.If the current flow has not been initialized, it must be initialized via
inverse_transform()
in the new flow.Returns: The inverted flow. Return type: tfsnippet.layers.InvertFlow
-
transform
(x, compute_y=True, compute_log_det=True, name=None)¶ Transform x into y, and compute the log-determinant of f at x (i.e., \(\log \det \frac{\partial f(x)}{\partial x}\)).
Parameters: Returns: Return type: (tf.Tensor, tf.Tensor)
Raises: RuntimeError
– If both compute_y and compute_log_det are set toFalse
.
-