PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tensorflow/g3doc/api_docs/python/functions_and_classes/shard2/tf.contrib.graph_editor.SubGraphView.md

https://gitlab.com/admin-github-cloud/tensorflow
Markdown | 391 lines | 228 code | 163 blank | 0 comment | 0 complexity | 1d19370696fd18f5a4504902967f2162 MD5 | raw file
  1. A subgraph view on an existing tf.Graph.
  2. An instance of this class is a subgraph view on an existing tf.Graph.
  3. "subgraph" means that it can represent part of the whole tf.Graph.
  4. "view" means that it only provides a passive observation and do not to act
  5. on the tf.Graph. Note that in this documentation, the term "subgraph" is often
  6. used as substitute to "subgraph view".
  7. A subgraph contains:
  8. * a list of input tensors, accessible via the "inputs" property.
  9. * a list of output tensors, accessible via the "outputs" property.
  10. * and the operations in between, accessible via the "ops" property.
  11. An subgraph can be seen as a function F(i0, i1, ...) -> o0, o1, ... It is a
  12. function which takes as input some input tensors and returns as output some
  13. output tensors. The computation that the function performs is encoded in the
  14. operations of the subgraph.
  15. The tensors (input or output) can be of two kinds:
  16. - connected: a connected tensor connects to at least one operation contained
  17. in the subgraph. One example is a subgraph representing a single operation
  18. and its inputs and outputs: all the input and output tensors of the op
  19. are "connected".
  20. - passthrough: a passthrough tensor does not connect to any operation
  21. contained in the subgraph. One example is a subgraph representing a
  22. single tensor: this tensor is passthrough. By default a passthrough tensor is
  23. present both in the input and output tensors of the subgraph. It can however
  24. be remapped to only appear as an input (or output) only.
  25. The input and output tensors can be remapped. For instance, some input tensor
  26. can be ommited. For instance, a subgraph representing an operation with two
  27. inputs can be remapped to only take one input. Note that this does not change
  28. at all the underlying tf.Graph (remember, it is a view). It means that
  29. the other input is being ignored, or is being treated as "given".
  30. The analogy with functions can be extended like this: F(x,y) is the original
  31. function. Remapping the inputs from [x, y] to just [x] means that the subgraph
  32. now represent the function F_y(x) (y is "given").
  33. The output tensors can also be remapped. For instance, some output tensor can
  34. be ommited. Other output tensor can be duplicated as well. As mentioned
  35. before, this does not change at all the underlying tf.Graph.
  36. The analogy with functions can be extended like this: F(...)->x,y is the
  37. original function. Remapping the outputs from [x, y] to just [y,y] means that
  38. the subgraph now represent the function M(F(...)) where M is the function
  39. M(a,b)->b,b.
  40. It is useful to describe three other kind of tensors:
  41. * internal: an internal tensor is a tensor connecting operations contained
  42. in the subgraph. One example in the subgraph representing the two
  43. operations A and B connected sequentially: -> A -> B ->. The middle arrow
  44. is an internal tensor.
  45. * actual input: an input tensor of the subgraph, regardless of whether it is
  46. listed in "inputs" or not (masked-out).
  47. * actual output: an output tensor of the subgraph, regardless of whether it is
  48. listed in "outputs" or not (masked-out).
  49. * hidden input: an actual input which has been masked-out using an
  50. input remapping. In other word, a hidden input is a non-internal tensor
  51. not listed as a input tensor and one of whose consumers belongs to
  52. the subgraph.
  53. * hidden output: a actual output which has been masked-out using an output
  54. remapping. In other word, a hidden output is a non-internal tensor
  55. not listed as an output and one of whose generating operations belongs to
  56. the subgraph.
  57. Here are some usefull guarantees about an instance of a SubGraphView:
  58. * the input (or output) tensors are not internal.
  59. * the input (or output) tensors are either "connected" or "passthrough".
  60. * the passthrough tensors are not connected to any of the operation of
  61. the subgraph.
  62. Note that there is no guarantee that an operation in a subgraph contributes
  63. at all to its inputs or outputs. For instance, remapping both the inputs and
  64. outputs to empty lists will produce a subgraph which still contains all the
  65. original operations. However, the remove_unused_ops function can be used to
  66. make a new subgraph view whose operations are connected to at least one of
  67. the input or output tensors.
  68. An instance of this class is meant to be a lightweight object which is not
  69. modified in-place by the user. Rather, the user can create new modified
  70. instances of a given subgraph. In that sense, the class SubGraphView is meant
  71. to be used like an immutable python object.
  72. A common problem when using views is that they can get out-of-sync with the
  73. data they observe (in this case, a tf.Graph). This is up to the user to insure
  74. that this doesn't happen. To keep on the safe sife, it is recommended that
  75. the life time of subgraph views are kept very short. One way to achieve this
  76. is to use subgraphs within a "with make_sgv(...) as sgv:" Python context.
  77. To alleviate the out-of-sync problem, some functions are granted the right to
  78. modified subgraph in place. This is typically the case of graph manipulation
  79. functions which, given some subgraphs as arguments, can modify the underlying
  80. tf.Graph. Since this modification is likely to render the subgraph view
  81. invalid, those functions can modify the argument in place to reflect the
  82. change. For instance, calling the function swap_inputs(svg0, svg1) will modify
  83. svg0 and svg1 in place to reflect the fact that their inputs have now being
  84. swapped.
  85. - - -
  86. #### `tf.contrib.graph_editor.SubGraphView.__init__(inside_ops=(), passthrough_ts=())` {#SubGraphView.__init__}
  87. Create a subgraph containing the given ops and the "passthrough" tensors.
  88. ##### Args:
  89. * <b>`inside_ops`</b>: an object convertible to a list of tf.Operation. This list
  90. defines all the operations in the subgraph.
  91. * <b>`passthrough_ts`</b>: an object convertible to a list of tf.Tensor. This list
  92. define all the "passthrough" tensors. A passthrough tensor is a tensor
  93. which goes directly from the input of the subgraph to it output, without
  94. any intermediate operations. All the non passthrough tensors are
  95. silently ignored.
  96. ##### Raises:
  97. * <b>`TypeError`</b>: if inside_ops cannot be converted to a list of tf.Operation or
  98. if passthrough_ts cannot be converted to a list of tf.Tensor.
  99. - - -
  100. #### `tf.contrib.graph_editor.SubGraphView.connected_inputs` {#SubGraphView.connected_inputs}
  101. The connected input tensors of this subgraph view.
  102. - - -
  103. #### `tf.contrib.graph_editor.SubGraphView.connected_outputs` {#SubGraphView.connected_outputs}
  104. The connected output tensors of this subgraph view.
  105. - - -
  106. #### `tf.contrib.graph_editor.SubGraphView.consumers()` {#SubGraphView.consumers}
  107. Return a Python set of all the consumers of this subgraph view.
  108. - - -
  109. #### `tf.contrib.graph_editor.SubGraphView.copy()` {#SubGraphView.copy}
  110. Return a copy of itself.
  111. Note that this class is a "view", copying it only create another view and
  112. does not copy the underlying part of the tf.Graph.
  113. ##### Returns:
  114. A new instance identical to the original one.
  115. - - -
  116. #### `tf.contrib.graph_editor.SubGraphView.find_op_by_name(op_name)` {#SubGraphView.find_op_by_name}
  117. Return the op named op_name.
  118. ##### Args:
  119. * <b>`op_name`</b>: the name to search for
  120. ##### Returns:
  121. The op named op_name.
  122. ##### Raises:
  123. * <b>`ValueError`</b>: if the op_name could not be found.
  124. * <b>`AssertionError`</b>: if the name was found multiple time.
  125. - - -
  126. #### `tf.contrib.graph_editor.SubGraphView.graph` {#SubGraphView.graph}
  127. The underlying tf.Graph.
  128. - - -
  129. #### `tf.contrib.graph_editor.SubGraphView.input_index(t)` {#SubGraphView.input_index}
  130. Find the input index corresponding to the given input tensor t.
  131. ##### Args:
  132. * <b>`t`</b>: the input tensor of this subgraph view.
  133. ##### Returns:
  134. The index in the self.inputs list.
  135. ##### Raises:
  136. * <b>`Error`</b>: if t in not an input tensor.
  137. - - -
  138. #### `tf.contrib.graph_editor.SubGraphView.inputs` {#SubGraphView.inputs}
  139. The input tensors of this subgraph view.
  140. - - -
  141. #### `tf.contrib.graph_editor.SubGraphView.is_passthrough(t)` {#SubGraphView.is_passthrough}
  142. Check whether a tensor is passthrough.
  143. - - -
  144. #### `tf.contrib.graph_editor.SubGraphView.op(op_id)` {#SubGraphView.op}
  145. Get an op by its index.
  146. - - -
  147. #### `tf.contrib.graph_editor.SubGraphView.ops` {#SubGraphView.ops}
  148. The operations in this subgraph view.
  149. - - -
  150. #### `tf.contrib.graph_editor.SubGraphView.output_index(t)` {#SubGraphView.output_index}
  151. Find the output index corresponding to given output tensor t.
  152. ##### Args:
  153. * <b>`t`</b>: the output tensor of this subgraph view.
  154. ##### Returns:
  155. The index in the self.outputs list.
  156. ##### Raises:
  157. * <b>`Error`</b>: if t in not an output tensor.
  158. - - -
  159. #### `tf.contrib.graph_editor.SubGraphView.outputs` {#SubGraphView.outputs}
  160. The output tensors of this subgraph view.
  161. - - -
  162. #### `tf.contrib.graph_editor.SubGraphView.passthroughs` {#SubGraphView.passthroughs}
  163. The passthrough tensors, going straight from input to output.
  164. - - -
  165. #### `tf.contrib.graph_editor.SubGraphView.remap(new_input_indices=None, new_output_indices=None)` {#SubGraphView.remap}
  166. Remap the inputs and outputs of the subgraph.
  167. Note that this is only modifying the view: the underlying tf.Graph is not
  168. affected.
  169. ##### Args:
  170. * <b>`new_input_indices`</b>: an iterable of integers representing a mapping between
  171. the old inputs and the new ones. This mapping can be under-complete and
  172. must be without repetitions.
  173. * <b>`new_output_indices`</b>: an iterable of integers representing a mapping between
  174. the old outputs and the new ones. This mapping can be under-complete and
  175. can have repetitions.
  176. ##### Returns:
  177. A new modified instance of the original subgraph view with remapped
  178. inputs and outputs.
  179. - - -
  180. #### `tf.contrib.graph_editor.SubGraphView.remap_default(remove_input_map=True, remove_output_map=True)` {#SubGraphView.remap_default}
  181. Remap the inputs and/or outputs to the default mapping.
  182. ##### Args:
  183. * <b>`remove_input_map`</b>: if True the input map is reset to the default one.
  184. * <b>`remove_output_map`</b>: if True the output map is reset to the default one.
  185. ##### Returns:
  186. A new modified instance of the original subgraph view with its
  187. input and/or output mapping reset to the default one.
  188. - - -
  189. #### `tf.contrib.graph_editor.SubGraphView.remap_inputs(new_input_indices)` {#SubGraphView.remap_inputs}
  190. Remap the inputs of the subgraph.
  191. If the inputs of the original subgraph are [t0, t1, t2], remapping to [2,0]
  192. will create a new instance whose inputs is [t2, t0].
  193. Note that this is only modifying the view: the underlying tf.Graph is not
  194. affected.
  195. ##### Args:
  196. * <b>`new_input_indices`</b>: an iterable of integers representing a mapping between
  197. the old inputs and the new ones. This mapping can be under-complete and
  198. must be without repetitions.
  199. ##### Returns:
  200. A new modified instance of the original subgraph view with remapped
  201. inputs.
  202. - - -
  203. #### `tf.contrib.graph_editor.SubGraphView.remap_outputs(new_output_indices)` {#SubGraphView.remap_outputs}
  204. Remap the output of the subgraph.
  205. If the output of the original subgraph are [t0, t1, t2], remapping to
  206. [1,1,0] will create a new instance whose outputs is [t1, t1, t0].
  207. Note that this is only modifying the view: the underlying tf.Graph is not
  208. affected.
  209. ##### Args:
  210. * <b>`new_output_indices`</b>: an iterable of integers representing a mapping between
  211. the old outputs and the new ones. This mapping can be under-complete and
  212. can have repetitions.
  213. ##### Returns:
  214. A new modified instance of the original subgraph view with remapped
  215. outputs.
  216. - - -
  217. #### `tf.contrib.graph_editor.SubGraphView.remap_outputs_make_unique()` {#SubGraphView.remap_outputs_make_unique}
  218. Remap the outputs so that all the tensors appears only once.
  219. - - -
  220. #### `tf.contrib.graph_editor.SubGraphView.remap_outputs_to_consumers()` {#SubGraphView.remap_outputs_to_consumers}
  221. Remap the outputs to match the number of consumers.
  222. - - -
  223. #### `tf.contrib.graph_editor.SubGraphView.remove_unused_ops(control_inputs=True)` {#SubGraphView.remove_unused_ops}
  224. Remove unused ops.
  225. ##### Args:
  226. * <b>`control_inputs`</b>: if True, control inputs are used to detect used ops.
  227. ##### Returns:
  228. A new subgraph view which only contains used operations.