def avg_pool3d(input, ksize, strides, padding, name=None)
Performs 3D average pooling on the input.
Args:
input: A Tensor
. Must be one of the following types: float32
, float64
, int64
, int32
, uint8
, uint16
, int16
, int8
, complex64
, complex128
, qint8
, quint8
, qint32
, half
.
Shape [batch, depth, rows, cols, channels]
tensor to pool over.
ksize: A list of ints
that has length >= 5
.
1-D tensor of length 5. The size of the window for each dimension of
the input tensor. Must have ksize[0] = ksize[4] = 1
.
strides: A list of ints
that has length >= 5
.
1-D tensor of length 5. The stride of the sliding window for each
dimension of input
. Must have strides[0] = strides[4] = 1
.
padding: A string
from: "SAME", "VALID"
.
The type of padding algorithm to use.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as input
.
The average pooled output tensor.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def avg_pool3d_grad(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.avg_pool3d_grad, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.avg_pool3d_grad
Return
Applicative
Origial documentation for Builder.avg_pool3d_grad
def avg_pool3d_grad(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.nn.avg_pool3d_grad
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.nn.avg_pool3d_grad
def avg_pool3d_grad(orig_input_shape, grad, ksize, strides, padding, name=None)
Computes gradients of average pooling function.
Args:
orig_input_shape: A Tensor
of type int32
.
The original input dimensions.
grad: A Tensor
. Must be one of the following types: float32
, float64
, int64
, int32
, uint8
, uint16
, int16
, int8
, complex64
, complex128
, qint8
, quint8
, qint32
, half
.
Output backprop of shape [batch, depth, rows, cols, channels]
.
ksize: A list of ints
that has length >= 5
.
1-D tensor of length 5. The size of the window for each dimension of
the input tensor. Must have ksize[0] = ksize[4] = 1
.
strides: A list of ints
that has length >= 5
.
1-D tensor of length 5. The stride of the sliding window for each
dimension of input
. Must have strides[0] = strides[4] = 1
.
padding: A string
from: "SAME", "VALID"
.
The type of padding algorithm to use.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as grad
. The backprop for input.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def avg_pool3d_grad_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.avg_pool3d_grad_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.avg_pool3d_grad_layer
Return
Applicative
Origial documentation for Builder.avg_pool3d_grad_layer
def avg_pool3d_grad_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.avg_pool3d_grad, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.avg_pool3d_grad
def avg_pool3d_grad(orig_input_shape, grad, ksize, strides, padding, name=None):
Computes gradients of average pooling function.
Args:
orig_input_shape: A Tensor
of type int32
.
The original input dimensions.
grad: A Tensor
. Must be one of the following types: float32
, float64
, int64
, int32
, uint8
, uint16
, int16
, int8
, complex64
, complex128
, qint8
, quint8
, qint32
, half
.
Output backprop of shape [batch, depth, rows, cols, channels]
.
ksize: A list of ints
that has length >= 5
.
1-D tensor of length 5. The size of the window for each dimension of
the input tensor. Must have ksize[0] = ksize[4] = 1
.
strides: A list of ints
that has length >= 5
.
1-D tensor of length 5. The stride of the sliding window for each
dimension of input
. Must have strides[0] = strides[4] = 1
.
padding: A string
from: "SAME", "VALID"
.
The type of padding algorithm to use.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as grad
. The backprop for input.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def avg_pool3d_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.avg_pool3d_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.avg_pool3d_layer
Return
Applicative
Origial documentation for Builder.avg_pool3d_layer
def avg_pool3d_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.avg_pool3d, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.avg_pool3d
def avg_pool3d(input, ksize, strides, padding, name=None):
Performs 3D average pooling on the input.
Args:
input: A Tensor
. Must be one of the following types: float32
, float64
, int64
, int32
, uint8
, uint16
, int16
, int8
, complex64
, complex128
, qint8
, quint8
, qint32
, half
.
Shape [batch, depth, rows, cols, channels]
tensor to pool over.
ksize: A list of ints
that has length >= 5
.
1-D tensor of length 5. The size of the window for each dimension of
the input tensor. Must have ksize[0] = ksize[4] = 1
.
strides: A list of ints
that has length >= 5
.
1-D tensor of length 5. The stride of the sliding window for each
dimension of input
. Must have strides[0] = strides[4] = 1
.
padding: A string
from: "SAME", "VALID"
.
The type of padding algorithm to use.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as input
.
The average pooled output tensor.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def avg_pool_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.avg_pool_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.avg_pool_layer
Return
Applicative
Origial documentation for Builder.avg_pool_layer
def avg_pool_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.avg_pool, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.avg_pool
def avg_pool(value, ksize, strides, padding, data_format="NHWC", name=None):
Performs the average pooling on the input.
Each entry in output
is the mean of the corresponding size ksize
window in value
.
Args:
value: A 4-D Tensor
of shape [batch, height, width, channels]
and type
float32
, float64
, qint8
, quint8
, or qint32
.
ksize: A list of ints that has length >= 4.
The size of the window for each dimension of the input tensor.
strides: A list of ints that has length >= 4.
The stride of the sliding window for each dimension of the
input tensor.
padding: A string, either 'VALID'
or 'SAME'
. The padding algorithm.
See the comment here
data_format: A string. 'NHWC' and 'NCHW' are supported.
name: Optional name for the operation.
Returns:
A Tensor
with the same type as value
. The average pooled output tensor.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def batch_matmul_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.batch_matmul_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.batch_matmul_layer
Return
Applicative
Origial documentation for Builder.batch_matmul_layer
def batch_matmul_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.batch_matmul, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.batch_matmul
def _batch_mat_mul(x, y, adj_x=None, adj_y=None, name=None):
Multiplies slices of two tensors in batches.
Multiplies all slices of Tensor
x
and y
(each slice can be
viewed as an element of a batch), and arranges the individual results
in a single output tensor of the same batch size. Each of the
individual slices can optionally be adjointed (to adjoint a matrix
means to transpose and conjugate it) before multiplication by setting
the adj_x
or adj_y
flag to True
, which are by default False
.
The input tensors x
and y
are 3-D or higher with shape [..., r_x, c_x]
and [..., r_y, c_y]
.
The output tensor is 3-D or higher with shape [..., r_o, c_o]
, where:
r_o = c_x if adj_x else r_x c_o = r_y if adj_y else c_y
It is computed as:
output[..., :, :] = matrix(x[..., :, :]) * matrix(y[..., :, :])
Args:
x: A Tensor
. Must be one of the following types: half
, float32
, float64
, int32
, complex64
, complex128
.
3-D or higher with shape [..., r_x, c_x]
.
y: A Tensor
. Must have the same type as x
.
3-D or higher with shape [..., r_y, c_y]
.
adj_x: An optional bool
. Defaults to False
.
If True
, adjoint the slices of x
. Defaults to False
.
adj_y: An optional bool
. Defaults to False
.
If True
, adjoint the slices of y
. Defaults to False
.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as x
.
3-D or higher with shape [..., r_o, c_o]
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def batch_norm_with_global_normalization(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.batch_norm_with_global_normalization, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.batch_norm_with_global_normalization
Return
Applicative
Origial documentation for Builder.batch_norm_with_global_normalization
def batch_norm_with_global_normalization(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.nn.batch_norm_with_global_normalization
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.nn.batch_norm_with_global_normalization
def batch_norm_with_global_normalization(t, m, v, beta, gamma, variance_epsilon, scale_after_normalization, name=None)
Batch normalization.
This op is deprecated. See tf.nn.batch_normalization
.
Args: t: A 4D input Tensor. m: A 1D mean Tensor with size matching the last dimension of t. This is the first output from tf.nn.moments, or a saved moving average thereof. v: A 1D variance Tensor with size matching the last dimension of t. This is the second output from tf.nn.moments, or a saved moving average thereof. beta: A 1D beta Tensor with size matching the last dimension of t. An offset to be added to the normalized tensor. gamma: A 1D gamma Tensor with size matching the last dimension of t. If "scale_after_normalization" is true, this tensor will be multiplied with the normalized tensor. variance_epsilon: A small float number to avoid dividing by 0. scale_after_normalization: A bool indicating whether the resulted tensor needs to be multiplied with gamma. name: A name for this operation (optional).
Returns:
A batch-normalized t
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def batch_norm_with_global_normalization_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.batch_norm_with_global_normalization_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.batch_norm_with_global_normalization_layer
Return
Applicative
Origial documentation for Builder.batch_norm_with_global_normalization_layer
def batch_norm_with_global_normalization_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.batch_norm_with_global_normalization, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.batch_norm_with_global_normalization
def batch_norm_with_global_normalization(t, m, v, beta, gamma, variance_epsilon, scale_after_normalization, name=None):
Batch normalization.
This op is deprecated. See tf.nn.batch_normalization
.
Args: t: A 4D input Tensor. m: A 1D mean Tensor with size matching the last dimension of t. This is the first output from tf.nn.moments, or a saved moving average thereof. v: A 1D variance Tensor with size matching the last dimension of t. This is the second output from tf.nn.moments, or a saved moving average thereof. beta: A 1D beta Tensor with size matching the last dimension of t. An offset to be added to the normalized tensor. gamma: A 1D gamma Tensor with size matching the last dimension of t. If "scale_after_normalization" is true, this tensor will be multiplied with the normalized tensor. variance_epsilon: A small float number to avoid dividing by 0. scale_after_normalization: A bool indicating whether the resulted tensor needs to be multiplied with gamma. name: A name for this operation (optional).
Returns:
A batch-normalized t
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def batch_normalization(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.batch_normalization, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.batch_normalization
Return
Applicative
Origial documentation for Builder.batch_normalization
def batch_normalization(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.nn.batch_normalization
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.nn.batch_normalization
def batch_normalization(x, mean, variance, offset, scale, variance_epsilon, name=None)
Batch normalization.
As described in http://arxiv.org/abs/1502.03167.
Normalizes a tensor by mean
and variance
, and applies (optionally) a
scale
\\(\gamma\\) to it, as well as an offset
\\(\beta\\):
\\(\frac{\gamma(x-\mu)}{\sigma}+\beta\\)
mean
, variance
, offset
and scale
are all expected to be of one of two
shapes:
* In all generality, they can have the same number of dimensions as the
input x
, with identical sizes as x
for the dimensions that are not
normalized over (the 'depth' dimension(s)), and dimension 1 for the
others which are being normalized over.
mean
and variance
in this case would typically be the outputs of
tf.nn.moments(..., keep_dims=True)
during training, or running averages
thereof during inference.
* In the common case where the 'depth' dimension is the last dimension in
the input tensor x
, they may be one dimensional tensors of the same
size as the 'depth' dimension.
This is the case for example for the common [batch, depth]
layout of
fully-connected layers, and [batch, height, width, depth]
for
convolutions.
mean
and variance
in this case would typically be the outputs of
tf.nn.moments(..., keep_dims=False)
during training, or running averages
thereof during inference.
Args:
x: Input Tensor
of arbitrary dimensionality.
mean: A mean Tensor
.
variance: A variance Tensor
.
offset: An offset Tensor
, often denoted \\(\beta\\) in equations, or
None. If present, will be added to the normalized tensor.
scale: A scale Tensor
, often denoted \\(\gamma\\) in equations, or
None
. If present, the scale is applied to the normalized tensor.
variance_epsilon: A small float number to avoid dividing by 0.
name: A name for this operation (optional).
Returns: the normalized, scaled, offset tensor.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def batch_normalization_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.batch_normalization_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.batch_normalization_layer
Return
Applicative
Origial documentation for Builder.batch_normalization_layer
def batch_normalization_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.batch_normalization, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.batch_normalization
def batch_normalization(x, mean, variance, offset, scale, variance_epsilon, name=None):
Batch normalization.
As described in http://arxiv.org/abs/1502.03167.
Normalizes a tensor by mean
and variance
, and applies (optionally) a
scale
\\(\gamma\\) to it, as well as an offset
\\(\beta\\):
\\(\frac{\gamma(x-\mu)}{\sigma}+\beta\\)
mean
, variance
, offset
and scale
are all expected to be of one of two
shapes:
* In all generality, they can have the same number of dimensions as the
input x
, with identical sizes as x
for the dimensions that are not
normalized over (the 'depth' dimension(s)), and dimension 1 for the
others which are being normalized over.
mean
and variance
in this case would typically be the outputs of
tf.nn.moments(..., keep_dims=True)
during training, or running averages
thereof during inference.
* In the common case where the 'depth' dimension is the last dimension in
the input tensor x
, they may be one dimensional tensors of the same
size as the 'depth' dimension.
This is the case for example for the common [batch, depth]
layout of
fully-connected layers, and [batch, height, width, depth]
for
convolutions.
mean
and variance
in this case would typically be the outputs of
tf.nn.moments(..., keep_dims=False)
during training, or running averages
thereof during inference.
Args:
x: Input Tensor
of arbitrary dimensionality.
mean: A mean Tensor
.
variance: A variance Tensor
.
offset: An offset Tensor
, often denoted \\(\beta\\) in equations, or
None. If present, will be added to the normalized tensor.
scale: A scale Tensor
, often denoted \\(\gamma\\) in equations, or
None
. If present, the scale is applied to the normalized tensor.
variance_epsilon: A small float number to avoid dividing by 0.
name: A name for this operation (optional).
Returns: the normalized, scaled, offset tensor.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def batch_to_space(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.batch_to_space, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.batch_to_space
Return
Applicative
Origial documentation for Builder.batch_to_space
def batch_to_space(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.batch_to_space
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.batch_to_space
def batch_to_space(input, crops, block_size, name=None)
BatchToSpace for 4-D tensors of type T.
This is a legacy version of the more general BatchToSpaceND.
Rearranges (permutes) data from batch into blocks of spatial data, followed by
cropping. This is the reverse transformation of SpaceToBatch. More specifically,
this op outputs a copy of the input tensor where values from the batch
dimension are moved in spatial blocks to the height
and width
dimensions,
followed by cropping along the height
and width
dimensions.
Args:
input: A Tensor
. 4-D tensor with shape
[batch*block_size*block_size, height_pad/block_size, width_pad/block_size,
depth]
. Note that the batch size of the input tensor must be divisible by
block_size * block_size
.
crops: A Tensor
. Must be one of the following types: int32
, int64
.
2-D tensor of non-negative integers with shape [2, 2]
. It specifies
how many elements to crop from the intermediate result across the spatial
dimensions as follows:
crops = [[crop_top, crop_bottom], [crop_left, crop_right]]
block_size: An int
that is >= 2
.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as input
.
4-D with shape [batch, height, width, depth]
, where:
height = height_pad - crop_top - crop_bottom width = width_pad - crop_left - crop_right
The attr block_size
must be greater than one. It indicates the block size.
Some examples:
(1) For the following input of shape [4, 1, 1, 1]
and block_size of 2:
prettyprint
[[[[1]]], [[[2]]], [[[3]]], [[[4]]]]
The output tensor has shape [1, 2, 2, 1]
and value:
prettyprint
x = [[[[1], [2]], [[3], [4]]]]
(2) For the following input of shape [4, 1, 1, 3]
and block_size of 2:
prettyprint
[[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]], [[10, 11, 12]]]
The output tensor has shape [1, 2, 2, 3]
and value:
prettyprint
x = [[[[1, 2, 3], [4, 5, 6]],
[[7, 8, 9], [10, 11, 12]]]]
(3) For the following input of shape [4, 2, 2, 1]
and block_size of 2:
prettyprint
x = [[[[1], [3]], [[5], [7]]],
[[[2], [4]], [[10], [12]]],
[[[5], [7]], [[13], [15]]],
[[[6], [8]], [[14], [16]]]]
The output tensor has shape [1, 4, 4, 1]
and value:
prettyprint
x = [[[1], [2], [3], [4]],
[[5], [6], [7], [8]],
[[9], [10], [11], [12]],
[[13], [14], [15], [16]]]
(4) For the following input of shape [8, 1, 2, 1]
and block_size of 2:
prettyprint
x = [[[[1], [3]]], [[[9], [11]]], [[[2], [4]]], [[[10], [12]]],
[[[5], [7]]], [[[13], [15]]], [[[6], [8]]], [[[14], [16]]]]
The output tensor has shape [2, 2, 4, 1]
and value:
prettyprint
x = [[[[1], [3]], [[5], [7]]],
[[[2], [4]], [[10], [12]]],
[[[5], [7]], [[13], [15]]],
[[[6], [8]], [[14], [16]]]]
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def batch_to_space_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.batch_to_space_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.batch_to_space_layer
Return
Applicative
Origial documentation for Builder.batch_to_space_layer
def batch_to_space_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.batch_to_space, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.batch_to_space
def batch_to_space(input, crops, block_size, name=None):
BatchToSpace for 4-D tensors of type T.
This is a legacy version of the more general BatchToSpaceND.
Rearranges (permutes) data from batch into blocks of spatial data, followed by
cropping. This is the reverse transformation of SpaceToBatch. More specifically,
this op outputs a copy of the input tensor where values from the batch
dimension are moved in spatial blocks to the height
and width
dimensions,
followed by cropping along the height
and width
dimensions.
Args:
input: A Tensor
. 4-D tensor with shape
[batch*block_size*block_size, height_pad/block_size, width_pad/block_size,
depth]
. Note that the batch size of the input tensor must be divisible by
block_size * block_size
.
crops: A Tensor
. Must be one of the following types: int32
, int64
.
2-D tensor of non-negative integers with shape [2, 2]
. It specifies
how many elements to crop from the intermediate result across the spatial
dimensions as follows:
crops = [[crop_top, crop_bottom], [crop_left, crop_right]]
block_size: An int
that is >= 2
.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as input
.
4-D with shape [batch, height, width, depth]
, where:
height = height_pad - crop_top - crop_bottom width = width_pad - crop_left - crop_right
The attr block_size
must be greater than one. It indicates the block size.
Some examples:
(1) For the following input of shape [4, 1, 1, 1]
and block_size of 2:
prettyprint
[[[[1]]], [[[2]]], [[[3]]], [[[4]]]]
The output tensor has shape [1, 2, 2, 1]
and value:
prettyprint
x = [[[[1], [2]], [[3], [4]]]]
(2) For the following input of shape [4, 1, 1, 3]
and block_size of 2:
prettyprint
[[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]], [[10, 11, 12]]]
The output tensor has shape [1, 2, 2, 3]
and value:
prettyprint
x = [[[[1, 2, 3], [4, 5, 6]],
[[7, 8, 9], [10, 11, 12]]]]
(3) For the following input of shape [4, 2, 2, 1]
and block_size of 2:
prettyprint
x = [[[[1], [3]], [[5], [7]]],
[[[2], [4]], [[10], [12]]],
[[[5], [7]], [[13], [15]]],
[[[6], [8]], [[14], [16]]]]
The output tensor has shape [1, 4, 4, 1]
and value:
prettyprint
x = [[[1], [2], [3], [4]],
[[5], [6], [7], [8]],
[[9], [10], [11], [12]],
[[13], [14], [15], [16]]]
(4) For the following input of shape [8, 1, 2, 1]
and block_size of 2:
prettyprint
x = [[[[1], [3]]], [[[9], [11]]], [[[2], [4]]], [[[10], [12]]],
[[[5], [7]]], [[[13], [15]]], [[[6], [8]]], [[[14], [16]]]]
The output tensor has shape [2, 2, 4, 1]
and value:
prettyprint
x = [[[[1], [3]], [[5], [7]]],
[[[2], [4]], [[10], [12]]],
[[[5], [7]], [[13], [15]]],
[[[6], [8]], [[14], [16]]]]
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def batch_to_space_nd(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.batch_to_space_nd, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.batch_to_space_nd
Return
Applicative
Origial documentation for Builder.batch_to_space_nd
def batch_to_space_nd(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.batch_to_space_nd
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.batch_to_space_nd
def batch_to_space_nd(input, block_shape, crops, name=None)
BatchToSpace for N-D tensors of type T.
This operation reshapes the "batch" dimension 0 into M + 1
dimensions of shape
block_shape + [batch]
, interleaves these blocks back into the grid defined by
the spatial dimensions [1, ..., M]
, to obtain a result with the same rank as
the input. The spatial dimensions of this intermediate result are then
optionally cropped according to crops
to produce the output. This is the
reverse of SpaceToBatch. See below for a precise description.
Args:
input: A Tensor
.
N-D with shape input_shape = [batch] + spatial_shape + remaining_shape
,
where spatial_shape has M dimensions.
block_shape: A Tensor
. Must be one of the following types: int32
, int64
.
1-D with shape [M]
, all values must be >= 1.
crops: A Tensor
. Must be one of the following types: int32
, int64
.
2-D with shape [M, 2]
, all values must be >= 0.
crops[i] = [crop_start, crop_end]
specifies the amount to crop from input
dimension i + 1
, which corresponds to spatial dimension i
. It is
required that
crop_start[i] + crop_end[i] <= block_shape[i] * input_shape[i + 1]
.
This operation is equivalent to the following steps: 1. Reshape `input` to `reshaped` of shape: [block_shape[0], ..., block_shape[M-1], batch / prod(block_shape), input_shape[1], ..., input_shape[N-1]] 2. Permute dimensions of `reshaped` to produce `permuted` of shape [batch / prod(block_shape), input_shape[1], block_shape[0], ..., input_shape[M], block_shape[M-1], input_shape[M+1], ..., input_shape[N-1]] 3. Reshape `permuted` to produce `reshaped_permuted` of shape [batch / prod(block_shape), input_shape[1] * block_shape[0], ..., input_shape[M] * block_shape[M-1], input_shape[M+1], ..., input_shape[N-1]] 4. Crop the start and end of dimensions `[1, ..., M]` of `reshaped_permuted` according to `crops` to produce the output of shape: [batch / prod(block_shape), input_shape[1] * block_shape[0] - crops[0,0] - crops[0,1], ..., input_shape[M] * block_shape[M-1] - crops[M-1,0] - crops[M-1,1], input_shape[M+1], ..., input_shape[N-1]] Some examples: (1) For the following input of shape `[4, 1, 1, 1]`, `block_shape = [2, 2]`, and `crops = [[0, 0], [0, 0]]`: ```prettyprint [[[[1]]], [[[2]]], [[[3]]], [[[4]]]] ``` The output tensor has shape `[1, 2, 2, 1]` and value: ```prettyprint x = [[[[1], [2]], [[3], [4]]]] ``` (2) For the following input of shape `[4, 1, 1, 3]`, `block_shape = [2, 2]`, and `crops = [[0, 0], [0, 0]]`: ```prettyprint [[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]], [[10, 11, 12]]] ``` The output tensor has shape `[1, 2, 2, 3]` and value: ```prettyprint x = [[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]] ``` (3) For the following input of shape `[4, 2, 2, 1]`, `block_shape = [2, 2]`, and `crops = [[0, 0], [0, 0]]`: ```prettyprint x = [[[[1], [3]], [[5], [7]]], [[[2], [4]], [[10], [12]]], [[[5], [7]], [[13], [15]]], [[[6], [8]], [[14], [16]]]] ``` The output tensor has shape `[1, 4, 4, 1]` and value: ```prettyprint x = [[[1], [2], [3], [4]], [[5], [6], [7], [8]], [[9], [10], [11], [12]], [[13], [14], [15], [16]]] ``` (4) For the following input of shape `[8, 1, 3, 1]`, `block_shape = [2, 2]`, and `crops = [[0, 0], [2, 0]]`: ```prettyprint x = [[[[0], [1], [3]]], [[[0], [9], [11]]], [[[0], [2], [4]]], [[[0], [10], [12]]], [[[0], [5], [7]]], [[[0], [13], [15]]], [[[0], [6], [8]]], [[[0], [14], [16]]]] ``` The output tensor has shape `[2, 2, 4, 1]` and value: ```prettyprint x = [[[[1], [2], [3], [4]], [[5], [6], [7], [8]]], [[[9], [10], [11], [12]], [[13], [14], [15], [16]]]] ```
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as input
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def batch_to_space_nd_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.batch_to_space_nd_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.batch_to_space_nd_layer
Return
Applicative
Origial documentation for Builder.batch_to_space_nd_layer
def batch_to_space_nd_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.batch_to_space_nd, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.batch_to_space_nd
def batch_to_space_nd(input, block_shape, crops, name=None):
BatchToSpace for N-D tensors of type T.
This operation reshapes the "batch" dimension 0 into M + 1
dimensions of shape
block_shape + [batch]
, interleaves these blocks back into the grid defined by
the spatial dimensions [1, ..., M]
, to obtain a result with the same rank as
the input. The spatial dimensions of this intermediate result are then
optionally cropped according to crops
to produce the output. This is the
reverse of SpaceToBatch. See below for a precise description.
Args:
input: A Tensor
.
N-D with shape input_shape = [batch] + spatial_shape + remaining_shape
,
where spatial_shape has M dimensions.
block_shape: A Tensor
. Must be one of the following types: int32
, int64
.
1-D with shape [M]
, all values must be >= 1.
crops: A Tensor
. Must be one of the following types: int32
, int64
.
2-D with shape [M, 2]
, all values must be >= 0.
crops[i] = [crop_start, crop_end]
specifies the amount to crop from input
dimension i + 1
, which corresponds to spatial dimension i
. It is
required that
crop_start[i] + crop_end[i] <= block_shape[i] * input_shape[i + 1]
.
This operation is equivalent to the following steps: 1. Reshape `input` to `reshaped` of shape: [block_shape[0], ..., block_shape[M-1], batch / prod(block_shape), input_shape[1], ..., input_shape[N-1]] 2. Permute dimensions of `reshaped` to produce `permuted` of shape [batch / prod(block_shape), input_shape[1], block_shape[0], ..., input_shape[M], block_shape[M-1], input_shape[M+1], ..., input_shape[N-1]] 3. Reshape `permuted` to produce `reshaped_permuted` of shape [batch / prod(block_shape), input_shape[1] * block_shape[0], ..., input_shape[M] * block_shape[M-1], input_shape[M+1], ..., input_shape[N-1]] 4. Crop the start and end of dimensions `[1, ..., M]` of `reshaped_permuted` according to `crops` to produce the output of shape: [batch / prod(block_shape), input_shape[1] * block_shape[0] - crops[0,0] - crops[0,1], ..., input_shape[M] * block_shape[M-1] - crops[M-1,0] - crops[M-1,1], input_shape[M+1], ..., input_shape[N-1]] Some examples: (1) For the following input of shape `[4, 1, 1, 1]`, `block_shape = [2, 2]`, and `crops = [[0, 0], [0, 0]]`: ```prettyprint [[[[1]]], [[[2]]], [[[3]]], [[[4]]]] ``` The output tensor has shape `[1, 2, 2, 1]` and value: ```prettyprint x = [[[[1], [2]], [[3], [4]]]] ``` (2) For the following input of shape `[4, 1, 1, 3]`, `block_shape = [2, 2]`, and `crops = [[0, 0], [0, 0]]`: ```prettyprint [[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]], [[10, 11, 12]]] ``` The output tensor has shape `[1, 2, 2, 3]` and value: ```prettyprint x = [[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]] ``` (3) For the following input of shape `[4, 2, 2, 1]`, `block_shape = [2, 2]`, and `crops = [[0, 0], [0, 0]]`: ```prettyprint x = [[[[1], [3]], [[5], [7]]], [[[2], [4]], [[10], [12]]], [[[5], [7]], [[13], [15]]], [[[6], [8]], [[14], [16]]]] ``` The output tensor has shape `[1, 4, 4, 1]` and value: ```prettyprint x = [[[1], [2], [3], [4]], [[5], [6], [7], [8]], [[9], [10], [11], [12]], [[13], [14], [15], [16]]] ``` (4) For the following input of shape `[8, 1, 3, 1]`, `block_shape = [2, 2]`, and `crops = [[0, 0], [2, 0]]`: ```prettyprint x = [[[[0], [1], [3]]], [[[0], [9], [11]]], [[[0], [2], [4]]], [[[0], [10], [12]]], [[[0], [5], [7]]], [[[0], [13], [15]]], [[[0], [6], [8]]], [[[0], [14], [16]]]] ``` The output tensor has shape `[2, 2, 4, 1]` and value: ```prettyprint x = [[[[1], [2], [3], [4]], [[5], [6], [7], [8]]], [[[9], [10], [11], [12]], [[13], [14], [15], [16]]]] ```
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as input
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def betainc(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.betainc, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.betainc
Return
Applicative
Origial documentation for Builder.betainc
def betainc(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.betainc
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.betainc
def betainc(a, b, x, name=None)
Compute the regularized incomplete beta integral \(I_x(a, b)\).
The regularized incomplete beta integral is defined as:
I_x(a, b) = \frac{B(x; a, b)}{B(a, b)}
where
B(x; a, b) = \int_0^x t^{a-1} (1 - t)^{b-1} dt
is the incomplete beta function and \(B(a, b)\) is the complete beta function.
Args:
a: A Tensor
. Must be one of the following types: float32
, float64
.
b: A Tensor
. Must have the same type as a
.
x: A Tensor
. Must have the same type as a
.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as a
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def betainc_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.betainc_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.betainc_layer
Return
Applicative
Origial documentation for Builder.betainc_layer
def betainc_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.betainc, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.betainc
def betainc(a, b, x, name=None):
Compute the regularized incomplete beta integral \(I_x(a, b)\).
The regularized incomplete beta integral is defined as:
I_x(a, b) = \frac{B(x; a, b)}{B(a, b)}
where
B(x; a, b) = \int_0^x t^{a-1} (1 - t)^{b-1} dt
is the incomplete beta function and \(B(a, b)\) is the complete beta function.
Args:
a: A Tensor
. Must be one of the following types: float32
, float64
.
b: A Tensor
. Must have the same type as a
.
x: A Tensor
. Must have the same type as a
.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as a
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bias_add(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bias_add, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bias_add
Return
Applicative
Origial documentation for Builder.bias_add
def bias_add(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.nn.bias_add
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.nn.bias_add
def bias_add(value, bias, data_format=None, name=None)
Adds bias
to value
.
This is (mostly) a special case of tf.add
where bias
is restricted to 1-D.
Broadcasting is supported, so value
may have any number of dimensions.
Unlike tf.add
, the type of bias
is allowed to differ from value
in the
case where both types are quantized.
Args:
value: A Tensor
with type float
, double
, int64
, int32
, uint8
,
int16
, int8
, complex64
, or complex128
.
bias: A 1-D Tensor
with size matching the last dimension of value
.
Must be the same type as value
unless value
is a quantized type,
in which case a different quantized type may be used.
data_format: A string. 'NHWC' and 'NCHW' are supported.
name: A name for the operation (optional).
Returns:
A Tensor
with the same type as value
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bias_add_grad(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bias_add_grad, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bias_add_grad
Return
Applicative
Origial documentation for Builder.bias_add_grad
def bias_add_grad(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.nn.bias_add_grad
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.nn.bias_add_grad
def bias_add_grad(out_backprop, data_format=None, name=None)
The backward operation for "BiasAdd" on the "bias" tensor.
It accumulates all the values from out_backprop into the feature dimension. For NHWC data format, the feature dimension is the last. For NCHW data format, the feature dimension is the third-to-last.
Args:
out_backprop: A Tensor
. Must be one of the following types: float32
, float64
, int64
, int32
, uint8
, uint16
, int16
, int8
, complex64
, complex128
, qint8
, quint8
, qint32
, half
.
Any number of dimensions.
data_format: An optional string
from: "NHWC", "NCHW"
. Defaults to "NHWC"
.
Specify the data format of the input and output data. With the
default format "NHWC", the bias tensor will be added to the last dimension
of the value tensor.
Alternatively, the format could be "NCHW", the data storage order of:
[batch, in_channels, in_height, in_width].
The tensor will be added to "in_channels", the third-to-the-last
dimension.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as out_backprop
.
1-D with size the feature dimension of out_backprop
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bias_add_grad_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bias_add_grad_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bias_add_grad_layer
Return
Applicative
Origial documentation for Builder.bias_add_grad_layer
def bias_add_grad_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.bias_add_grad, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.bias_add_grad
def bias_add_grad(out_backprop, data_format=None, name=None):
The backward operation for "BiasAdd" on the "bias" tensor.
It accumulates all the values from out_backprop into the feature dimension. For NHWC data format, the feature dimension is the last. For NCHW data format, the feature dimension is the third-to-last.
Args:
out_backprop: A Tensor
. Must be one of the following types: float32
, float64
, int64
, int32
, uint8
, uint16
, int16
, int8
, complex64
, complex128
, qint8
, quint8
, qint32
, half
.
Any number of dimensions.
data_format: An optional string
from: "NHWC", "NCHW"
. Defaults to "NHWC"
.
Specify the data format of the input and output data. With the
default format "NHWC", the bias tensor will be added to the last dimension
of the value tensor.
Alternatively, the format could be "NCHW", the data storage order of:
[batch, in_channels, in_height, in_width].
The tensor will be added to "in_channels", the third-to-the-last
dimension.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as out_backprop
.
1-D with size the feature dimension of out_backprop
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bias_add_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bias_add_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bias_add_layer
Return
Applicative
Origial documentation for Builder.bias_add_layer
def bias_add_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.bias_add, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.bias_add
def bias_add(value, bias, data_format=None, name=None):
Adds bias
to value
.
This is (mostly) a special case of tf.add
where bias
is restricted to 1-D.
Broadcasting is supported, so value
may have any number of dimensions.
Unlike tf.add
, the type of bias
is allowed to differ from value
in the
case where both types are quantized.
Args:
value: A Tensor
with type float
, double
, int64
, int32
, uint8
,
int16
, int8
, complex64
, or complex128
.
bias: A 1-D Tensor
with size matching the last dimension of value
.
Must be the same type as value
unless value
is a quantized type,
in which case a different quantized type may be used.
data_format: A string. 'NHWC' and 'NCHW' are supported.
name: A name for the operation (optional).
Returns:
A Tensor
with the same type as value
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bias_add_v1(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bias_add_v1, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bias_add_v1
Return
Applicative
Origial documentation for Builder.bias_add_v1
def bias_add_v1(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.nn.bias_add_v1
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.nn.bias_add_v1
def bias_add_v1(value, bias, name=None)
Adds bias
to value
.
This is a deprecated version of bias_add and will soon to be removed.
This is (mostly) a special case of tf.add
where bias
is restricted to 1-D.
Broadcasting is supported, so value
may have any number of dimensions.
Unlike tf.add
, the type of bias
is allowed to differ from value
in the
case where both types are quantized.
Args:
value: A Tensor
with type float
, double
, int64
, int32
, uint8
,
int16
, int8
, complex64
, or complex128
.
bias: A 1-D Tensor
with size matching the last dimension of value
.
Must be the same type as value
unless value
is a quantized type,
in which case a different quantized type may be used.
name: A name for the operation (optional).
Returns:
A Tensor
with the same type as value
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bias_add_v1_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bias_add_v1_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bias_add_v1_layer
Return
Applicative
Origial documentation for Builder.bias_add_v1_layer
def bias_add_v1_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.bias_add_v1, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.bias_add_v1
def bias_add_v1(value, bias, name=None):
Adds bias
to value
.
This is a deprecated version of bias_add and will soon to be removed.
This is (mostly) a special case of tf.add
where bias
is restricted to 1-D.
Broadcasting is supported, so value
may have any number of dimensions.
Unlike tf.add
, the type of bias
is allowed to differ from value
in the
case where both types are quantized.
Args:
value: A Tensor
with type float
, double
, int64
, int32
, uint8
,
int16
, int8
, complex64
, or complex128
.
bias: A 1-D Tensor
with size matching the last dimension of value
.
Must be the same type as value
unless value
is a quantized type,
in which case a different quantized type may be used.
name: A name for the operation (optional).
Returns:
A Tensor
with the same type as value
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bidirectional_dynamic_rnn(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bidirectional_dynamic_rnn, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bidirectional_dynamic_rnn
Return
Applicative
Origial documentation for Builder.bidirectional_dynamic_rnn
def bidirectional_dynamic_rnn(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.nn.bidirectional_dynamic_rnn
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.nn.bidirectional_dynamic_rnn
def bidirectional_dynamic_rnn(cell_fw, cell_bw, inputs, sequence_length=None, initial_state_fw=None, initial_state_bw=None, dtype=None, parallel_iterations=None, swap_memory=False, time_major=False, scope=None)
Creates a dynamic version of bidirectional recurrent neural network.
Similar to the unidirectional case above (rnn) but takes input and builds independent forward and backward RNNs. The input_size of forward and backward cell must match. The initial state for both directions is zero by default (but can be set optionally) and no intermediate states are ever returned -- the network is fully unrolled for the given (passed in) length(s) of the sequence(s) or completely unrolled if length(s) is not given.
Args:
cell_fw: An instance of RNNCell, to be used for forward direction.
cell_bw: An instance of RNNCell, to be used for backward direction.
inputs: The RNN inputs.
If time_major == False (default), this must be a tensor of shape:
[batch_size, max_time, input_size]
.
If time_major == True, this must be a tensor of shape:
[max_time, batch_size, input_size]
.
[batch_size, input_size].
sequence_length: An int32/int64 vector, size [batch_size]
,
containing the actual lengths for each of the sequences.
initial_state_fw: (optional) An initial state for the forward RNN.
This must be a tensor of appropriate type and shape
[batch_size, cell_fw.state_size]
.
If cell_fw.state_size
is a tuple, this should be a tuple of
tensors having shapes [batch_size, s] for s in cell_fw.state_size
.
initial_state_bw: (optional) Same as for initial_state_fw
, but using
the corresponding properties of cell_bw
.
dtype: (optional) The data type for the initial states and expected output.
Required if initial_states are not provided or RNN states have a
heterogeneous dtype.
parallel_iterations: (Default: 32). The number of iterations to run in
parallel. Those operations which do not have any temporal dependency
and can be run in parallel, will be. This parameter trades off
time for space. Values >> 1 use more memory but take less time,
while smaller values use less memory but computations take longer.
swap_memory: Transparently swap the tensors produced in forward inference
but needed for back prop from GPU to CPU. This allows training RNNs
which would typically not fit on a single GPU, with very minimal (or no)
performance penalty.
time_major: The shape format of the inputs
and outputs
Tensors.
If true, these Tensors
must be shaped [max_time, batch_size, depth]
.
If false, these Tensors
must be shaped [batch_size, max_time, depth]
.
Using time_major = True
is a bit more efficient because it avoids
transposes at the beginning and end of the RNN calculation. However,
most TensorFlow data is batch-major, so by default this function
accepts input and emits output in batch-major form.
dtype: (optional) The data type for the initial state. Required if
initial_state is not provided.
sequence_length: An int32/int64 vector, size [batch_size]
,
containing the actual lengths for each of the sequences.
either of the initial states are not provided.
scope: VariableScope for the created subgraph; defaults to "BiRNN"
Returns:
A tuple (outputs, output_states) where:
outputs: A tuple (output_fw, output_bw) containing the forward and
the backward rnn output Tensor
.
If time_major == False (default),
output_fw will be a Tensor
shaped:
[batch_size, max_time, cell_fw.output_size]
and output_bw will be a Tensor
shaped:
[batch_size, max_time, cell_bw.output_size]
.
If time_major == True,
output_fw will be a Tensor
shaped:
[max_time, batch_size, cell_fw.output_size]
and output_bw will be a Tensor
shaped:
[max_time, batch_size, cell_bw.output_size]
.
It returns a tuple instead of a single concatenated Tensor
, unlike
in the bidirectional_rnn
. If the concatenated one is preferred,
the forward and backward outputs can be concatenated as
tf.concat(2, outputs)
.
output_states: A tuple (output_state_fw, output_state_bw) containing
the forward and the backward final states of bidirectional rnn.
Raises:
TypeError: If cell_fw
or cell_bw
is not an instance of RNNCell
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bidirectional_dynamic_rnn_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bidirectional_dynamic_rnn_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bidirectional_dynamic_rnn_layer
Return
Applicative
Origial documentation for Builder.bidirectional_dynamic_rnn_layer
def bidirectional_dynamic_rnn_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.bidirectional_dynamic_rnn, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.bidirectional_dynamic_rnn
def bidirectional_dynamic_rnn(cell_fw, cell_bw, inputs, sequence_length=None, initial_state_fw=None, initial_state_bw=None, dtype=None, parallel_iterations=None, swap_memory=False, time_major=False, scope=None):
Creates a dynamic version of bidirectional recurrent neural network.
Similar to the unidirectional case above (rnn) but takes input and builds independent forward and backward RNNs. The input_size of forward and backward cell must match. The initial state for both directions is zero by default (but can be set optionally) and no intermediate states are ever returned -- the network is fully unrolled for the given (passed in) length(s) of the sequence(s) or completely unrolled if length(s) is not given.
Args:
cell_fw: An instance of RNNCell, to be used for forward direction.
cell_bw: An instance of RNNCell, to be used for backward direction.
inputs: The RNN inputs.
If time_major == False (default), this must be a tensor of shape:
[batch_size, max_time, input_size]
.
If time_major == True, this must be a tensor of shape:
[max_time, batch_size, input_size]
.
[batch_size, input_size].
sequence_length: An int32/int64 vector, size [batch_size]
,
containing the actual lengths for each of the sequences.
initial_state_fw: (optional) An initial state for the forward RNN.
This must be a tensor of appropriate type and shape
[batch_size, cell_fw.state_size]
.
If cell_fw.state_size
is a tuple, this should be a tuple of
tensors having shapes [batch_size, s] for s in cell_fw.state_size
.
initial_state_bw: (optional) Same as for initial_state_fw
, but using
the corresponding properties of cell_bw
.
dtype: (optional) The data type for the initial states and expected output.
Required if initial_states are not provided or RNN states have a
heterogeneous dtype.
parallel_iterations: (Default: 32). The number of iterations to run in
parallel. Those operations which do not have any temporal dependency
and can be run in parallel, will be. This parameter trades off
time for space. Values >> 1 use more memory but take less time,
while smaller values use less memory but computations take longer.
swap_memory: Transparently swap the tensors produced in forward inference
but needed for back prop from GPU to CPU. This allows training RNNs
which would typically not fit on a single GPU, with very minimal (or no)
performance penalty.
time_major: The shape format of the inputs
and outputs
Tensors.
If true, these Tensors
must be shaped [max_time, batch_size, depth]
.
If false, these Tensors
must be shaped [batch_size, max_time, depth]
.
Using time_major = True
is a bit more efficient because it avoids
transposes at the beginning and end of the RNN calculation. However,
most TensorFlow data is batch-major, so by default this function
accepts input and emits output in batch-major form.
dtype: (optional) The data type for the initial state. Required if
initial_state is not provided.
sequence_length: An int32/int64 vector, size [batch_size]
,
containing the actual lengths for each of the sequences.
either of the initial states are not provided.
scope: VariableScope for the created subgraph; defaults to "BiRNN"
Returns:
A tuple (outputs, output_states) where:
outputs: A tuple (output_fw, output_bw) containing the forward and
the backward rnn output Tensor
.
If time_major == False (default),
output_fw will be a Tensor
shaped:
[batch_size, max_time, cell_fw.output_size]
and output_bw will be a Tensor
shaped:
[batch_size, max_time, cell_bw.output_size]
.
If time_major == True,
output_fw will be a Tensor
shaped:
[max_time, batch_size, cell_fw.output_size]
and output_bw will be a Tensor
shaped:
[max_time, batch_size, cell_bw.output_size]
.
It returns a tuple instead of a single concatenated Tensor
, unlike
in the bidirectional_rnn
. If the concatenated one is preferred,
the forward and backward outputs can be concatenated as
tf.concat(2, outputs)
.
output_states: A tuple (output_state_fw, output_state_bw) containing
the forward and the backward final states of bidirectional rnn.
Raises:
TypeError: If cell_fw
or cell_bw
is not an instance of RNNCell
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bidirectional_rnn(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bidirectional_rnn, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bidirectional_rnn
Return
Applicative
Origial documentation for Builder.bidirectional_rnn
def bidirectional_rnn(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.nn.bidirectional_rnn
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.nn.bidirectional_rnn
def bidirectional_rnn(cell_fw, cell_bw, inputs, initial_state_fw=None, initial_state_bw=None, dtype=None, sequence_length=None, scope=None)
Creates a bidirectional recurrent neural network.
Similar to the unidirectional case above (rnn) but takes input and builds independent forward and backward RNNs with the final forward and backward outputs depth-concatenated, such that the output will have the format [time][batch][cell_fw.output_size + cell_bw.output_size]. The input_size of forward and backward cell must match. The initial state for both directions is zero by default (but can be set optionally) and no intermediate states are ever returned -- the network is fully unrolled for the given (passed in) length(s) of the sequence(s) or completely unrolled if length(s) is not given.
Args:
cell_fw: An instance of RNNCell, to be used for forward direction.
cell_bw: An instance of RNNCell, to be used for backward direction.
inputs: A length T list of inputs, each a tensor of shape
[batch_size, input_size], or a nested tuple of such elements.
initial_state_fw: (optional) An initial state for the forward RNN.
This must be a tensor of appropriate type and shape
[batch_size, cell_fw.state_size]
.
If cell_fw.state_size
is a tuple, this should be a tuple of
tensors having shapes [batch_size, s] for s in cell_fw.state_size
.
initial_state_bw: (optional) Same as for initial_state_fw
, but using
the corresponding properties of cell_bw
.
dtype: (optional) The data type for the initial state. Required if
either of the initial states are not provided.
sequence_length: (optional) An int32/int64 vector, size [batch_size]
,
containing the actual lengths for each of the sequences.
scope: VariableScope for the created subgraph; defaults to "BiRNN"
Returns:
A tuple (outputs, output_state_fw, output_state_bw) where:
outputs is a length T
list of outputs (one for each input), which
are depth-concatenated forward and backward outputs.
output_state_fw is the final state of the forward rnn.
output_state_bw is the final state of the backward rnn.
Raises:
TypeError: If cell_fw
or cell_bw
is not an instance of RNNCell
.
ValueError: If inputs is None or an empty list.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bidirectional_rnn_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bidirectional_rnn_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bidirectional_rnn_layer
Return
Applicative
Origial documentation for Builder.bidirectional_rnn_layer
def bidirectional_rnn_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.bidirectional_rnn, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.bidirectional_rnn
def bidirectional_rnn(cell_fw, cell_bw, inputs, initial_state_fw=None, initial_state_bw=None, dtype=None, sequence_length=None, scope=None):
Creates a bidirectional recurrent neural network.
Similar to the unidirectional case above (rnn) but takes input and builds independent forward and backward RNNs with the final forward and backward outputs depth-concatenated, such that the output will have the format [time][batch][cell_fw.output_size + cell_bw.output_size]. The input_size of forward and backward cell must match. The initial state for both directions is zero by default (but can be set optionally) and no intermediate states are ever returned -- the network is fully unrolled for the given (passed in) length(s) of the sequence(s) or completely unrolled if length(s) is not given.
Args:
cell_fw: An instance of RNNCell, to be used for forward direction.
cell_bw: An instance of RNNCell, to be used for backward direction.
inputs: A length T list of inputs, each a tensor of shape
[batch_size, input_size], or a nested tuple of such elements.
initial_state_fw: (optional) An initial state for the forward RNN.
This must be a tensor of appropriate type and shape
[batch_size, cell_fw.state_size]
.
If cell_fw.state_size
is a tuple, this should be a tuple of
tensors having shapes [batch_size, s] for s in cell_fw.state_size
.
initial_state_bw: (optional) Same as for initial_state_fw
, but using
the corresponding properties of cell_bw
.
dtype: (optional) The data type for the initial state. Required if
either of the initial states are not provided.
sequence_length: (optional) An int32/int64 vector, size [batch_size]
,
containing the actual lengths for each of the sequences.
scope: VariableScope for the created subgraph; defaults to "BiRNN"
Returns:
A tuple (outputs, output_state_fw, output_state_bw) where:
outputs is a length T
list of outputs (one for each input), which
are depth-concatenated forward and backward outputs.
output_state_fw is the final state of the forward rnn.
output_state_bw is the final state of the backward rnn.
Raises:
TypeError: If cell_fw
or cell_bw
is not an instance of RNNCell
.
ValueError: If inputs is None or an empty list.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bitcast(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bitcast, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bitcast
Return
Applicative
Origial documentation for Builder.bitcast
def bitcast(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.bitcast
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.bitcast
def bitcast(input, type, name=None)
Bitcasts a tensor from one type to another without copying data.
Given a tensor input
, this operation returns a tensor that has the same buffer
data as input
with datatype type
.
If the input datatype T
is larger than the output datatype type
then the
shape changes from [...] to [..., sizeof(T
)/sizeof(type
)].
If T
is smaller than type
, the operator requires that the rightmost
dimension be equal to sizeof(type
)/sizeof(T
). The shape then goes from
[..., sizeof(type
)/sizeof(T
)] to [...].
NOTE: Bitcast is implemented as a low-level cast, so machines with different endian orderings will give different results.
Args:
input: A Tensor
. Must be one of the following types: float32
, float64
, int64
, int32
, uint8
, uint16
, int16
, int8
, complex64
, complex128
, qint8
, quint8
, qint32
, half
.
type: A tf.DType
from: tf.float32, tf.float64, tf.int64, tf.int32, tf.uint8, tf.uint16, tf.int16, tf.int8, tf.complex64, tf.complex128, tf.qint8, tf.quint8, tf.qint32, tf.half
.
name: A name for the operation (optional).
Returns:
A Tensor
of type type
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def bitcast_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.bitcast_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.bitcast_layer
Return
Applicative
Origial documentation for Builder.bitcast_layer
def bitcast_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.bitcast, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.bitcast
def bitcast(input, type, name=None):
Bitcasts a tensor from one type to another without copying data.
Given a tensor input
, this operation returns a tensor that has the same buffer
data as input
with datatype type
.
If the input datatype T
is larger than the output datatype type
then the
shape changes from [...] to [..., sizeof(T
)/sizeof(type
)].
If T
is smaller than type
, the operator requires that the rightmost
dimension be equal to sizeof(type
)/sizeof(T
). The shape then goes from
[..., sizeof(type
)/sizeof(T
)] to [...].
NOTE: Bitcast is implemented as a low-level cast, so machines with different endian orderings will give different results.
Args:
input: A Tensor
. Must be one of the following types: float32
, float64
, int64
, int32
, uint8
, uint16
, int16
, int8
, complex64
, complex128
, qint8
, quint8
, qint32
, half
.
type: A tf.DType
from: tf.float32, tf.float64, tf.int64, tf.int32, tf.uint8, tf.uint16, tf.int16, tf.int8, tf.complex64, tf.complex128, tf.qint8, tf.quint8, tf.qint32, tf.half
.
name: A name for the operation (optional).
Returns:
A Tensor
of type type
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def boolean_mask(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.boolean_mask, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.boolean_mask
Return
Applicative
Origial documentation for Builder.boolean_mask
def boolean_mask(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.boolean_mask
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.boolean_mask
def boolean_mask(tensor, mask, name="boolean_mask")
Apply boolean mask to tensor. Numpy equivalent is tensor[mask]
.
```python
1-D example
tensor = [0, 1, 2, 3] mask = [True, False, True, False] boolean_mask(tensor, mask) ==> [0, 2] ```
In general, 0 < dim(mask) = K <= dim(tensor)
, and mask
's shape must match
the first K dimensions of tensor
's shape. We then have:
boolean_mask(tensor, mask)[i, j1,...,jd] = tensor[i1,...,iK,j1,...,jd]
where (i1,...,iK)
is the ith True
entry of mask
(row-major order).
Args: tensor: N-D tensor. mask: K-D boolean tensor, K <= N and K must be known statically. name: A name for this operation (optional).
Returns:
Tensor populated by entries in tensor
corresponding to True
values in
mask
.
Raises: ValueError: If shapes do not conform.
Examples:
```python
2-D example
tensor = [[1, 2], [3, 4], [5, 6]] mask = [True, False, True] boolean_mask(tensor, mask) ==> [[1, 2], [5, 6]] ```
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def boolean_mask_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.boolean_mask_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.boolean_mask_layer
Return
Applicative
Origial documentation for Builder.boolean_mask_layer
def boolean_mask_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.boolean_mask, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.boolean_mask
def boolean_mask(tensor, mask, name="boolean_mask"):
Apply boolean mask to tensor. Numpy equivalent is tensor[mask]
.
```python
1-D example
tensor = [0, 1, 2, 3] mask = [True, False, True, False] boolean_mask(tensor, mask) ==> [0, 2] ```
In general, 0 < dim(mask) = K <= dim(tensor)
, and mask
's shape must match
the first K dimensions of tensor
's shape. We then have:
boolean_mask(tensor, mask)[i, j1,...,jd] = tensor[i1,...,iK,j1,...,jd]
where (i1,...,iK)
is the ith True
entry of mask
(row-major order).
Args: tensor: N-D tensor. mask: K-D boolean tensor, K <= N and K must be known statically. name: A name for this operation (optional).
Returns:
Tensor populated by entries in tensor
corresponding to True
values in
mask
.
Raises: ValueError: If shapes do not conform.
Examples:
```python
2-D example
tensor = [[1, 2], [3, 4], [5, 6]] mask = [True, False, True] boolean_mask(tensor, mask) ==> [[1, 2], [5, 6]] ```
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def branch(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.branch, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.branch
Return
Applicative
Origial documentation for Builder.branch
def branch(builder, fn):
@immutable
Expects a function fn with type Builder -> iterable( Builder | BuilderTree )
. This method enables you to branch the computational graph so you can easily create neural networks with more complex topologies.
Parameters
fn
: a function of typeBuilder -> iterable( Builder | BuilderTree )
.
Return
tensorbuilder.core.builders.BuilderTree
Examples
import tensorflow as tf from tensorbuilder import tb x = placeholder(tf.float32, shape=[None, 10]) h = ( tb.build(x) .branch(lambda x: [ x.relu_layer(20) , x.sigmoid_layer(20) , x.tanh_layer(20) ]) .softmax_layer(5) .tensor() )
Same with the DSL
import tensorflow as tf from tensorbuilder import tb x = placeholder(tf.float32, shape=[None, 10]) h = tb.pipe( x, [ tb.relu_layer(20) , tb.sigmoid_layer(20) , tb.tanh_layer(20) ], tb.softmax_layer(5) .tensor() )
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def builders(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(BuilderTree.builders, ...)
Arguments
- All other *args and **kwargs are forwarded to
BuilderTree.builders
Return
Applicative
Origial documentation for BuilderTree.builders
def builders(self):
Returns a flattened list tensorbuilder.core.builders.Builder
s contained by this tree. The whole result is flattened in case of sub-elements are also tensorbuilder.core.builders.BuilderTree
s.
Return
list( tensorbuilder.core.builders.Builder )
Examples
This examples creates a network to that solves the XOR problem using sigmoid units
import tensorflow as tf from tensorbuilder import tb x = tf.placeholder(tf.float32, shape=[None, 2]) y = tf.placeholder(tf.float32, shape=[None, 1]) #Network [activation_builder, trainer_builder] = ( tb.build(x) .sigmoid_layer(2) .linear_layer(1) .branch(lambda logit: [ logit.sigmoid() # activation , logit .sigmoid_cross_entropy_with_logits(y) # loss .map(tf.train.AdamOptimizer(0.01).minimize) # trainer ]) .builders() )
Same example using the DSL
import tensorflow as tf from tensorbuilder import tb x = tf.placeholder(tf.float32, shape=[None, 2]) y = tf.placeholder(tf.float32, shape=[None, 1]) #Network [activation_builder, trainer_builder] = tb.pipe( x, tb.sigmoid_layer(2) .linear_layer(1), [ tb.sigmoid() # activation , tb .sigmoid_cross_entropy_with_logits(y) # loss .map(tf.train.AdamOptimizer(0.01).minimize) # trainer ], tb.builders() )
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def case(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.case, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.case
Return
Applicative
Origial documentation for Builder.case
def case(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.case
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.case
def case(pred_fn_pairs, default, exclusive=False, name="case")
Create a case operation.
The pred_fn_pairs
parameter is a dict or list of pairs of size N.
Each pair contains a boolean scalar tensor and a python callable that
creates the tensors to be returned if the boolean evaluates to True.
default
is a callable generating a list of tensors. All the callables
in pred_fn_pairs
as well as default
should return the same number
and types of tensors.
If exclusive==True
, all predicates are evaluated, and a logging operation
with an error is returned if more than one of the predicates evaluates to
True. If exclusive==False
, execution stops are the first predicate which
evaluates to True, and the tensors generated by the corresponding function
are returned immediately. If none of the predicates evaluate to True, this
operation returns the tensors generated by default
.
Example 1:
Pseudocode:
if (x < y) return 17;
else return 23;
Expressions:
f1 = lambda: tf.constant(17)
f2 = lambda: tf.constant(23)
r = case([(tf.less(x, y), f1)], default=f2)
Example 2:
Pseudocode:
if (x < y && x > z) raise OpError("Only one predicate may evaluate true");
if (x < y) return 17;
else if (x > z) return 23;
else return -1;
Expressions:
x = tf.constant(0)
y = tf.constant(1)
z = tf.constant(2)
def f1(): return tf.constant(17)
def f2(): return tf.constant(23)
def f3(): return tf.constant(-1)
r = case({tf.less(x, y): f1, tf.greater(x, z): f2},
default=f3, exclusive=True)
Args: pred_fn_pairs: Dict or list of pairs of a boolean scalar tensor and a callable which returns a list of tensors. default: A callable that returns a list of tensors. exclusive: True iff more than one predicate is allowed to evaluate to True. name: A name for this operation (optional).
Returns:
The tensors returned by the first pair whose predicate evaluated to True, or
those returned by default
if none does.
Raises:
TypeError: If pred_fn_pairs
is not a list/dictionary.
TypeError: If pred_fn_pairs
is a list but does not contain 2-tuples.
TypeError: If fns[i]
is not callable for any i, or default
is not
callable.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def case_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.case_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.case_layer
Return
Applicative
Origial documentation for Builder.case_layer
def case_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.case, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.case
def case(pred_fn_pairs, default, exclusive=False, name="case"):
Create a case operation.
The pred_fn_pairs
parameter is a dict or list of pairs of size N.
Each pair contains a boolean scalar tensor and a python callable that
creates the tensors to be returned if the boolean evaluates to True.
default
is a callable generating a list of tensors. All the callables
in pred_fn_pairs
as well as default
should return the same number
and types of tensors.
If exclusive==True
, all predicates are evaluated, and a logging operation
with an error is returned if more than one of the predicates evaluates to
True. If exclusive==False
, execution stops are the first predicate which
evaluates to True, and the tensors generated by the corresponding function
are returned immediately. If none of the predicates evaluate to True, this
operation returns the tensors generated by default
.
Example 1:
Pseudocode:
if (x < y) return 17;
else return 23;
Expressions:
f1 = lambda: tf.constant(17)
f2 = lambda: tf.constant(23)
r = case([(tf.less(x, y), f1)], default=f2)
Example 2:
Pseudocode:
if (x < y && x > z) raise OpError("Only one predicate may evaluate true");
if (x < y) return 17;
else if (x > z) return 23;
else return -1;
Expressions:
x = tf.constant(0)
y = tf.constant(1)
z = tf.constant(2)
def f1(): return tf.constant(17)
def f2(): return tf.constant(23)
def f3(): return tf.constant(-1)
r = case({tf.less(x, y): f1, tf.greater(x, z): f2},
default=f3, exclusive=True)
Args: pred_fn_pairs: Dict or list of pairs of a boolean scalar tensor and a callable which returns a list of tensors. default: A callable that returns a list of tensors. exclusive: True iff more than one predicate is allowed to evaluate to True. name: A name for this operation (optional).
Returns:
The tensors returned by the first pair whose predicate evaluated to True, or
those returned by default
if none does.
Raises:
TypeError: If pred_fn_pairs
is not a list/dictionary.
TypeError: If pred_fn_pairs
is a list but does not contain 2-tuples.
TypeError: If fns[i]
is not callable for any i, or default
is not
callable.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def cast(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.cast, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.cast
Return
Applicative
Origial documentation for Builder.cast
def cast(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.cast
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.cast
def cast(x, dtype, name=None)
Casts a tensor to a new type.
The operation casts x
(in case of Tensor
) or x.values
(in case of SparseTensor
) to dtype
.
For example:
```python
tensor a
is [1.8, 2.2], dtype=tf.float
tf.cast(a, tf.int32) ==> [1, 2] # dtype=tf.int32 ```
Args:
x: A Tensor
or SparseTensor
.
dtype: The destination type.
name: A name for the operation (optional).
Returns:
A Tensor
or SparseTensor
with same shape as x
.
Raises:
TypeError: If x
cannot be cast to the dtype
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def cast_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.cast_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.cast_layer
Return
Applicative
Origial documentation for Builder.cast_layer
def cast_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.cast, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.cast
def cast(x, dtype, name=None):
Casts a tensor to a new type.
The operation casts x
(in case of Tensor
) or x.values
(in case of SparseTensor
) to dtype
.
For example:
```python
tensor a
is [1.8, 2.2], dtype=tf.float
tf.cast(a, tf.int32) ==> [1, 2] # dtype=tf.int32 ```
Args:
x: A Tensor
or SparseTensor
.
dtype: The destination type.
name: A name for the operation (optional).
Returns:
A Tensor
or SparseTensor
with same shape as x
.
Raises:
TypeError: If x
cannot be cast to the dtype
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def ceil(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.ceil, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.ceil
Return
Applicative
Origial documentation for Builder.ceil
def ceil(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.ceil
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.ceil
def ceil(x, name=None)
Returns element-wise smallest integer in not less than x.
Args:
x: A Tensor
. Must be one of the following types: half
, float32
, float64
.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as x
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def ceil_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.ceil_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.ceil_layer
Return
Applicative
Origial documentation for Builder.ceil_layer
def ceil_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.ceil, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.ceil
def ceil(x, name=None):
Returns element-wise smallest integer in not less than x.
Args:
x: A Tensor
. Must be one of the following types: half
, float32
, float64
.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as x
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def check_numerics(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.check_numerics, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.check_numerics
Return
Applicative
Origial documentation for Builder.check_numerics
def check_numerics(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.check_numerics
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.check_numerics
def check_numerics(tensor, message, name=None)
Checks a tensor for NaN and Inf values.
When run, reports an InvalidArgument
error if tensor
has any values
that are not a number (NaN) or infinity (Inf). Otherwise, passes tensor
as-is.
Args:
tensor: A Tensor
. Must be one of the following types: half
, float32
, float64
.
message: A string
. Prefix of the error message.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as tensor
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def check_numerics_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.check_numerics_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.check_numerics_layer
Return
Applicative
Origial documentation for Builder.check_numerics_layer
def check_numerics_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.check_numerics, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.check_numerics
def check_numerics(tensor, message, name=None):
Checks a tensor for NaN and Inf values.
When run, reports an InvalidArgument
error if tensor
has any values
that are not a number (NaN) or infinity (Inf). Otherwise, passes tensor
as-is.
Args:
tensor: A Tensor
. Must be one of the following types: half
, float32
, float64
.
message: A string
. Prefix of the error message.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as tensor
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def cholesky(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.cholesky, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.cholesky
Return
Applicative
Origial documentation for Builder.cholesky
def cholesky(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.cholesky
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.cholesky
def cholesky(input, name=None)
Computes the Cholesky decomposition of one or more square matrices.
The input is a tensor of shape [..., M, M]
whose inner-most 2 dimensions
form square matrices, with the same constraints as the single matrix Cholesky
decomposition above. The output is a tensor of the same shape as the input
containing the Cholesky decompositions for all input submatrices [..., :, :]
.
Args:
input: A Tensor
. Must be one of the following types: float64
, float32
.
Shape is [..., M, M]
.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as input
. Shape is [..., M, M]
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def cholesky_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.cholesky_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.cholesky_layer
Return
Applicative
Origial documentation for Builder.cholesky_layer
def cholesky_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.cholesky, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.cholesky
def cholesky(input, name=None):
Computes the Cholesky decomposition of one or more square matrices.
The input is a tensor of shape [..., M, M]
whose inner-most 2 dimensions
form square matrices, with the same constraints as the single matrix Cholesky
decomposition above. The output is a tensor of the same shape as the input
containing the Cholesky decompositions for all input submatrices [..., :, :]
.
Args:
input: A Tensor
. Must be one of the following types: float64
, float32
.
Shape is [..., M, M]
.
name: A name for the operation (optional).
Returns:
A Tensor
. Has the same type as input
. Shape is [..., M, M]
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def cholesky_solve(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.cholesky_solve, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.cholesky_solve
Return
Applicative
Origial documentation for Builder.cholesky_solve
def cholesky_solve(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.cholesky_solve
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.cholesky_solve
def cholesky_solve(chol, rhs, name=None)
Solves systems of linear eqns A X = RHS
, given Cholesky factorizations.
```python
Solve 10 separate 2x2 linear systems:
A = ... # shape 10 x 2 x 2 RHS = ... # shape 10 x 2 x 1 chol = tf.cholesky(A) # shape 10 x 2 x 2 X = tf.cholesky_solve(chol, RHS) # shape 10 x 2 x 1
tf.matmul(A, X) ~ RHS
X[3, :, 0] # Solution to the linear system A[3, :, :] x = RHS[3, :, 0]
Solve five linear systems (K = 5) for every member of the length 10 batch.
A = ... # shape 10 x 2 x 2 RHS = ... # shape 10 x 2 x 5 ... X[3, :, 2] # Solution to the linear system A[3, :, :] x = RHS[3, :, 2] ```
Args:
chol: A Tensor
. Must be float32
or float64
, shape is [..., M, M]
.
Cholesky factorization of A
, e.g. chol = tf.cholesky(A)
.
For that reason, only the lower triangular parts (including the diagonal)
of the last two dimensions of chol
are used. The strictly upper part is
assumed to be zero and not accessed.
rhs: A Tensor
, same type as chol
, shape is [..., M, K]
.
name: A name to give this Op
. Defaults to cholesky_solve
.
Returns:
Solution to A x = rhs
, shape [..., M, K]
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def cholesky_solve_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.cholesky_solve_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.cholesky_solve_layer
Return
Applicative
Origial documentation for Builder.cholesky_solve_layer
def cholesky_solve_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.cholesky_solve, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.cholesky_solve
def cholesky_solve(chol, rhs, name=None):
Solves systems of linear eqns A X = RHS
, given Cholesky factorizations.
```python
Solve 10 separate 2x2 linear systems:
A = ... # shape 10 x 2 x 2 RHS = ... # shape 10 x 2 x 1 chol = tf.cholesky(A) # shape 10 x 2 x 2 X = tf.cholesky_solve(chol, RHS) # shape 10 x 2 x 1
tf.matmul(A, X) ~ RHS
X[3, :, 0] # Solution to the linear system A[3, :, :] x = RHS[3, :, 0]
Solve five linear systems (K = 5) for every member of the length 10 batch.
A = ... # shape 10 x 2 x 2 RHS = ... # shape 10 x 2 x 5 ... X[3, :, 2] # Solution to the linear system A[3, :, :] x = RHS[3, :, 2] ```
Args:
chol: A Tensor
. Must be float32
or float64
, shape is [..., M, M]
.
Cholesky factorization of A
, e.g. chol = tf.cholesky(A)
.
For that reason, only the lower triangular parts (including the diagonal)
of the last two dimensions of chol
are used. The strictly upper part is
assumed to be zero and not accessed.
rhs: A Tensor
, same type as chol
, shape is [..., M, K]
.
name: A name to give this Op
. Defaults to cholesky_solve
.
Returns:
Solution to A x = rhs
, shape [..., M, K]
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def clip_by_average_norm(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.clip_by_average_norm, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.clip_by_average_norm
Return
Applicative
Origial documentation for Builder.clip_by_average_norm
def clip_by_average_norm(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.clip_by_average_norm
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.clip_by_average_norm
def clip_by_average_norm(t, clip_norm, name=None)
Clips tensor values to a maximum average L2-norm.
Given a tensor t
, and a maximum clip value clip_norm
, this operation
normalizes t
so that its average L2-norm is less than or equal to
clip_norm
. Specifically, if the average L2-norm is already less than or
equal to clip_norm
, then t
is not modified. If the average L2-norm is
greater than clip_norm
, then this operation returns a tensor of the same
type and shape as t
with its values set to:
t * clip_norm / l2norm_avg(t)
In this case, the average L2-norm of the output tensor is clip_norm
.
This operation is typically used to clip gradients before applying them with an optimizer.
Args:
t: A Tensor
.
clip_norm: A 0-D (scalar) Tensor
> 0. A maximum clipping value.
name: A name for the operation (optional).
Returns:
A clipped Tensor
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def clip_by_average_norm_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.clip_by_average_norm_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.clip_by_average_norm_layer
Return
Applicative
Origial documentation for Builder.clip_by_average_norm_layer
def clip_by_average_norm_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.clip_by_average_norm, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.clip_by_average_norm
def clip_by_average_norm(t, clip_norm, name=None):
Clips tensor values to a maximum average L2-norm.
Given a tensor t
, and a maximum clip value clip_norm
, this operation
normalizes t
so that its average L2-norm is less than or equal to
clip_norm
. Specifically, if the average L2-norm is already less than or
equal to clip_norm
, then t
is not modified. If the average L2-norm is
greater than clip_norm
, then this operation returns a tensor of the same
type and shape as t
with its values set to:
t * clip_norm / l2norm_avg(t)
In this case, the average L2-norm of the output tensor is clip_norm
.
This operation is typically used to clip gradients before applying them with an optimizer.
Args:
t: A Tensor
.
clip_norm: A 0-D (scalar) Tensor
> 0. A maximum clipping value.
name: A name for the operation (optional).
Returns:
A clipped Tensor
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def clip_by_global_norm(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.clip_by_global_norm, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.clip_by_global_norm
Return
Applicative
Origial documentation for Builder.clip_by_global_norm
def clip_by_global_norm(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.clip_by_global_norm
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.clip_by_global_norm
def clip_by_global_norm(t_list, clip_norm, use_norm=None, name=None)
Clips values of multiple tensors by the ratio of the sum of their norms.
Given a tuple or list of tensors t_list
, and a clipping ratio clip_norm
,
this operation returns a list of clipped tensors list_clipped
and the global norm (global_norm
) of all tensors in t_list
. Optionally,
if you've already computed the global norm for t_list
, you can specify
the global norm with use_norm
.
To perform the clipping, the values t_list[i]
are set to:
t_list[i] * clip_norm / max(global_norm, clip_norm)
where:
global_norm = sqrt(sum([l2norm(t)**2 for t in t_list]))
If clip_norm > global_norm
then the entries in t_list
remain as they are,
otherwise they're all shrunk by the global ratio.
Any of the entries of t_list
that are of type None
are ignored.
This is the correct way to perform gradient clipping (for example, see Pascanu et al., 2012 (pdf)).
However, it is slower than clip_by_norm()
because all the parameters must be
ready before the clipping operation can be performed.
Args:
t_list: A tuple or list of mixed Tensors
, IndexedSlices
, or None.
clip_norm: A 0-D (scalar) Tensor
> 0. The clipping ratio.
use_norm: A 0-D (scalar) Tensor
of type float
(optional). The global
norm to use. If not provided, global_norm()
is used to compute the norm.
name: A name for the operation (optional).
Returns:
list_clipped: A list of Tensors
of the same type as list_t
.
global_norm: A 0-D (scalar) Tensor
representing the global norm.
Raises:
TypeError: If t_list
is not a sequence.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def clip_by_global_norm_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.clip_by_global_norm_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.clip_by_global_norm_layer
Return
Applicative
Origial documentation for Builder.clip_by_global_norm_layer
def clip_by_global_norm_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.clip_by_global_norm, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.clip_by_global_norm
def clip_by_global_norm(t_list, clip_norm, use_norm=None, name=None):
Clips values of multiple tensors by the ratio of the sum of their norms.
Given a tuple or list of tensors t_list
, and a clipping ratio clip_norm
,
this operation returns a list of clipped tensors list_clipped
and the global norm (global_norm
) of all tensors in t_list
. Optionally,
if you've already computed the global norm for t_list
, you can specify
the global norm with use_norm
.
To perform the clipping, the values t_list[i]
are set to:
t_list[i] * clip_norm / max(global_norm, clip_norm)
where:
global_norm = sqrt(sum([l2norm(t)**2 for t in t_list]))
If clip_norm > global_norm
then the entries in t_list
remain as they are,
otherwise they're all shrunk by the global ratio.
Any of the entries of t_list
that are of type None
are ignored.
This is the correct way to perform gradient clipping (for example, see Pascanu et al., 2012 (pdf)).
However, it is slower than clip_by_norm()
because all the parameters must be
ready before the clipping operation can be performed.
Args:
t_list: A tuple or list of mixed Tensors
, IndexedSlices
, or None.
clip_norm: A 0-D (scalar) Tensor
> 0. The clipping ratio.
use_norm: A 0-D (scalar) Tensor
of type float
(optional). The global
norm to use. If not provided, global_norm()
is used to compute the norm.
name: A name for the operation (optional).
Returns:
list_clipped: A list of Tensors
of the same type as list_t
.
global_norm: A 0-D (scalar) Tensor
representing the global norm.
Raises:
TypeError: If t_list
is not a sequence.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def clip_by_norm(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.clip_by_norm, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.clip_by_norm
Return
Applicative
Origial documentation for Builder.clip_by_norm
def clip_by_norm(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.clip_by_norm
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.clip_by_norm
def clip_by_norm(t, clip_norm, axes=None, name=None)
Clips tensor values to a maximum L2-norm.
Given a tensor t
, and a maximum clip value clip_norm
, this operation
normalizes t
so that its L2-norm is less than or equal to clip_norm
,
along the dimensions given in axes
. Specifically, in the default case
where all dimensions are used for calculation, if the L2-norm of t
is
already less than or equal to clip_norm
, then t
is not modified. If
the L2-norm is greater than clip_norm
, then this operation returns a
tensor of the same type and shape as t
with its values set to:
t * clip_norm / l2norm(t)
In this case, the L2-norm of the output tensor is clip_norm
.
As another example, if t
is a matrix and axes == [1]
, then each row
of the output will have L2-norm equal to clip_norm
. If axes == [0]
instead, each column of the output will be clipped.
This operation is typically used to clip gradients before applying them with an optimizer.
Args:
t: A Tensor
.
clip_norm: A 0-D (scalar) Tensor
> 0. A maximum clipping value.
axes: A 1-D (vector) Tensor
of type int32 containing the dimensions
to use for computing the L2-norm. If None
(the default), uses all
dimensions.
name: A name for the operation (optional).
Returns:
A clipped Tensor
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def clip_by_norm_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.clip_by_norm_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.clip_by_norm_layer
Return
Applicative
Origial documentation for Builder.clip_by_norm_layer
def clip_by_norm_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.clip_by_norm, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.clip_by_norm
def clip_by_norm(t, clip_norm, axes=None, name=None):
Clips tensor values to a maximum L2-norm.
Given a tensor t
, and a maximum clip value clip_norm
, this operation
normalizes t
so that its L2-norm is less than or equal to clip_norm
,
along the dimensions given in axes
. Specifically, in the default case
where all dimensions are used for calculation, if the L2-norm of t
is
already less than or equal to clip_norm
, then t
is not modified. If
the L2-norm is greater than clip_norm
, then this operation returns a
tensor of the same type and shape as t
with its values set to:
t * clip_norm / l2norm(t)
In this case, the L2-norm of the output tensor is clip_norm
.
As another example, if t
is a matrix and axes == [1]
, then each row
of the output will have L2-norm equal to clip_norm
. If axes == [0]
instead, each column of the output will be clipped.
This operation is typically used to clip gradients before applying them with an optimizer.
Args:
t: A Tensor
.
clip_norm: A 0-D (scalar) Tensor
> 0. A maximum clipping value.
axes: A 1-D (vector) Tensor
of type int32 containing the dimensions
to use for computing the L2-norm. If None
(the default), uses all
dimensions.
name: A name for the operation (optional).
Returns:
A clipped Tensor
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def clip_by_value(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.clip_by_value, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.clip_by_value
Return
Applicative
Origial documentation for Builder.clip_by_value
def clip_by_value(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.clip_by_value
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.clip_by_value
def clip_by_value(t, clip_value_min, clip_value_max, name=None)
Clips tensor values to a specified min and max.
Given a tensor t
, this operation returns a tensor of the same type and
shape as t
with its values clipped to clip_value_min
and clip_value_max
.
Any values less than clip_value_min
are set to clip_value_min
. Any values
greater than clip_value_max
are set to clip_value_max
.
Args:
t: A Tensor
.
clip_value_min: A 0-D (scalar) Tensor
. The minimum value to clip by.
clip_value_max: A 0-D (scalar) Tensor
. The maximum value to clip by.
name: A name for the operation (optional).
Returns:
A clipped Tensor
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def clip_by_value_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.clip_by_value_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.clip_by_value_layer
Return
Applicative
Origial documentation for Builder.clip_by_value_layer
def clip_by_value_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.clip_by_value, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.clip_by_value
def clip_by_value(t, clip_value_min, clip_value_max, name=None):
Clips tensor values to a specified min and max.
Given a tensor t
, this operation returns a tensor of the same type and
shape as t
with its values clipped to clip_value_min
and clip_value_max
.
Any values less than clip_value_min
are set to clip_value_min
. Any values
greater than clip_value_max
are set to clip_value_max
.
Args:
t: A Tensor
.
clip_value_min: A 0-D (scalar) Tensor
. The minimum value to clip by.
clip_value_max: A 0-D (scalar) Tensor
. The maximum value to clip by.
name: A name for the operation (optional).
Returns:
A clipped Tensor
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def compile(
self, *ast)
compile
an object ast
which must be part of the domain of the DSL and returns function. It applies the rules of the DSL to create an actual Python function that does what you intend. Normally you will just use pipe, which not only compiles the DSL it actually performs the computation to a given Tensor/Builder, however, it you are building and API this might be useful since you can create a function from an AST which can itself be used as an element of another AST since final elements of the DSL are functions.
Arguments
*ast
: a sequence of elements of the DSL.
Return
A function
Examples
import tensorflow as tf from tensorbuilder import tb x = placeholder(tf.float32, shape=[None, 10]) f = tb.compile( tb.build, #accept a Tensor as a parameter and create a builder so you can use the rest of the methods [ { tf.device("/gpu:0"): tb.relu_layer(20) } , { tf.device("/gpu:1"): tb.sigmoid_layer(20) } , { tf.device("/cpu:0"): tb.tanh_layer(20) } ], tb.relu_layer(10) .tensor() ) h = f(x)
def compile(self, *ast): """ `compile` an object `ast` which must be part of the domain of the DSL and returns function. It applies the rules of the DSL to create an actual Python function that does what you intend. Normally you will just use pipe, which not only compiles the DSL it actually performs the computation to a given Tensor/Builder, however, it you are building and API this might be useful since you can create a function from an AST which can itself be used as an element of another AST since final elements of the DSL are functions. **Arguments** * `*ast`: a sequence of elements of the DSL. **Return** A function **Examples** import tensorflow as tf from tensorbuilder import tb x = placeholder(tf.float32, shape=[None, 10]) f = tb.compile( tb.build, #accept a Tensor as a parameter and create a builder so you can use the rest of the methods [ { tf.device("/gpu:0"): tb.relu_layer(20) } , { tf.device("/gpu:1"): tb.sigmoid_layer(20) } , { tf.device("/cpu:0"): tb.tanh_layer(20) } ], tb.relu_layer(10) .tensor() ) h = f(x) """ return _compile(ast)
def complex(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.complex, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.complex
Return
Applicative
Origial documentation for Builder.complex
def complex(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.complex
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.complex
def complex(real, imag, name=None)
Converts two real numbers to a complex number.
Given a tensor real
representing the real part of a complex number, and a
tensor imag
representing the imaginary part of a complex number, this
operation returns complex numbers elementwise of the form (a + bj), where
a represents the real
part and b represents the imag
part.
The input tensors real
and imag
must have the same shape.
For example:
```
tensor 'real' is [2.25, 3.25]
tensor imag
is [4.75, 5.75]
tf.complex(real, imag) ==> [[2.25 + 4.75j], [3.25 + 5.75j]] ```
Args:
real: A Tensor
. Must be one of the following types: float32
, float64
.
imag: A Tensor
. Must have the same type as real
.
name: A name for the operation (optional).
Returns:
A Tensor
of type complex64
or complex128
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def complex_abs(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.complex_abs, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.complex_abs
Return
Applicative
Origial documentation for Builder.complex_abs
def complex_abs(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.complex_abs
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.complex_abs
def complex_abs(x, name=None)
Computes the complex absolute value of a tensor.
Given a tensor x
of complex numbers, this operation returns a tensor of type
float32
or float64
that is the absolute value of each element in x
. All
elements in x
must be complex numbers of the form \(a + bj\). The
absolute value is computed as \( \sqrt{a^2 + b^2}\).
For example:
```
tensor 'x' is [[-2.25 + 4.75j], [-3.25 + 5.75j]]
tf.complex_abs(x) ==> [5.25594902, 6.60492229] ```
Args:
x: A Tensor
of type complex64
or complex128
.
name: A name for the operation (optional).
Returns:
A Tensor
of type float32
or float64
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def complex_abs_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.complex_abs_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.complex_abs_layer
Return
Applicative
Origial documentation for Builder.complex_abs_layer
def complex_abs_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.complex_abs, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.complex_abs
def complex_abs(x, name=None):
Computes the complex absolute value of a tensor.
Given a tensor x
of complex numbers, this operation returns a tensor of type
float32
or float64
that is the absolute value of each element in x
. All
elements in x
must be complex numbers of the form \(a + bj\). The
absolute value is computed as \( \sqrt{a^2 + b^2}\).
For example:
```
tensor 'x' is [[-2.25 + 4.75j], [-3.25 + 5.75j]]
tf.complex_abs(x) ==> [5.25594902, 6.60492229] ```
Args:
x: A Tensor
of type complex64
or complex128
.
name: A name for the operation (optional).
Returns:
A Tensor
of type float32
or float64
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def complex_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.complex_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.complex_layer
Return
Applicative
Origial documentation for Builder.complex_layer
def complex_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.complex, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.complex
def complex(real, imag, name=None):
Converts two real numbers to a complex number.
Given a tensor real
representing the real part of a complex number, and a
tensor imag
representing the imaginary part of a complex number, this
operation returns complex numbers elementwise of the form (a + bj), where
a represents the real
part and b represents the imag
part.
The input tensors real
and imag
must have the same shape.
For example:
```
tensor 'real' is [2.25, 3.25]
tensor imag
is [4.75, 5.75]
tf.complex(real, imag) ==> [[2.25 + 4.75j], [3.25 + 5.75j]] ```
Args:
real: A Tensor
. Must be one of the following types: float32
, float64
.
imag: A Tensor
. Must have the same type as real
.
name: A name for the operation (optional).
Returns:
A Tensor
of type complex64
or complex128
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def compose(
app, g, *args, **kwargs)
Takes in a function g
and composes it with tensorbuilder.core.Applicative.f
as g o f
. All *args and ** are forwarded to g. This is an essential method since most registered methods use this.
Arguments
g
: A function- All *args and ** are forwarded to
g
Return
Applicative
Examples
import tensorflow as tf from tensorbuilder import tb
def compose(app, g, *args, **kwargs): """ Takes in a function `g` and composes it with `tensorbuilder.core.Applicative.f` as `g o f`. All \*args and \*\* are forwarded to g. This is an essential method since most registered methods use this. **Arguments** * `g`: A function * All \*args and \*\* are forwarded to `g` **Return** Applicative **Examples** import tensorflow as tf from tensorbuilder import tb """ return app._unit(lambda x: g(app.f(x), *args, **kwargs))
def compute_accidental_hits(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.compute_accidental_hits, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.compute_accidental_hits
Return
Applicative
Origial documentation for Builder.compute_accidental_hits
def compute_accidental_hits(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.nn.compute_accidental_hits
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.nn.compute_accidental_hits
def compute_accidental_hits(true_classes, sampled_candidates, num_true, seed=None, name=None)
Compute the position ids in sampled_candidates
matching true_classes
.
In Candidate Sampling, this operation facilitates virtually removing sampled classes which happen to match target classes. This is done in Sampled Softmax and Sampled Logistic.
See our Candidate Sampling Algorithms Reference.
We presuppose that the sampled_candidates
are unique.
We call it an 'accidental hit' when one of the target classes
matches one of the sampled classes. This operation reports
accidental hits as triples (index, id, weight)
, where index
represents the row number in true_classes
, id
represents the
position in sampled_candidates
, and weight is -FLOAT_MAX
.
The result of this op should be passed through a sparse_to_dense
operation, then added to the logits of the sampled classes. This
removes the contradictory effect of accidentally sampling the true
target classes as noise classes for the same example.
Args:
true_classes: A Tensor
of type int64
and shape [batch_size,
num_true]
. The target classes.
sampled_candidates: A tensor of type int64
and shape [num_sampled]
.
The sampled_candidates output of CandidateSampler.
num_true: An int
. The number of target classes per training example.
seed: An int
. An operation-specific seed. Default is 0.
name: A name for the operation (optional).
Returns:
indices: A Tensor
of type int32
and shape [num_accidental_hits]
.
Values indicate rows in true_classes
.
ids: A Tensor
of type int64
and shape [num_accidental_hits]
.
Values indicate positions in sampled_candidates
.
weights: A Tensor
of type float
and shape [num_accidental_hits]
.
Each value is -FLOAT_MAX
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def compute_accidental_hits_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.compute_accidental_hits_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.compute_accidental_hits_layer
Return
Applicative
Origial documentation for Builder.compute_accidental_hits_layer
def compute_accidental_hits_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.nn.compute_accidental_hits, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.nn.compute_accidental_hits
def compute_accidental_hits(true_classes, sampled_candidates, num_true, seed=None, name=None):
Compute the position ids in sampled_candidates
matching true_classes
.
In Candidate Sampling, this operation facilitates virtually removing sampled classes which happen to match target classes. This is done in Sampled Softmax and Sampled Logistic.
See our Candidate Sampling Algorithms Reference.
We presuppose that the sampled_candidates
are unique.
We call it an 'accidental hit' when one of the target classes
matches one of the sampled classes. This operation reports
accidental hits as triples (index, id, weight)
, where index
represents the row number in true_classes
, id
represents the
position in sampled_candidates
, and weight is -FLOAT_MAX
.
The result of this op should be passed through a sparse_to_dense
operation, then added to the logits of the sampled classes. This
removes the contradictory effect of accidentally sampling the true
target classes as noise classes for the same example.
Args:
true_classes: A Tensor
of type int64
and shape [batch_size,
num_true]
. The target classes.
sampled_candidates: A tensor of type int64
and shape [num_sampled]
.
The sampled_candidates output of CandidateSampler.
num_true: An int
. The number of target classes per training example.
seed: An int
. An operation-specific seed. Default is 0.
name: A name for the operation (optional).
Returns:
indices: A Tensor
of type int32
and shape [num_accidental_hits]
.
Values indicate rows in true_classes
.
ids: A Tensor
of type int64
and shape [num_accidental_hits]
.
Values indicate positions in sampled_candidates
.
weights: A Tensor
of type float
and shape [num_accidental_hits]
.
Each value is -FLOAT_MAX
.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def concat(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.concat, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.concat
Return
Applicative
Origial documentation for Builder.concat
def concat(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.concat
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.concat
def concat(concat_dim, values, name="concat")
Concatenates tensors along one dimension.
Concatenates the list of tensors values
along dimension concat_dim
. If
values[i].shape = [D0, D1, ... Dconcat_dim(i), ...Dn]
, the concatenated
result has shape
[D0, D1, ... Rconcat_dim, ...Dn]
where
Rconcat_dim = sum(Dconcat_dim(i))
That is, the data from the input tensors is joined along the concat_dim
dimension.
The number of dimensions of the input tensors must match, and all dimensions
except concat_dim
must be equal.
For example:
```python t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, 8, 9], [10, 11, 12]] tf.concat(0, [t1, t2]) ==> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] tf.concat(1, [t1, t2]) ==> [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]]
tensor t3 with shape [2, 3]
tensor t4 with shape [2, 3]
tf.shape(tf.concat(0, [t3, t4])) ==> [4, 3] tf.shape(tf.concat(1, [t3, t4])) ==> [2, 6] ```
Note: If you are concatenating along a new axis consider using pack. E.g.
python
tf.concat(axis, [tf.expand_dims(t, axis) for t in tensors])
can be rewritten as
python
tf.pack(tensors, axis=axis)
Args:
concat_dim: 0-D int32
Tensor
. Dimension along which to concatenate.
values: A list of Tensor
objects or a single Tensor
.
name: A name for the operation (optional).
Returns:
A Tensor
resulting from concatenation of the input tensors.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def concat_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.concat_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.concat_layer
Return
Applicative
Origial documentation for Builder.concat_layer
def concat_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.concat, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.concat
def concat(concat_dim, values, name="concat"):
Concatenates tensors along one dimension.
Concatenates the list of tensors values
along dimension concat_dim
. If
values[i].shape = [D0, D1, ... Dconcat_dim(i), ...Dn]
, the concatenated
result has shape
[D0, D1, ... Rconcat_dim, ...Dn]
where
Rconcat_dim = sum(Dconcat_dim(i))
That is, the data from the input tensors is joined along the concat_dim
dimension.
The number of dimensions of the input tensors must match, and all dimensions
except concat_dim
must be equal.
For example:
```python t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, 8, 9], [10, 11, 12]] tf.concat(0, [t1, t2]) ==> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] tf.concat(1, [t1, t2]) ==> [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]]
tensor t3 with shape [2, 3]
tensor t4 with shape [2, 3]
tf.shape(tf.concat(0, [t3, t4])) ==> [4, 3] tf.shape(tf.concat(1, [t3, t4])) ==> [2, 6] ```
Note: If you are concatenating along a new axis consider using pack. E.g.
python
tf.concat(axis, [tf.expand_dims(t, axis) for t in tensors])
can be rewritten as
python
tf.pack(tensors, axis=axis)
Args:
concat_dim: 0-D int32
Tensor
. Dimension along which to concatenate.
values: A list of Tensor
objects or a single Tensor
.
name: A name for the operation (optional).
Returns:
A Tensor
resulting from concatenation of the input tensors.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def cond(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.cond, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.cond
Return
Applicative
Origial documentation for Builder.cond
def cond(builder):
THIS METHOD IS AUTOMATICALLY GENERATED
@immutable
This method is a lifted version the function tf.cond
to work with tensorbuilder.core.builders.Builder
s. Instead of taking a Tensor as its first argument it takes a builder, the rest of the arguments are exactly the same.
Original Documentation for tf.cond
def cond(pred, fn1, fn2, name=None)
Return either fn1() or fn2() based on the boolean predicate pred
.
fn1
and fn2
both return lists of output tensors. fn1
and fn2
must have
the same non-zero number and type of outputs.
Note that the conditional execution applies only to the operations defined in fn1 and fn2. Consider the following simple program:
python
z = tf.mul(a, b)
result = tf.cond(x < y, lambda: tf.add(x, z), lambda: tf.square(y))
If x < y, the tf.add operation will be executed and tf.square operation will not be executed. Since z is needed for at least one branch of the cond, the tf.mul operation is always executed, unconditionally. Although this behavior is consistent with the dataflow model of TensorFlow, it has occasionally surprised some users who expected a lazier semantics.
Args:
pred: A scalar determining whether to return the result of fn1
or fn2
.
fn1: The callable to be performed if pred is true.
fn2: The callable to be performed if pref is false.
name: Optional name prefix for the returned tensors.
Returns:
Tensors returned by the call to either fn1
or fn2
. If the callables
return a singleton list, the element is extracted from the list.
Raises:
TypeError: if fn1
or fn2
is not callable.
ValueError: if fn1
and fn2
do not return the same number of tensors, or
return tensors of different types.
Example:
python
x = tf.constant(2)
y = tf.constant(5)
def f1(): return tf.mul(x, 17)
def f2(): return tf.add(y, 23)
r = cond(tf.less(x, y), f1, f2)
# r is set to f1().
# Operations in f2 (e.g., tf.add) are not executed.
def _method(app, *args, **kwargs): def _lambda(builder): g = getattr(builder, f.__name__) return g(*args, **kwargs) return app.compose(_lambda)
def cond_layer(
app, *args, **kwargs)
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .compose(Builder.cond_layer, ...)
Arguments
- All other *args and **kwargs are forwarded to
Builder.cond_layer
Return
Applicative
Origial documentation for Builder.cond_layer
def cond_layer(builder, size):
THIS METHOD IS AUTOMATICALLY GENERATED
Alias for .fully_connected(size, activation_fn = tf.cond, ...)
Arguments
size
: the size of the resulting layer- All other *args and **kwargs are forwarded to
tf.contrib.layers.fully_connected
Return
Builder
Origial documentation for tf.cond
def cond(pred, fn1, fn2, name=None):