`class tf.contrib.graph_editor.ControlOutputs`

The control outputs topology.

`tf.contrib.graph_editor.ControlOutputs.__init__(graph)`

{:#ControlOutputs.**init**}

Create a dictionary of control-output dependencies.

##### Args:

: a`graph`

`tf.Graph`

.

##### Returns:

A dictionary where a key is a `tf.Operation`

instance and the
corresponding value is a list of all the ops which have the key
as one of their control-input dependencies.

##### Raises:

: graph is not a`TypeError`

`tf.Graph`

.

`tf.contrib.graph_editor.ControlOutputs.get(op)`

return the control outputs of op.

`tf.contrib.graph_editor.ControlOutputs.get_all()`

`tf.contrib.graph_editor.ControlOutputs.graph`

`tf.contrib.graph_editor.ControlOutputs.update()`

Update the control outputs if the graph has changed.

`class tf.contrib.graph_editor.OpMatcher`

Graph match class.

`tf.contrib.graph_editor.OpMatcher.__call__(op)`

{:#OpMatcher.**call**}

Evaluate if the op matches or not.

`tf.contrib.graph_editor.OpMatcher.__init__(positive_filter)`

{:#OpMatcher.**init**}

Graph match constructor.

`tf.contrib.graph_editor.OpMatcher.control_input_ops(*args)`

Add input matches.

`tf.contrib.graph_editor.OpMatcher.input_ops(*args)`

Add input matches.

`tf.contrib.graph_editor.OpMatcher.output_ops(*args)`

Add output matches.

`class tf.contrib.graph_editor.SubGraphView`

A subgraph view on an existing `tf.Graph`

.

An instance of this class is a subgraph view on an existing `tf.Graph`

.
"subgraph" means that it can represent part of the whole `tf.Graph`

.
"view" means that it only provides a passive observation and do not to act
on the `tf.Graph`

. Note that in this documentation, the term "subgraph" is
often used as substitute to "subgraph view".

A subgraph contains:

- a list of input tensors, accessible via the
`inputs`

property. - a list of output tensors, accessible via the
`outputs`

property. - and the operations in between, accessible via the "ops" property.

An subgraph can be seen as a function F(i0, i1, ...) -> o0, o1, ... It is a function which takes as input some input tensors and returns as output some output tensors. The computation that the function performs is encoded in the operations of the subgraph.

The tensors (input or output) can be of two kinds:

- connected: a connected tensor connects to at least one operation contained in the subgraph. One example is a subgraph representing a single operation and its inputs and outputs: all the input and output tensors of the op are "connected".
- passthrough: a passthrough tensor does not connect to any operation contained in the subgraph. One example is a subgraph representing a single tensor: this tensor is passthrough. By default a passthrough tensor is present both in the input and output tensors of the subgraph. It can however be remapped to only appear as an input (or output) only.

The input and output tensors can be remapped. For instance, some input tensor
can be omitted. For instance, a subgraph representing an operation with two
inputs can be remapped to only take one input. Note that this does not change
at all the underlying `tf.Graph`

(remember, it is a view). It means that
the other input is being ignored, or is being treated as "given".
The analogy with functions can be extended like this: F(x,y) is the original
function. Remapping the inputs from [x, y] to just [x] means that the subgraph
now represent the function F_y(x) (y is "given").

The output tensors can also be remapped. For instance, some output tensor can
be omitted. Other output tensor can be duplicated as well. As mentioned
before, this does not change at all the underlying `tf.Graph`

.
The analogy with functions can be extended like this: F(...)->x,y is the
original function. Remapping the outputs from [x, y] to just [y,y] means that
the subgraph now represent the function M(F(...)) where M is the function
M(a,b)->b,b.

It is useful to describe three other kind of tensors:

- internal: an internal tensor is a tensor connecting operations contained in the subgraph. One example in the subgraph representing the two operations A and B connected sequentially: -> A -> B ->. The middle arrow is an internal tensor.
- actual input: an input tensor of the subgraph, regardless of whether it is listed in "inputs" or not (masked-out).
- actual output: an output tensor of the subgraph, regardless of whether it is listed in "outputs" or not (masked-out).
- hidden input: an actual input which has been masked-out using an input remapping. In other word, a hidden input is a non-internal tensor not listed as a input tensor and one of whose consumers belongs to the subgraph.
- hidden output: a actual output which has been masked-out using an output remapping. In other word, a hidden output is a non-internal tensor not listed as an output and one of whose generating operations belongs to the subgraph.

Here are some useful guarantees about an instance of a SubGraphView:

- the input (or output) tensors are not internal.
- the input (or output) tensors are either "connected" or "passthrough".
- the passthrough tensors are not connected to any of the operation of the subgraph.

Note that there is no guarantee that an operation in a subgraph contributes at all to its inputs or outputs. For instance, remapping both the inputs and outputs to empty lists will produce a subgraph which still contains all the original operations. However, the remove_unused_ops function can be used to make a new subgraph view whose operations are connected to at least one of the input or output tensors.

An instance of this class is meant to be a lightweight object which is not modified in-place by the user. Rather, the user can create new modified instances of a given subgraph. In that sense, the class SubGraphView is meant to be used like an immutable python object.

A common problem when using views is that they can get out-of-sync with the
data they observe (in this case, a `tf.Graph`

). This is up to the user to
ensure that this doesn't happen. To keep on the safe side, it is recommended
that the life time of subgraph views are kept very short. One way to achieve
this is to use subgraphs within a "with make_sgv(...) as sgv:" Python context.

To alleviate the out-of-sync problem, some functions are granted the right to
modified subgraph in place. This is typically the case of graph manipulation
functions which, given some subgraphs as arguments, can modify the underlying
`tf.Graph`

. Since this modification is likely to render the subgraph view
invalid, those functions can modify the argument in place to reflect the
change. For instance, calling the function swap_inputs(svg0, svg1) will modify
svg0 and svg1 in place to reflect the fact that their inputs have now being
swapped.

`tf.contrib.graph_editor.SubGraphView.__bool__()`

{:#SubGraphView.**bool**}

Allows for implicit boolean conversion.

`tf.contrib.graph_editor.SubGraphView.__copy__()`

{:#SubGraphView.**copy**}

Create a copy of this subgraph.

Note that this class is a "view", copying it only create another view and
does not copy the underlying part of the `tf.Graph`

.

##### Returns:

A new identical instance of the original subgraph view.

`tf.contrib.graph_editor.SubGraphView.__enter__()`

{:#SubGraphView.**enter**}

Allow Python context to minimize the life time of a subgraph view.

A subgraph view is meant to be a lightweight and transient object. A short lifetime will alleviate the "out-of-sync" issue mentioned earlier. For that reason, a SubGraphView instance can be used within a Python context. For example:

from tensorflow.contrib import graph_editor as ge with ge.make_sgv(...) as sgv: print(sgv)

##### Returns:

Itself.

`tf.contrib.graph_editor.SubGraphView.__exit__(exc_type, exc_value, traceback)`

{:#SubGraphView.**exit**}

`tf.contrib.graph_editor.SubGraphView.__init__(inside_ops=(), passthrough_ts=())`

{:#SubGraphView.**init**}

Create a subgraph containing the given ops and the "passthrough" tensors.

##### Args:

: an object convertible to a list of`inside_ops`

`tf.Operation`

. This list defines all the operations in the subgraph.: an object convertible to a list of`passthrough_ts`

`tf.Tensor`

. This list define all the "passthrough" tensors. A passthrough tensor is a tensor which goes directly from the input of the subgraph to it output, without any intermediate operations. All the non passthrough tensors are silently ignored.

##### Raises:

: if inside_ops cannot be converted to a list of`TypeError`

`tf.Operation`

or if`passthrough_ts`

cannot be converted to a list of`tf.Tensor`

.

`tf.contrib.graph_editor.SubGraphView.__nonzero__()`

{:#SubGraphView.**nonzero**}

Allows for implicit boolean conversion.

`tf.contrib.graph_editor.SubGraphView.__str__()`

{:#SubGraphView.**str**}

`tf.contrib.graph_editor.SubGraphView.connected_inputs`

The connected input tensors of this subgraph view.

`tf.contrib.graph_editor.SubGraphView.connected_outputs`

The connected output tensors of this subgraph view.

`tf.contrib.graph_editor.SubGraphView.consumers()`

Return a Python set of all the consumers of this subgraph view.

A consumer of a subgraph view is a tf.Operation which is a consumer of one of the output tensors and is not in the subgraph.

##### Returns:

A list of `tf.Operation`

which are the consumers of this subgraph view.

`tf.contrib.graph_editor.SubGraphView.copy()`

Return a copy of itself.

Note that this class is a "view", copying it only create another view and does not copy the underlying part of the tf.Graph.

##### Returns:

A new instance identical to the original one.

`tf.contrib.graph_editor.SubGraphView.find_op_by_name(op_name)`

Return the op named op_name.

##### Args:

: the name to search for`op_name`

##### Returns:

The op named op_name.

##### Raises:

: if the op_name could not be found.`ValueError`

: if the name was found multiple time.`AssertionError`

`tf.contrib.graph_editor.SubGraphView.graph`

The underlying `tf.Graph`

.

`tf.contrib.graph_editor.SubGraphView.input_index(t)`

Find the input index corresponding to the given input tensor t.

##### Args:

: the input tensor of this subgraph view.`t`

##### Returns:

The index in the self.inputs list.

##### Raises:

: if t in not an input tensor.`Error`

`tf.contrib.graph_editor.SubGraphView.inputs`

The input tensors of this subgraph view.

`tf.contrib.graph_editor.SubGraphView.is_passthrough(t)`

Check whether a tensor is passthrough.

`tf.contrib.graph_editor.SubGraphView.op(op_id)`

Get an op by its index.

`tf.contrib.graph_editor.SubGraphView.ops`

The operations in this subgraph view.

`tf.contrib.graph_editor.SubGraphView.output_index(t)`

Find the output index corresponding to given output tensor t.

##### Args:

: the output tensor of this subgraph view.`t`

##### Returns:

The index in the self.outputs list.

##### Raises:

: if t in not an output tensor.`Error`

`tf.contrib.graph_editor.SubGraphView.outputs`

The output tensors of this subgraph view.

`tf.contrib.graph_editor.SubGraphView.passthroughs`

The passthrough tensors, going straight from input to output.

`tf.contrib.graph_editor.SubGraphView.remap(new_input_indices=None, new_output_indices=None)`

Remap the inputs and outputs of the subgraph.

Note that this is only modifying the view: the underlying tf.Graph is not affected.

##### Args:

: an iterable of integers or tf.Tensors representing a mapping between the old inputs and the new ones. Integers must be positive and smaller than the number of old inputs. tf.Tensors must belong to the old list of inputs. This mapping can be under-complete and must be without repetitions.`new_input_indices`

: an iterable of integers or tf.Tensors representing a mapping between the old outputs and the new ones. Integers must be positive and smaller than the number of old outputs. tf.Tensors must belong to the old list of outputs. This mapping can be under-complete and can have repetitions.`new_output_indices`

##### Returns:

A new modified instance of the original subgraph view with remapped inputs and outputs.

`tf.contrib.graph_editor.SubGraphView.remap_default(remove_input_map=True, remove_output_map=True)`

Remap the inputs and/or outputs to the default mapping.

##### Args:

: if True the input map is reset to the default one.`remove_input_map`

: if True the output map is reset to the default one.`remove_output_map`

##### Returns:

A new modified instance of the original subgraph view with its input and/or output mapping reset to the default one.

`tf.contrib.graph_editor.SubGraphView.remap_inputs(new_input_indices)`

Remap the inputs of the subgraph.

If the inputs of the original subgraph are [t0, t1, t2], remapping to [2,0] will create a new instance whose inputs is [t2, t0].

Note that this is only modifying the view: the underlying `tf.Graph`

is not
affected.

##### Args:

: an iterable of integers or tf.Tensors representing a mapping between the old inputs and the new ones. Integers must be positive and smaller than the number of old inputs. tf.Tensors must belong to the old list of inputs. This mapping can be under-complete and must be without repetitions.`new_input_indices`

##### Returns:

A new modified instance of the original subgraph view with remapped inputs.

`tf.contrib.graph_editor.SubGraphView.remap_outputs(new_output_indices)`

Remap the output of the subgraph.

If the output of the original subgraph are [t0, t1, t2], remapping to [1,1,0] will create a new instance whose outputs is [t1, t1, t0].

Note that this is only modifying the view: the underlying tf.Graph is not affected.

##### Args:

: an iterable of integers or tf.Tensors representing a mapping between the old outputs and the new ones. Integers must be positive and smaller than the number of old outputs. tf.Tensors must belong to the old list of outputs. This mapping can be under-complete and can have repetitions.`new_output_indices`

##### Returns:

A new modified instance of the original subgraph view with remapped outputs.

`tf.contrib.graph_editor.SubGraphView.remap_outputs_make_unique()`

Remap the outputs so that all the tensors appears only once.

`tf.contrib.graph_editor.SubGraphView.remap_outputs_to_consumers()`

Remap the outputs to match the number of consumers.

`tf.contrib.graph_editor.SubGraphView.remove_unused_ops(control_inputs=True)`

Remove unused ops.

##### Args:

: if True, control inputs are used to detect used ops.`control_inputs`

##### Returns:

A new subgraph view which only contains used operations.

`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:

: the source subgraph-view.`sgv`

: the destination graph.`dst_graph`

: the destination scope.`dst_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.`src_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).`reuse_dst_scope`

##### Returns:

A tuple `(sgv, info)`

where:
`sgv`

is the transformed subgraph view;
`info`

is an instance of TransformerInfo containing
information about the transform, including mapping between
original and transformed tensors and operations.

##### Raises:

: if the arguments are invalid.`ValueError`

`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_handler: handle the transform of original_op. This
handler defaults to transforming original_op only if they are in the
subgraph, otherwise they are ignored.

`class tf.contrib.graph_editor.TransformerInfo`

"Contains information about the result of a transform operation.

`tf.contrib.graph_editor.TransformerInfo.__init__(info)`

{:#TransformerInfo.**init**}

Constructor.

##### Args:

: an instance of Transformer._TmpInfo containing various internal information about the transform operation.`info`

`tf.contrib.graph_editor.TransformerInfo.__str__()`

{:#TransformerInfo.**str**}

`tf.contrib.graph_editor.TransformerInfo.original(transformed, missing_fn=None)`

Return the original op/tensor corresponding to the transformed one.

Note that the output of this function mimics the hierarchy
of its input argument `transformed`

.
Given an iterable, it returns a list. Given an operation or a tensor,
it will return an operation or a tensor.

##### Args:

: the transformed tensor/operation.`transformed`

: function handling the case where the counterpart cannot be found. By default, None is returned.`missing_fn`

##### Returns:

the original tensor/operation (or None if no match is found).

`tf.contrib.graph_editor.TransformerInfo.transformed(original, missing_fn=None)`

Return the transformed op/tensor corresponding to the original one.

Note that the output of this function mimics the hierarchy
of its input argument `original`

.
Given an iterable, it returns a list. Given an operation or a tensor,
it will return an operation or a tensor.

##### Args:

: the original tensor/operation.`original`

: function handling the case where the counterpart cannot be found. By default, None is returned.`missing_fn`

##### Returns:

the transformed tensor/operation (or None if no match is found).

`tf.contrib.graph_editor.add_control_inputs(op, cops)`

Add the control inputs cops to co.

##### Args:

: a tf.Operation to which the control inputs are added.`op`

: an object convertible to a list of`cops`

`tf.Operation`

.

##### Raises:

: if op is not a tf.Operation`TypeError`

: if any cop in cops is already a control input of op.`ValueError`

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

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

A collection is renamed only if is not a known key, as described in
`tf.GraphKeys`

.

##### Args:

: Transform._TmpInfo instance.`info`

: the original element (`elem`

`tf.Tensor`

or`tf.Operation`

): the transformed element`elem_`

`tf.contrib.graph_editor.bypass(sgv)`

Bypass the given subgraph by connecting its inputs to its outputs.

##### Args:

: the subgraph view to be bypassed. This argument is converted to a subgraph using the same rules than the function subgraph.make_view. Note that sgv is modified in place.`sgv`

##### Returns:

A tuple `(sgv, detached_inputs)`

where:
`sgv`

is a new subgraph view of the bypassed subgraph;
`detached_inputs`

is a list of the created input placeholders.

##### Raises:

: if sgv cannot be converted to a SubGraphView using the same rules than the function subgraph.make_view.`StandardError`

`tf.contrib.graph_editor.can_be_regex(obj)`

Return True if obj can be turned into a regular expression.

`tf.contrib.graph_editor.check_cios(control_inputs=False, control_outputs=None, control_ios=None)`

Do various check on control_inputs and control_outputs.

##### Args:

: A boolean indicating whether control inputs are enabled.`control_inputs`

: An instance of util.ControlOutputs or None. If not None, control outputs are enabled.`control_outputs`

: An instance of util.ControlOutputs or None. If not None, both control inputs and control outputs are enabled. This is equivalent to set control_inputs to True and control_outputs to the util.ControlOutputs instance.`control_ios`

##### Returns:

A tuple `(control_inputs, control_outputs)`

where:
`control_inputs`

is a boolean indicating whether to use control inputs.
`control_outputs`

is an instance of util.ControlOutputs or None

##### Raises:

: if control_inputs is an instance of util.ControlOutputs but control_outputs is not None`ValueError`

: if control_outputs is not None and is not a util.ControlOutputs.`TypeError`

`tf.contrib.graph_editor.compute_boundary_ts(ops)`

Compute the tensors at the boundary of a set of ops.

This function looks at all the tensors connected to the given ops (in/out) and classify them into three categories: 1) input tensors: tensors whose generating operation is not in ops. 2) output tensors: tensors whose consumer operations are not in ops 3) inside tensors: tensors which are neither input nor output tensors.

Note that a tensor can be both an inside tensor and an output tensor if it is
consumed by operations both outside and inside of `ops`

.

##### Args:

: an object convertible to a list of tf.Operation.`ops`

##### Returns:

A tuple `(outside_input_ts, outside_output_ts, inside_ts)`

where:
`outside_input_ts`

is a Python list of input tensors;
`outside_output_ts`

is a python list of output tensors;
`inside_ts`

is a python list of inside tensors.
Since a tensor can be both an inside tensor and an output tensor,
`outside_output_ts`

and `inside_ts`

might intersect.

##### Raises:

: if ops cannot be converted to a list of tf.Operation.`TypeError`

`tf.contrib.graph_editor.connect(sgv0, sgv1, disconnect_first=False)`

Connect the outputs of sgv0 to the inputs of sgv1.

##### Args:

: the first subgraph to have its outputs swapped. This argument is converted to a subgraph using the same rules as the function subgraph.make_view. Note that sgv0 is modified in place.`sgv0`

: the second subgraph to have its outputs swapped. This argument is converted to a subgraph using the same rules as the function subgraph.make_view. Note that sgv1 is modified in place.`sgv1`

: if True the current outputs of sgv0 are disconnected.`disconnect_first`

##### Returns:

A tuple `(sgv0, sgv1)`

of the now connected subgraphs.

##### Raises:

: if sgv0 or sgv1 cannot be converted to a SubGraphView using the same rules than the function subgraph.make_view.`StandardError`

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

Copy a `tf.Operation`

.

##### Args:

: Transform._TmpInfo instance.`info`

: the`op`

`tf.Operation`

to be copied.: also copy the shape of the tensor`copy_shape`

##### Returns:

A `(op, op_outputs)`

tuple containgin the transformed op and its outputs.

`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:

: the source subgraph-view. This argument is converted to a subgraph using the same rules as the function subgraph.make_view.`sgv`

: dictionary mapping from original tensors to the replaced one.`replacement_ts`

: the destination graph.`dst_graph`

: the destination scope.`dst_scope`

: the source scope.`src_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).`reuse_dst_scope`

##### Returns:

A tuple `(sgv, info)`

where:
`sgv`

is the transformed subgraph view;
`info`

is an instance of TransformerInfo containing
information about the transform, including mapping between
original and transformed tensors and operations.

##### Raises:

: if dst_graph is not a tf.Graph.`TypeError`

: if sgv cannot be converted to a SubGraphView using the same rules as the function subgraph.make_view.`StandardError`

`tf.contrib.graph_editor.detach(sgv, control_inputs=False, control_outputs=None, control_ios=None)`

Detach both the inputs and the outputs of a subgraph view.

##### Args:

: the subgraph view to be detached. This argument is converted to a subgraph using the same rules as the function subgraph.make_view. Note that sgv is modified in place.`sgv`

: A boolean indicating whether control inputs are enabled.`control_inputs`

: An instance of util.ControlOutputs or None. If not None, control outputs are enabled.`control_outputs`

: An instance of util.ControlOutputs or None. If not None, both control inputs and control outputs are enabled. This is equivalent to set control_inputs to True and control_outputs to the util.ControlOutputs instance.`control_ios`

##### Returns:

A tuple `(sgv, detached_inputs, detached_outputs)`

where:
`sgv`

is a new subgraph view of the detached subgraph;
`detach_inputs`

is a list of the created input placeholders;
`detach_outputs`

is a list of the created output placeholders.

##### Raises:

: if sgv cannot be converted to a SubGraphView using the same rules than the function subgraph.make_view.`StandardError`

`tf.contrib.graph_editor.detach_control_inputs(sgv)`

Detach all the external control inputs of the subgraph sgv.

##### Args:

: the subgraph view to be detached. This argument is converted to a subgraph using the same rules as the function subgraph.make_view.`sgv`

`tf.contrib.graph_editor.detach_control_outputs(sgv, control_outputs)`

Detach all the external control outputs of the subgraph sgv.

##### Args:

: the subgraph view to be detached. This argument is converted to a subgraph using the same rules as the function subgraph.make_view.`sgv`

: a util.ControlOutputs instance.`control_outputs`

`tf.contrib.graph_editor.detach_inputs(sgv, control_inputs=False)`

Detach the inputs of a subgraph view.

##### Args:

: the subgraph view to be detached. This argument is converted to a subgraph using the same rules as the function subgraph.make_view. Note that sgv is modified in place.`sgv`

: if True control_inputs are also detached.`control_inputs`

##### Returns:

A tuple `(sgv, input_placeholders)`

where
`sgv`

is a new subgraph view of the detached subgraph;
`input_placeholders`

is a list of the created input placeholders.

##### Raises:

: if sgv cannot be converted to a SubGraphView using the same rules than the function subgraph.make_view.`StandardError`

`tf.contrib.graph_editor.detach_outputs(sgv, control_outputs=None)`

Detach the output of a subgraph view.

##### Args:

: the subgraph view to be detached. This argument is converted to a subgraph using the same rules as the function subgraph.make_view. Note that sgv is modified in place.`sgv`

: a util.ControlOutputs instance or None. If not None the control outputs are also detached.`control_outputs`

##### Returns:

A tuple `(sgv, output_placeholders)`

where
`sgv`

is a new subgraph view of the detached subgraph;
`output_placeholders`

is a list of the created output placeholders.

##### Raises:

: if sgv cannot be converted to a SubGraphView using the same rules than the function subgraph.make_view.`StandardError`

`tf.contrib.graph_editor.filter_ops(ops, positive_filter)`

Get the ops passing the given filter.

##### Args:

: an object convertible to a list of tf.Operation.`ops`

: a function deciding where to keep an operation or not. If True, all the operations are returned.`positive_filter`

##### Returns:

A list of selected tf.Operation.

##### Raises:

: if ops cannot be converted to a list of tf.Operation.`TypeError`

`tf.contrib.graph_editor.filter_ops_from_regex(ops, regex)`

Get all the operations that match the given regex.

##### Args:

: an object convertible to a list of`ops`

`tf.Operation`

.: a regular expression matching the operation's name. For example,`regex`

`"^foo(/.*)?$"`

will match all the operations in the "foo" scope.

##### Returns:

A list of `tf.Operation`

.

##### Raises:

: if ops cannot be converted to a list of`TypeError`

`tf.Operation`

.

`tf.contrib.graph_editor.filter_ts(ops, positive_filter)`

Get all the tensors which are input or output of an op in ops.

##### Args:

: an object convertible to a list of`ops`

`tf.Operation`

.: a function deciding whether to keep a tensor or not. If`positive_filter`

`True`

, all the tensors are returned.

##### Returns:

A list of `tf.Tensor`

.

##### Raises:

: if ops cannot be converted to a list of`TypeError`

`tf.Operation`

.

`tf.contrib.graph_editor.filter_ts_from_regex(ops, regex)`

Get all the tensors linked to ops that match the given regex.

##### Args:

: an object convertible to a list of tf.Operation.`ops`

: a regular expression matching the tensors' name. For example, "^foo(/.*)?:\d+$" will match all the tensors in the "foo" scope.`regex`

##### Returns:

A list of tf.Tensor.

##### Raises:

: if ops cannot be converted to a list of tf.Operation.`TypeError`

`tf.contrib.graph_editor.get_backward_walk_ops(seed_ops, inclusive=True, within_ops=None, stop_at_ts=(), control_inputs=False)`

Do a backward graph walk and return all the visited ops.

##### Args:

: an iterable of operations from which the backward graph walk starts. If a list of tensors is given instead, the seed_ops are set to be the generators of those tensors.`seed_ops`

: if True the given seed_ops are also part of the resulting set.`inclusive`

: an iterable of`within_ops`

`tf.Operation`

within which the search is restricted. If`within_ops`

is`None`

, the search is performed within the whole graph.: an iterable of tensors at which the graph walk stops.`stop_at_ts`

: if True, control inputs will be used while moving backward.`control_inputs`

##### Returns:

A Python set of all the `tf.Operation`

behind `seed_ops`

.

##### Raises:

: if`TypeError`

`seed_ops`

or`within_ops`

cannot be converted to a list of`tf.Operation`

.

`tf.contrib.graph_editor.get_consuming_ops(ts)`

Return all the consuming ops of the tensors in ts.

##### Args:

: a list of`ts`

`tf.Tensor`

##### Returns:

A list of all the consuming `tf.Operation`

of the tensors in `ts`

.

##### Raises:

: if ts cannot be converted to a list of`TypeError`

`tf.Tensor`

.

`tf.contrib.graph_editor.get_forward_walk_ops(seed_ops, inclusive=True, within_ops=None, stop_at_ts=(), control_outputs=None)`

Do a forward graph walk and return all the visited ops.

##### Args:

: an iterable of operations from which the forward graph walk starts. If a list of tensors is given instead, the seed_ops are set to be the consumers of those tensors.`seed_ops`

: if True the given seed_ops are also part of the resulting set.`inclusive`

: an iterable of`within_ops`

`tf.Operation`

within which the search is restricted. If`within_ops`

is`None`

, the search is performed within the whole graph.: an iterable of tensors at which the graph walk stops.`stop_at_ts`

: a`control_outputs`

`util.ControlOutputs`

instance or None. If not`None`

, it will be used while walking the graph forward.

##### Returns:

A Python set of all the `tf.Operation`

ahead of `seed_ops`

.

##### Raises:

: if`TypeError`

`seed_ops`

or`within_ops`

cannot be converted to a list of`tf.Operation`

.

`tf.contrib.graph_editor.get_generating_ops(ts)`

Return all the generating ops of the tensors in `ts`

.

##### Args:

: a list of`ts`

`tf.Tensor`

##### Returns:

A list of all the generating `tf.Operation`

of the tensors in `ts`

.

##### Raises:

: if`TypeError`

`ts`

cannot be converted to a list of`tf.Tensor`

.

`tf.contrib.graph_editor.get_name_scope_ops(ops, scope)`

Get all the operations under the given scope path.

##### Args:

: an object convertible to a list of tf.Operation.`ops`

: a scope path.`scope`

##### Returns:

A list of tf.Operation.

##### Raises:

: if ops cannot be converted to a list of tf.Operation.`TypeError`

`tf.contrib.graph_editor.get_ops_ios(ops, control_inputs=False, control_outputs=None, control_ios=None)`

Return all the `tf.Operation`

which are connected to an op in ops.

##### Args:

: an object convertible to a list of`ops`

`tf.Operation`

.: A boolean indicating whether control inputs are enabled.`control_inputs`

: An instance of`control_outputs`

`util.ControlOutputs`

or`None`

. If not`None`

, control outputs are enabled.: An instance of`control_ios`

`util.ControlOutputs`

or`None`

. If not`None`

, both control inputs and control outputs are enabled. This is equivalent to set`control_inputs`

to`True`

and`control_outputs`

to the`util.ControlOutputs`

instance.

##### Returns:

All the `tf.Operation`

surrounding the given ops.

##### Raises:

: if`TypeError`

`ops`

cannot be converted to a list of`tf.Operation`

.

`tf.contrib.graph_editor.get_tensors(graph)`

get all the tensors which are input or output of an op in the graph.

##### Args:

: a`graph`

`tf.Graph`

.

##### Returns:

A list of `tf.Tensor`

.

##### Raises:

: if graph is not a`TypeError`

`tf.Graph`

.

`tf.contrib.graph_editor.get_walks_intersection_ops(forward_seed_ops, backward_seed_ops, forward_inclusive=True, backward_inclusive=True, within_ops=None, control_inputs=False, control_outputs=None, control_ios=None)`

Return the intersection of a forward and a backward walk.

##### Args:

: an iterable of operations from which the forward graph walk starts. If a list of tensors is given instead, the seed_ops are set to be the consumers of those tensors.`forward_seed_ops`

: an iterable of operations from which the backward graph walk starts. If a list of tensors is given instead, the seed_ops are set to be the generators of those tensors.`backward_seed_ops`

: if True the given forward_seed_ops are also part of the resulting set.`forward_inclusive`

: if True the given backward_seed_ops are also part of the resulting set.`backward_inclusive`

: an iterable of tf.Operation within which the search is restricted. If within_ops is None, the search is performed within the whole graph.`within_ops`

: A boolean indicating whether control inputs are enabled.`control_inputs`

: An instance of util.ControlOutputs or None. If not None, control outputs are enabled.`control_outputs`

: An instance of util.ControlOutputs or None. If not None, both control inputs and control outputs are enabled. This is equivalent to set control_inputs to True and control_outputs to the util.ControlOutputs instance.`control_ios`

##### Returns:

A Python set of all the tf.Operation in the intersection of a forward and a backward walk.

##### Raises:

: if`TypeError`

`forward_seed_ops`

or`backward_seed_ops`

or`within_ops`

cannot be converted to a list of`tf.Operation`

.

`tf.contrib.graph_editor.get_walks_union_ops(forward_seed_ops, backward_seed_ops, forward_inclusive=True, backward_inclusive=True, within_ops=None, control_inputs=False, control_outputs=None, control_ios=None)`

Return the union of a forward and a backward walk.

##### Args:

: an iterable of operations from which the forward graph walk starts. If a list of tensors is given instead, the seed_ops are set to be the consumers of those tensors.`forward_seed_ops`

: an iterable of operations from which the backward graph walk starts. If a list of tensors is given instead, the seed_ops are set to be the generators of those tensors.`backward_seed_ops`

: if True the given forward_seed_ops are also part of the resulting set.`forward_inclusive`

: if True the given backward_seed_ops are also part of the resulting set.`backward_inclusive`

: restrict the search within those operations. If within_ops is None, the search is done within the whole graph.`within_ops`

: A boolean indicating whether control inputs are enabled.`control_inputs`

: An instance of util.ControlOutputs or None. If not None, control outputs are enabled.`control_outputs`

: An instance of util.ControlOutputs or None. If not None, both control inputs and control outputs are enabled. This is equivalent to set control_inputs to True and control_outputs to the util.ControlOutputs instance.`control_ios`

##### Returns:

A Python set of all the tf.Operation in the union of a forward and a backward walk.

##### Raises:

: if forward_seed_ops or backward_seed_ops or within_ops cannot be converted to a list of tf.Operation.`TypeError`

`tf.contrib.graph_editor.get_within_boundary_ops(ops, seed_ops, boundary_ops=(), inclusive=True, control_inputs=False, control_outputs=None, control_ios=None)`

Return all the `tf.Operation`

within the given boundary.

##### Args:

: an object convertible to a list of`ops`

`tf.Operation`

. those ops define the set in which to perform the operation (if a`tf.Graph`

is given, it will be converted to the list of all its operations).: the operations from which to start expanding.`seed_ops`

: the ops forming the boundary.`boundary_ops`

: if`inclusive`

`True`

, the result will also include the boundary ops.: A boolean indicating whether control inputs are enabled.`control_inputs`

: An instance of`control_outputs`

`util.ControlOutputs`

or`None`

. If not`None`

, control outputs are enabled.: An instance of`control_ios`

`util.ControlOutputs`

or`None`

. If not`None`

, both control inputs and control outputs are enabled. This is equivalent to set control_inputs to True and control_outputs to the`util.ControlOutputs`

instance.

##### Returns:

All the `tf.Operation`

surrounding the given ops.

##### Raises:

: if`TypeError`

`ops`

or`seed_ops`

cannot be converted to a list of`tf.Operation`

.: if the boundary is intersecting with the seeds.`ValueError`

`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:

: a single tf.Tensor or an iterable of tf.Tensor.`target_ts`

: dictionary mapping from original tensors to replaced tensors`replacement_ts`

: the destination scope.`dst_scope`

: the source scope.`src_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).`reuse_dst_scope`

##### 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:

: if the targets are not connected to replacement_ts.`ValueError`

`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:

: Transform._TmpInfo instance.`info`

: tensor whose input must be transformed into a place holder.`t`

##### Returns:

The tensor generated by the newly created place holder.

`tf.contrib.graph_editor.make_list_of_op(ops, check_graph=True, allow_graph=True, ignore_ts=False)`

Convert ops to a list of `tf.Operation`

.

##### Args:

: can be an iterable of`ops`

`tf.Operation`

, a`tf.Graph`

or a single operation.: if`check_graph`

`True`

check if all the operations belong to the same graph.: if`allow_graph`

`False`

a`tf.Graph`

cannot be converted.: if True, silently ignore`ignore_ts`

`tf.Tensor`

.

##### Returns:

A newly created list of `tf.Operation`

.

##### Raises:

: if ops cannot be converted to a list of`TypeError`

`tf.Operation`

or, if`check_graph`

is`True`

, if all the ops do not belong to the same graph.

`tf.contrib.graph_editor.make_list_of_t(ts, check_graph=True, allow_graph=True, ignore_ops=False)`

Convert ts to a list of `tf.Tensor`

.

##### Args:

: can be an iterable of`ts`

`tf.Tensor`

, a`tf.Graph`

or a single tensor.: if`check_graph`

`True`

check if all the tensors belong to the same graph.: if`allow_graph`

`False`

a`tf.Graph`

cannot be converted.: if`ignore_ops`

`True`

, silently ignore`tf.Operation`

.

##### Returns:

A newly created list of `tf.Tensor`

.

##### Raises:

: if`TypeError`

`ts`

cannot be converted to a list of`tf.Tensor`

or, if`check_graph`

is`True`

, if all the ops do not belong to the same graph.

`tf.contrib.graph_editor.make_placeholder_from_dtype_and_shape(dtype, shape=None, scope=None)`

Create a tf.placeholder for the Graph Editor.

Note that the correct graph scope must be set by the calling function. The placeholder is named using the function placeholder_name (with no tensor argument).

##### Args:

: the tensor type.`dtype`

: the tensor shape (optional).`shape`

: absolute scope within which to create the placeholder. None means that the scope of t is preserved. "" means the root scope.`scope`

##### Returns:

A newly created tf.placeholder.

`tf.contrib.graph_editor.make_placeholder_from_tensor(t, scope=None)`

Create a `tf.placeholder`

for the Graph Editor.

Note that the correct graph scope must be set by the calling function.

##### Args:

: a`t`

`tf.Tensor`

whose name will be used to create the placeholder (see function placeholder_name).: absolute scope within which to create the placeholder. None means that the scope of`scope`

`t`

is preserved.`""`

means the root scope.

##### Returns:

A newly created `tf.placeholder`

.

##### Raises:

: if`TypeError`

`t`

is not`None`

or a`tf.Tensor`

.

`tf.contrib.graph_editor.make_regex(obj)`

Return a compiled regular expression.

##### Args:

: a string or a regular expression.`obj`

##### Returns:

A compiled regular expression.

##### Raises:

: if obj could not be converted to a regular expression.`ValueError`

`tf.contrib.graph_editor.make_view(*args, **kwargs)`

Create a SubGraphView from selected operations and passthrough tensors.

##### Args:

: list of 1) regular expressions (compiled or not) or 2) (array of)`*args`

`tf.Operation`

3) (array of)`tf.Tensor`

. Those objects will be converted into a list of operations and a list of candidate for passthrough tensors.: keyword graph is used 1) to check that the ops and ts are from the correct graph 2) for regular expression query`**kwargs`

##### Returns:

A subgraph view.

##### Raises:

: if the optional keyword argument graph is not a`TypeError`

`tf.Graph`

or if an argument in args is not an (array of)`tf.Tensor`

or an (array of)`tf.Operation`

or a string or a regular expression.: if one of the keyword arguments is unexpected.`ValueError`

`tf.contrib.graph_editor.make_view_from_scope(scope, graph)`

Make a subgraph from a name scope.

##### Args:

: the name of the scope.`scope`

: the`graph`

`tf.Graph`

.

##### Returns:

A subgraph view representing the given scope.

`tf.contrib.graph_editor.op_type(op_types, op=None)`

Check if an op is of the given type.

##### Args:

: tuple of strings containing the types to check against. For instance: ("Add", "Const")`op_types`

: the operation to check (or None).`op`

##### Returns:

if op is not None, return True if the op is of the correct type. if op is None, return a lambda function which does the type checking.

`tf.contrib.graph_editor.ph(dtype, shape=None, scope=None)`

Create a tf.placeholder for the Graph Editor.

Note that the correct graph scope must be set by the calling function. The placeholder is named using the function placeholder_name (with no tensor argument).

##### Args:

: the tensor type.`dtype`

: the tensor shape (optional).`shape`

: absolute scope within which to create the placeholder. None means that the scope of t is preserved. "" means the root scope.`scope`

##### Returns:

A newly created tf.placeholder.

`tf.contrib.graph_editor.placeholder_name(t=None, scope=None)`

Create placeholder name for the graph editor.

##### Args:

: optional tensor on which the placeholder operation's name will be based on`t`

: absolute scope with which to prefix the placeholder's name. None means that the scope of t is preserved. "" means the root scope.`scope`

##### Returns:

A new placeholder name prefixed by "geph". Note that "geph" stands for Graph Editor PlaceHolder. This convention allows to quickly identify the placeholder generated by the Graph Editor.

##### Raises:

: if t is not None or a tf.Tensor.`TypeError`

`tf.contrib.graph_editor.remove_control_inputs(op, cops)`

Remove the control inputs cops from co.

##### Args:

: a`op`

`tf.Operation`

from which to remove the control inputs.: an object convertible to a list of`cops`

`tf.Operation`

.

##### Raises:

: if op is not a`TypeError`

`tf.Operation`

.: if any cop in cops is not a control input of op.`ValueError`

`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:

: Transform._TmpInfo instance.`info`

: tensor whose input must be transformed into a place holder.`t`

##### Returns:

The tensor generated by the newly created place holder.

`tf.contrib.graph_editor.reroute_inputs(sgv0, sgv1)`

Re-route all the inputs of sgv0 to sgv1 (see reroute_inputs).

`tf.contrib.graph_editor.reroute_ios(sgv0, sgv1)`

Re-route the inputs and outputs of sgv0 to sgv1 (see _reroute).

`tf.contrib.graph_editor.reroute_outputs(sgv0, sgv1)`

Re-route all the outputs of sgv0 to sgv1 (see _reroute_outputs).

`tf.contrib.graph_editor.reroute_ts(ts0, ts1, can_modify=None, cannot_modify=None)`

For each tensor's pair, replace the end of t1 by the end of t0.

B0 B1 B0 B1 | | => |/ A0 A1 A0 A1

The end of the tensors in ts1 are left dangling.

##### Args:

: an object convertible to a list of`ts0`

`tf.Tensor`

.: an object convertible to a list of`ts1`

`tf.Tensor`

.: iterable of operations which can be modified. Any operation outside within_ops will be left untouched by this function.`can_modify`

: iterable of operations which cannot be modified. Any operation within cannot_modify will be left untouched by this function.`cannot_modify`

##### Returns:

The number of individual modifications made by the function.

##### Raises:

: if ts0 or ts1 cannot be converted to a list of tf.Tensor.`TypeError`

: if can_modify or cannot_modify is not None and cannot be converted to a list of tf.Operation.`TypeError`

`tf.contrib.graph_editor.select_ops(*args, **kwargs)`

Helper to select operations.

##### Args:

: list of 1) regular expressions (compiled or not) or 2) (array of)`*args`

`tf.Operation`

.`tf.Tensor`

instances are silently ignored.: 'graph':`**kwargs`

`tf.Graph`

in which to perform the regex query.This is required when using regex. 'positive_filter': an elem if selected only if`positive_filter(elem)`

is`True`

. This is optional. 'restrict_ops_regex': a regular expression is ignored if it doesn't start with the substring "(?#ops)".

##### Returns:

A list of `tf.Operation`

.

##### Raises:

: if the optional keyword argument graph is not a`TypeError`

`tf.Graph`

or if an argument in args is not an (array of)`tf.Operation`

or an (array of)`tf.Tensor`

(silently ignored) or a string or a regular expression.: if one of the keyword arguments is unexpected or if a regular expression is used without passing a graph as a keyword argument.`ValueError`

`tf.contrib.graph_editor.select_ops_and_ts(*args, **kwargs)`

Helper to select operations and tensors.

##### Args:

: list of 1) regular expressions (compiled or not) or 2) (array of)`*args`

`tf.Operation`

3) (array of) tf.Tensor. Regular expressions matching tensors must start with the comment`"(?#ts)"`

, for instance:`"(?#ts)^foo/.*"`

.: 'graph':`**kwargs`

`tf.Graph`

in which to perform the regex query.This is required when using regex. 'positive_filter': an elem if selected only if`positive_filter(elem)`

is`True`

. This is optional.

##### Returns:

A tuple `(ops, ts)`

where:
`ops`

is a list of `tf.Operation`

, and
`ts`

is a list of `tf.Tensor`

##### Raises:

: if the optional keyword argument graph is not a`TypeError`

`tf.Graph`

or if an argument in args is not an (array of)`tf.Tensor`

or an (array of)`tf.Operation`

or a string or a regular expression.: if one of the keyword arguments is unexpected or if a regular expression is used without passing a graph as a keyword argument.`ValueError`

`tf.contrib.graph_editor.select_ts(*args, **kwargs)`

Helper to select tensors.

##### Args:

: list of 1) regular expressions (compiled or not) or 2) (array of)`*args`

`tf.Tensor`

.`tf.Operation`

instances are silently ignored.: 'graph':`**kwargs`

`tf.Graph`

in which to perform the regex query.This is required when using regex. 'positive_filter': an elem if selected only if`positive_filter(elem)`

is`True`

. This is optional. 'restrict_ts_regex': a regular expression is ignored if it doesn't start with the substring "(?#ts)".

##### Returns:

A list of `tf.Tensor`

.

##### Raises:

: if the optional keyword argument graph is not a`TypeError`

`tf.Graph`

or if an argument in args is not an (array of)`tf.Tensor`

or an (array of)`tf.Operation`

(silently ignored) or a string or a regular expression.: if one of the keyword arguments is unexpected or if a regular expression is used without passing a graph as a keyword argument.`ValueError`

`tf.contrib.graph_editor.sgv(*args, **kwargs)`

Create a SubGraphView from selected operations and passthrough tensors.

##### Args:

: list of 1) regular expressions (compiled or not) or 2) (array of)`*args`

`tf.Operation`

3) (array of)`tf.Tensor`

. Those objects will be converted into a list of operations and a list of candidate for passthrough tensors.: keyword graph is used 1) to check that the ops and ts are from the correct graph 2) for regular expression query`**kwargs`

##### Returns:

A subgraph view.

##### Raises:

: if the optional keyword argument graph is not a`TypeError`

`tf.Graph`

or if an argument in args is not an (array of)`tf.Tensor`

or an (array of)`tf.Operation`

or a string or a regular expression.: if one of the keyword arguments is unexpected.`ValueError`

`tf.contrib.graph_editor.sgv_scope(scope, graph)`

Make a subgraph from a name scope.

##### Args:

: the name of the scope.`scope`

: the`graph`

`tf.Graph`

.

##### Returns:

A subgraph view representing the given scope.

`tf.contrib.graph_editor.swap_inputs(sgv0, sgv1)`

Swap all the inputs of sgv0 and sgv1 (see reroute_inputs).

`tf.contrib.graph_editor.swap_ios(sgv0, sgv1)`

Swap the inputs and outputs of sgv1 to sgv0 (see _reroute).

`tf.contrib.graph_editor.swap_outputs(sgv0, sgv1)`

Swap all the outputs of sgv0 and sgv1 (see _reroute_outputs).

`tf.contrib.graph_editor.swap_ts(ts0, ts1, can_modify=None, cannot_modify=None)`

For each tensor's pair, swap the end of (t0,t1).

B0 B1 B0 B1 | | => X A0 A1 A0 A1

##### Args:

: an object convertible to a list of`ts0`

`tf.Tensor`

.: an object convertible to a list of`ts1`

`tf.Tensor`

.: iterable of operations which can be modified. Any operation outside within_ops will be left untouched by this function.`can_modify`

: iterable of operations which cannot be modified. Any operation within cannot_modify will be left untouched by this function.`cannot_modify`

##### Returns:

The number of individual modifications made by the function.

##### Raises:

: if ts0 or ts1 cannot be converted to a list of tf.Tensor.`TypeError`

: if can_modify or cannot_modify is not None and cannot be converted to a list of tf.Operation.`TypeError`

`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:

: Transform._TmpInfo instance.`info`

: the optional op to transform (or ignore).`op`

: re-attach to the original op if possible, that is, if the source graph and the destination graph are the same.`keep_if_possible`

##### Returns:

The transformed op or None.