Module: transform

tf.contrib.graph_editor.replace_t_with_placeholder_handler(info, t)

Transform a tensor into a placeholder tensor.

This handler is typically used to transform a subgraph input tensor into a placeholder.

Args:
  • info: Transform._Info instance.
  • t: tensor whose input must be transformed into a place holder.
Returns:

The tensor generated by the newly created place holder.


tf.contrib.graph_editor.keep_t_if_possible_handler(info, t)

Transform a tensor into itself (identity) if possible.

This handler transform a tensor into itself if the source and destination graph are the same. Otherwise it will create a placeholder. This handler is typically used to transform a hidden input tensors.

Args:
  • info: Transform._Info instance.
  • t: tensor whose input must be transformed into a place holder.
Returns:

The tensor generated by the newly created place holder.


tf.contrib.graph_editor.assign_renamed_collections_handler(info, elem, elem_)

Add the transformed elem to the (renamed) collections of elem.

Args:
  • info: Transform._Info instance.
  • elem: the original element (tf.Tensor or tf.Operation)
  • elem_: the transformed element

tf.contrib.graph_editor.transform_op_if_inside_handler(info, op, keep_if_possible=True)

Transform an optional op only if it is inside the subgraph.

This handler is typically use to handle original op: it is fine to keep them if they are inside the subgraph, otherwise they are just ignored.

Args:
  • info: Transform._Info instance.
  • op: the optional op to transform (or ignore).
  • keep_if_possible: re-attach to the original op if possible, that is, if the source graph and the destination graph are the same.
Returns:

The transformed op or None.


tf.contrib.graph_editor.copy_op_handler(info, op, copy_shape=True)

Copy a tf.Operation.

Args:
  • info: Transform._Info instance.
  • op: the tf.Operation to be copied.
  • copy_shape: also copy the shape of the tensor
Returns:

A copy of op.


tf.contrib.graph_editor.transform_op_in_place(info, op, detach_outputs=False)

Transform a op in-place - experimental!

Transform an operation in place. It reconnects the inputs if they have been modified. if detach_outputs is True, the outputs of op are also detached.

Args:
  • info: Transform._Info instance.
  • op: the op to transform in place.
  • detach_outputs: if True, the outputs of op are detached, ready for the user to add more operation.
Returns:

The transformed op.


class tf.contrib.graph_editor.Transformer

Transform a subgraph into another one.

By default, the constructor create a transform which copy a subgraph and replaces inputs with placeholders. This behavior can be modified by changing the handlers.


tf.contrib.graph_editor.Transformer.__call__(sgv, dst_graph, dst_scope, src_scope='', reuse_dst_scope=False) {:#Transformer.call}

Execute the transformation.

Args:
  • sgv: the source subgraph-view.
  • dst_graph: the destination graph.
  • dst_scope: the destination scope.
  • src_scope: the source scope, which specify the path from which the relative path of the transformed nodes are computed. For instance, if src_scope is a/ and dst_scoped is b/, then the node a/x/y will have a relative path of x/y and will be transformed into b/x/y.
  • reuse_dst_scope: if True the dst_scope is re-used if it already exists. Otherwise, the scope is given a unique name based on the one given by appending an underscore followed by a digit (default).
Returns:

A tuple (sgv, info) where: sgv is the transformed subgraph view; info is an instance of Transformer.ResultInfo containing information about the transform, including mapping between original and transformed tensors and operations.

Raises:
  • ValueError: if the argumens are invalid.

tf.contrib.graph_editor.Transformer.__init__() {:#Transformer.init}

Transformer constructor.

The following members can be modified: transform_op_handler: handle the transformation of a tf.Operation. This handler defaults to a simple copy. assign_collections_handler: handle the assignment of collections. This handler defaults to assigning new collections created under the given name-scope. transform_external_input_handler: handle the transform of the inputs to the given subgraph. This handler defaults to creating placeholders instead of the ops just before the input tensors of the subgraph. transform_external_hidden_input_handler: handle the transform of the hidden inputs of the subgraph, that is, the inputs which are not listed in sgv.inputs. This handler defaults to a transform which keep the same input if the source and destination graphs are the same, otherwise use placeholders. transform_original_op_hanlder: handle the transform of original_op. This handler defaults to transforming original_op only if they are in the subgraph, otherwise they are ignored.


tf.contrib.graph_editor.Transformer.new_name(name)

Compute a destination name from a source name.

Args:
  • name: the name to be "transformed".
Returns:

The transformed name.

Raises:
  • ValueError: if the source scope is used (that is, not an empty string) and the source name does not belong to the source scope.

tf.contrib.graph_editor.copy(sgv, dst_graph=None, dst_scope='', src_scope='', reuse_dst_scope=False)

Copy a subgraph.

Args:
  • sgv: the source subgraph-view. This argument is converted to a subgraph using the same rules than the function subgraph.make_view.
  • dst_graph: the destination graph.
  • dst_scope: the destination scope.
  • src_scope: the source scope.
  • reuse_dst_scope: if True the dst_scope is re-used if it already exists. Otherwise, the scope is given a unique name based on the one given by appending an underscore followed by a digit (default).
Returns:

A tuple (sgv, info) where: sgv is the transformed subgraph view; info is an instance of Transformer.ResultInfo containing information about the transform, including mapping between original and transformed tensors and operations.

Raises:
  • TypeError: if dst_graph is not a tf.Graph.
  • StandardError: if sgv cannot be converted to a SubGraphView using the same rules than the function subgraph.make_view.

tf.contrib.graph_editor.copy_with_input_replacements(sgv, replacement_ts, dst_graph=None, dst_scope='', src_scope='', reuse_dst_scope=False)

Copy a subgraph, replacing some of its inputs.

Note a replacement only happens if the tensor to be replaced is an input of the given subgraph. The inputs of a subgraph can be queried using sgv.inputs.

Args:
  • sgv: the source subgraph-view. This argument is converted to a subgraph using the same rules as the function subgraph.make_view.
  • replacement_ts: dictionary mapping from original tensors to the replaced one.
  • dst_graph: the destination graph.
  • dst_scope: the destination scope.
  • src_scope: the source scope.
  • reuse_dst_scope: if True the dst_scope is re-used if it already exists. Otherwise, the scope is given a unique name based on the one given by appending an underscore followed by a digit (default).
Returns:

A tuple (sgv, info) where: sgv is the transformed subgraph view; info is an instance of Transformer.ResultInfo containing information about the transform, including mapping between original and transformed tensors and operations.

Raises:
  • TypeError: if dst_graph is not a tf.Graph.
  • StandardError: if sgv cannot be converted to a SubGraphView using the same rules as the function subgraph.make_view.

tf.contrib.graph_editor.graph_replace(target_ts, replacement_ts, dst_scope='', src_scope='', reuse_dst_scope=False)

Create a new graph which compute the targets from the replaced Tensors.

Args:
  • target_ts: a single tf.Tensor or an iterabble of tf.Tensor.
  • replacement_ts: dictionary mapping from original tensors to replaced tensors
  • dst_scope: the destination scope.
  • src_scope: the source scope.
  • reuse_dst_scope: if True the dst_scope is re-used if it already exists. Otherwise, the scope is given a unique name based on the one given by appending an underscore followed by a digit (default).
Returns:

A single tf.Tensor or a list of target tf.Tensor, depending on the type of the input argument target_ts. The returned tensors are recomputed using the tensors from replacement_ts.

Raises:
  • ValueError: if the targets are not connected to replacement_ts.