Type SubGraphView
Namespace tensorflow.contrib.graph_editor
Parent PythonObjectContainer
Interfaces ISubGraphView, IContextManager<T>
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 (maskedout).
* actual output: an output tensor of the subgraph, regardless of whether it is
listed in "outputs" or not (maskedout).
* hidden input: an actual input which has been maskedout using an
input remapping. In other word, a hidden input is a noninternal tensor
not listed as a input tensor and one of whose consumers belongs to
the subgraph.
* hidden output: a actual output which has been maskedout using an output
remapping. In other word, a hidden output is a noninternal 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 inplace 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 outofsync 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 outofsync 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.
Methods
 copy_dyn
 find_op_by_name_dyn
 input_index_dyn
 is_passthrough_dyn
 op_dyn
 output_index_dyn
 remap
 remap_default
 remap_default_dyn
 remap_dyn
 remap_inputs
 remap_inputs_dyn
 remap_outputs
 remap_outputs_dyn
 remap_outputs_make_unique
 remap_outputs_make_unique_dyn
 remap_outputs_to_consumers
 remap_outputs_to_consumers_dyn
 remove_unused_ops
 remove_unused_ops_dyn
Properties
Public instance methods
object copy_dyn()
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

object
 A new instance identical to the original one.
object find_op_by_name_dyn(object op_name)
Return the op named op_name.
Parameters

object
op_name  the name to search for
Returns

object
 The op named op_name.
object input_index_dyn(object t)
Find the input index corresponding to the given input tensor t.
Parameters

object
t  the input tensor of this subgraph view.
Returns

object
 The index in the self.inputs list.
object is_passthrough_dyn(object t)
Check whether a tensor is passthrough.
object op_dyn(object op_id)
Get an op by its index.
object output_index_dyn(object t)
Find the output index corresponding to given output tensor t.
Parameters

object
t  the output tensor of this subgraph view.
Returns

object
 The index in the self.outputs list.
object remap(IEnumerable<int> new_input_indices, IEnumerable<int> new_output_indices)
Remap the inputs and outputs of the subgraph. Note that this is only modifying the view: the underlying tf.Graph is not
affected.
Parameters

IEnumerable<int>
new_input_indices  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 undercomplete and must be without repetitions.

IEnumerable<int>
new_output_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 undercomplete and can have repetitions.
Returns

object
 A new modified instance of the original subgraph view with remapped inputs and outputs.
object remap_default(bool remove_input_map, bool remove_output_map)
Remap the inputs and/or outputs to the default mapping.
Parameters

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

bool
remove_output_map  if True the output map is reset to the default one.
Returns

object
 A new modified instance of the original subgraph view with its input and/or output mapping reset to the default one.
object remap_default_dyn(ImplicitContainer<T> remove_input_map, ImplicitContainer<T> remove_output_map)
Remap the inputs and/or outputs to the default mapping.
Parameters

ImplicitContainer<T>
remove_input_map  if True the input map is reset to the default one.

ImplicitContainer<T>
remove_output_map  if True the output map is reset to the default one.
Returns

object
 A new modified instance of the original subgraph view with its input and/or output mapping reset to the default one.
object remap_dyn(object new_input_indices, object new_output_indices)
Remap the inputs and outputs of the subgraph. Note that this is only modifying the view: the underlying tf.Graph is not
affected.
Parameters

object
new_input_indices  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 undercomplete and must be without repetitions.

object
new_output_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 undercomplete and can have repetitions.
Returns

object
 A new modified instance of the original subgraph view with remapped inputs and outputs.
object remap_inputs(IEnumerable<object> 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.
Parameters

IEnumerable<object>
new_input_indices  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 undercomplete and must be without repetitions.
Returns

object
 A new modified instance of the original subgraph view with remapped inputs.
object remap_inputs_dyn(object 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.
Parameters

object
new_input_indices  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 undercomplete and must be without repetitions.
Returns

object
 A new modified instance of the original subgraph view with remapped inputs.
object remap_outputs(IEnumerable<object> 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.
Parameters

IEnumerable<object>
new_output_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 undercomplete and can have repetitions.
Returns

object
 A new modified instance of the original subgraph view with remapped outputs.
object remap_outputs_dyn(object 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.
Parameters

object
new_output_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 undercomplete and can have repetitions.
Returns

object
 A new modified instance of the original subgraph view with remapped outputs.
object remap_outputs_make_unique()
Remap the outputs so that all the tensors appears only once.
object remap_outputs_make_unique_dyn()
Remap the outputs so that all the tensors appears only once.
object remap_outputs_to_consumers()
Remap the outputs to match the number of consumers.
object remap_outputs_to_consumers_dyn()
Remap the outputs to match the number of consumers.
object remove_unused_ops(bool control_inputs)
Remove unused ops.
Parameters

bool
control_inputs  if True, control inputs are used to detect used ops.
Returns

object
 A new subgraph view which only contains used operations.
object remove_unused_ops_dyn(ImplicitContainer<T> control_inputs)
Remove unused ops.
Parameters

ImplicitContainer<T>
control_inputs  if True, control inputs are used to detect used ops.
Returns

object
 A new subgraph view which only contains used operations.
Public properties
IList<object> connected_inputs get;
The connected input tensors of this subgraph view.
object connected_inputs_dyn get;
The connected input tensors of this subgraph view.
IList<object> connected_outputs get;
The connected output tensors of this subgraph view.
object connected_outputs_dyn get;
The connected output tensors of this subgraph view.
object graph get;
The underlying
tf.Graph
.
object graph_dyn get;
The underlying
tf.Graph
.
ListView inputs get;
The input tensors of this subgraph view.
object inputs_dyn get;
The input tensors of this subgraph view.
object ops get;
The operations in this subgraph view.
object ops_dyn get;
The operations in this subgraph view.
ListView outputs get;
The output tensors of this subgraph view.
object outputs_dyn get;
The output tensors of this subgraph view.
ListView passthroughs get;
The passthrough tensors, going straight from input to output.
object passthroughs_dyn get;
The passthrough tensors, going straight from input to output.