deepr.utils package
Submodules
deepr.utils.broadcasting module
Tensorflow Broadcasting utilities
deepr.utils.checkpoint module
Checkpoint utilities
deepr.utils.datastruct module
Generic Iter Utilities
- deepr.utils.datastruct.dict_to_item(data, keys)[source]
Convert dictionary into object or tuple of objects.
- deepr.utils.datastruct.item_to_dict(items, keys)[source]
Convert tuple or object to dictionary.
- Return type:
- deepr.utils.datastruct.to_flat_tuple(items)[source]
Convert nested list, tuples and generators to a flat tuple.
Flatten any nested structure of items. Will unpack lists, tuple and generators. Any other type will not be unpacked, meaning that you can safely use this function on other iterable types like strings or tf.Tensor. For example:
to_flat_tuple(1) # (1,) to_flat_tuple("hello") # ("hello",) to_flat_tuple(tf.ones([2, 2])) # (tf.ones([2, 2]),) to_flat_tuple((x for x in range(2))) # (0, 1) to_flat_tuple((1, 2)) # (1, 2) to_flat_tuple(((0, 1), 2)) # (0, 1, 2)
- Parameters:
items (Item, Tuple, List or Generator (nested)) – Items to transform to a flat tuple
- Returns:
- Return type:
Tuple
deepr.utils.exceptions module
Utilities for dealing with exceptions.
deepr.utils.field module
Field.
- class deepr.utils.field.Field(name, shape, dtype, default=None, sequence=None)[source]
Bases:
object
Convenient way to define fields for features.
- default
Default value of the field for padding
- Type:
Any
- dtype
Tensorflow type of the field (automatically inferred if string)
- Type:
tf.DType
- sequence
If True, the field represents a sequence.
Used for
tf.Example
message serialization : ifsequence
isTrue
, the field with be stored in thefeature_list
entry of atf.train.SequenceExample
.Automatically set if not given :
True
ifshape
’s first dimension isNone
.- Type:
- shape
Shape of the field
- Type:
Tuple
- property batch_shape
- property feature_specs
Return feature specs for parsing Example messages.
- to_feature(value)[source]
Convert value to tf.train.Feature or tf.train.FeatureList.
For shapes with more than 2 dimensions, uses
np.ravel
to flatten tensors in a list of values. Note that becausetf.Example
uses row-major to parse list of values, we make sure to use the same order with NumPy.For that reason, if any of the dimensions is not set (i.e. is
None
), aValueError
is raised.- Parameters:
value (np.array) – Tensor values
- Return type:
Union
[Feature
,FeatureList
]- Returns:
tf.train.FeatureList – If
sequence
isTrue
tf.train.Feature – If
sequence
isFalse
- Raises:
ValueError – If
sequence
,len(shape) > 2
and one of the non-first dimensions is not set (i.e. isNone
). If notsequence
,len(shape) > 2
and any of the dimensions is not set (i.e. isNone
).
deepr.utils.graph module
Tensorflow Graph utilities.
- deepr.utils.graph.get_by_name(graph, name)[source]
Return op in Graph with name or None if not found.
- Parameters:
graph (tf.Graph) – A Tensorflow Graph
- Returns:
- Return type:
tf.Operation or None
deepr.utils.graphite module
Graphite Utilities
deepr.utils.iter module
Utilities for logging.
deepr.utils.mlflow module
MLFlow utilities.
- deepr.utils.mlflow.clear_run()[source]
Clear run (remove from MLFlow stack and unset ENV variable).
- deepr.utils.mlflow.download_artifacts(run_id, path, dst_path=None, tracking_uri=None)[source]
Download artifacts from MLFlow over HTTP if possible.
deepr.utils.tables module
Tables Utilities
- class deepr.utils.tables.TableContext[source]
Bases:
object
Context Manager to reuse Tensorflow tables.
Tensorflow does not have a
tf.get_variable
equivalent for tables. TheTableContext
is here to provide this functionality.Example
>>> import deepr >>> with deepr.utils.TableContext() as tables: ... table = deepr.utils.table_from_mapping(name="my_table", mapping={1: 2}) ... tables.get("my_table") is table True
>>> with deepr.utils.TableContext(): ... table = deepr.utils.table_from_mapping(name="my_table", mapping={1: 2}) ... reused = deepr.utils.table_from_mapping(name="my_table", reuse=True) ... table is reused True
- deepr.utils.tables.index_to_string_table_from_file(name, path=None, vocab_size=None, default_value='UNK', reuse=False)[source]
Create reverse table from file
deepr.utils.tf2xla_pb2 module
deepr.utils.uuid module
Uuid