Utils

track

track(tensor, collection, module_name=None)

Track tensor by adding it to the collection.


get_tracked

get_tracked(collection, module_name=None, scope=None)

Returns a list of values in the collection with the given collection.


get_shape

get_shape(x)

Get the incoming data shape.

  • Args:
    • x: incoming data.
  • Returns: the incoming data shape.

validate_dtype

validate_dtype(x)

get_variable_scope

get_variable_scope(name=None, scope=None, values=None, reuse=None)

get_name_scope

get_name_scope(name=None, scope=None, values=None)

clip

clip(x, min_value, max_value)

Element-wise value clipping.


int_or_tuple

int_or_tuple(value)

Converts value (int or tuple) to height, width.

This functions normalizes the input value by always returning a tuple.

  • Args:

    • value: A list of 2 ints, 4 ints, a single int or a tf.TensorShape.
  • Returns: A list with 4 values.

  • Raises:

    • ValueError: If value it not well formed.
    • TypeError: if the value type is not supported

int_or_tuple_3d

int_or_tuple_3d(value)

Converts value (int or tuple) to height, width for 3d ops.

This functions normalizes the input value by always returning a tuple.

  • Args:

    • value: A list of 3 ints, 5 ints, a single int or a tf.TensorShape.
  • Returns: A list with 5 values.

  • Raises:

    • ValueError: If value it not well formed.
    • TypeError: if the value type is not supported

validate_padding

validate_padding(value)

Validates and format padding value

  • Args:

    • value: str padding value to validate.
  • Returns: formatted value.

  • Raises:

    • ValueError: if is not valid.

validate_filter_size

validate_filter_size(filter_size, in_depth, num_filter)

Validates filter size for CNN operations


validate_filter_size_3d

validate_filter_size_3d(filter_size, in_depth, num_filter)

Validates filter size for 3d CNN operations


check_restore_tensor

check_restore_tensor(tensor_to_check, exclvars)

transpose_batch_time

transpose_batch_time(x)

Transpose the batch and time dimensions of a Tensor.

Retains as much of the static shape information as possible.

  • Args:

    • x: A tensor of rank 2 or higher.
  • Returns: x transposed along the first two dimensions.

  • Raises:

    • ValueError: if x is rank 1 or lower.

generate_model_dir

generate_model_dir()

get_arguments

get_arguments(func)

Returns list of arguments this function has.


extract_batch_length

extract_batch_length(values)

Extracts batch length of values.


get_tensor_batch_size

get_tensor_batch_size(values)

Extracts batch size from tensor


total_tensor_depth

total_tensor_depth(tensor=None, tensor_shape=None)

Returns the size of a tensor without the first (batch) dimension


new_attr_context

new_attr_context()

Creates a new context in which an object's attribute can be changed.

This creates a context in which an object's attribute can be changed. Once the context is exited, the attribute reverts to its original value.

  • Args:

    • obj: An object whose attribute to restore at the end of the context.
    • attr: An attribute to remember and restore at the end of the context.
  • Yields: Context.

  • Example:

>>> my_obj.x = 1
>>> with _new_attr_context(my_obj, "x"):
>>> my_obj.x = 2
>>> print(my_obj.x)
>>> print(my_obj.x)

get_function_name

get_function_name(func)

Returns a module name for a callable or None if no name can be found.