Tensorflow Utilities
General tensorflow utilities.
Custom tensorflow modules
Simple general tensorflow operations (e.g.
reduced_batched_outer_product()
)tensorboard utilities
- class tf_utils.BiasedDense(input_dim, output_size, name=None, activation=<function relu>, stddev=0.001)
Bases:
tensorflow.python.module.module.Module
Biased dense layer,
y = W * f(x) + b
- Parameters
input_dim (int) – dimension of the layer’s input
output_size (int) – dimension of the layer’s output
name (str, optional) – custom name for the layer, defaults to None
activation (function, optional) – activation function, defaults to tf.nn.relu
stddev (float, optional) – standard deviation of the normal initialization, defaults to .001
- class tf_utils.Dense(input_dim, output_size, name=None, activation=<function relu>, stddev=0.001)
Bases:
tensorflow.python.module.module.Module
Unbiased dense layer,
y = W * f(x)
- Parameters
input_dim (int) – dimension of the layer’s input
output_size (int) – dimension of the layer’s output
name (str, optional) – custom name for the layer, defaults to None
activation (function, optional) – activation function, defaults to tf.nn.relu
stddev (float, optional) – standard deviation of the normal initialization, defaults to .001
- class tf_utils.PrecisionModulatedDense(input_dim, output_size, name=None, activation=<function relu>, stddev=0.001)
Bases:
tensorflow.python.module.module.Module
- tf_utils.load_tensorboard_graph(logdir, func, args, name, step=0, kwargs={})
Log the tensorboard graph trace of
func(*args, **kwargs)
- Parameters
logdir (str) – log folder path
func (function) – function to analyze
args (list) – arguments of func
name (str) – name of the tensorboard trace
step (int, optional) – tensorboard step, defaults to 0
kwargs (dict, optional) – kwargs of func, defaults to {}
- tf_utils.mlp(*args, biased=False, reversed_flow=False, activation=<function relu>, stddev=0.01, only_return_variables=False, precision_modulated=False)
Create a multi-layer perceptron
- Parameters
args – sequence of int representing layer sizes
biased (bool, optional) – controls weither we use bias in layers, defaults to False
reversed_flow (bool, optional) – controls weither we reverse the flow of activation (default is bottom-up), defaults to False
activation (function, optional) – activation function, defaults to tf.nn.relu
stddev (float, optional) – standard deviation of the normal initialization, defaults to 0.01
only_return_weights (bool, optional) – controls weither we return a list of tf.Module or 2d variable weight matrices, defaults to False
- Returns
model
- Return type
list of
tf_utils.Dense
ortf_utils.BiasedDense
or 2d variable tf.Tensor of float32
- tf_utils.one_hot_pred_accuracy(p, t, axis=1)
Compute the accuracy of a prediction
p
with respect to targett
as the proportion of timeargmax(p) == argmax(t)
- Parameters
p (3d tf.Tensor) – network prediction
t (3d tf.Tensor) – ground truth target
axis (int, optional) – argmax axis, defaults to 1
- Returns
accuracy
- Return type
float32
- tf_utils.reduced_batched_outer_product(x, y)
Compute the outer product of
x
andy
summed over batch dimesion- Parameters
x (3d tf.Tensor) – first tensor
y (3d tf.Tensor) – second tensor
- Returns
outer product summed over batch dimesion
- Return type
2d tf.Tensor
- tf_utils.relu_derivate(x)
Derivate of the ReLU activation function
- Parameters
x (tf.Tensor) – input
- Returns
output
- Return type
tf.Tensor