Detach the output of a subgraph view. Args: sgv: 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. control_outputs: a util.ControlOutputs instance or None. If
(sgv, control_outputs=None)
| 99 | |
| 100 | |
| 101 | def detach_outputs(sgv, control_outputs=None): |
| 102 | """Detach the output of a subgraph view. |
| 103 | |
| 104 | Args: |
| 105 | sgv: the subgraph view to be detached. This argument is converted to a |
| 106 | subgraph using the same rules as the function subgraph.make_view. |
| 107 | Note that sgv is modified in place. |
| 108 | control_outputs: a util.ControlOutputs instance or None. If not None the |
| 109 | control outputs are also detached. |
| 110 | Returns: |
| 111 | A tuple `(sgv, output_placeholders)` where |
| 112 | `sgv` is a new subgraph view of the detached subgraph; |
| 113 | `output_placeholders` is a list of the created output placeholders. |
| 114 | Raises: |
| 115 | StandardError: if sgv cannot be converted to a SubGraphView using |
| 116 | the same rules than the function subgraph.make_view. |
| 117 | """ |
| 118 | sgv = subgraph.make_view(sgv) |
| 119 | # only select outputs with consumers |
| 120 | sgv_ = sgv.remap_outputs([output_id |
| 121 | for output_id, output_t in enumerate(sgv.outputs) |
| 122 | if output_t.consumers()]) |
| 123 | # create consumer subgraph and remap |
| 124 | consumers_sgv = subgraph.SubGraphView(sgv_.consumers()) |
| 125 | consumers_sgv = consumers_sgv.remap_inputs( |
| 126 | [input_id for input_id, input_t in enumerate(consumers_sgv.inputs) |
| 127 | if input_t in sgv_.outputs]) |
| 128 | |
| 129 | with sgv_.graph.as_default(): |
| 130 | output_placeholders = [ |
| 131 | util.make_placeholder_from_tensor(input_t) |
| 132 | for input_t in consumers_sgv.inputs |
| 133 | ] |
| 134 | |
| 135 | reroute.swap_outputs(sgv_, output_placeholders) |
| 136 | if control_outputs is not None: |
| 137 | detach_control_outputs(sgv_, control_outputs) |
| 138 | return sgv_, output_placeholders |
| 139 | |
| 140 | |
| 141 | def detach(sgv, control_inputs=False, control_outputs=None, control_ios=None): |
no test coverage detected