Construct a new FuncGraph. The graph will inherit its graph key, collections, seed, and distribution strategy stack from the current context or graph. Args: name: the name of the function. collections: a dictionary of collections this FuncGraph should start with. If
(self, name, collections=None, capture_by_value=None)
| 169 | """ |
| 170 | |
| 171 | def __init__(self, name, collections=None, capture_by_value=None): |
| 172 | """Construct a new FuncGraph. |
| 173 | |
| 174 | The graph will inherit its graph key, collections, seed, and distribution |
| 175 | strategy stack from the current context or graph. |
| 176 | |
| 177 | Args: |
| 178 | name: the name of the function. |
| 179 | collections: a dictionary of collections this FuncGraph should start |
| 180 | with. If not specified (None), the FuncGraph will read (but not write |
| 181 | to) the outer graph's collections that are not whitelisted, and both |
| 182 | read and write to the outer graph's collections that are whitelisted. |
| 183 | The current whitelisted collections are the global variables, the |
| 184 | local variables, and the trainable variables. |
| 185 | Defaults to None. |
| 186 | capture_by_value: An optional boolean. If True, the func graph will |
| 187 | capture Variables by value instead of reference. By default inherit |
| 188 | from outer graphs, and failing that will default to False. |
| 189 | """ |
| 190 | super(FuncGraph, self).__init__() |
| 191 | |
| 192 | self.name = name |
| 193 | self.inputs = [] |
| 194 | self.outputs = [] |
| 195 | self.control_outputs = [] |
| 196 | self.control_captures = set() |
| 197 | self.structured_input_signature = None |
| 198 | self.structured_outputs = None |
| 199 | self._weak_variables = [] |
| 200 | self._watched_variables = object_identity.ObjectIdentityWeakSet() |
| 201 | self.outer_graph = ops.get_default_graph() |
| 202 | self._captures = py_collections.OrderedDict() |
| 203 | # If not None, records the names of output args of this function. Used to |
| 204 | # preserve the output names in the signature of a serialized+deserialized |
| 205 | # function. Private at the moment mostly because it's often out of date. |
| 206 | self._output_names = None |
| 207 | # Maps arbitrary key -> (closure, nest of placeholders), where at function |
| 208 | # call time the value of closure() will be used to feed the nest of |
| 209 | # placeholders. |
| 210 | self._deferred_captures = py_collections.OrderedDict() |
| 211 | # Inherit capture-by-value from outer graph. |
| 212 | if capture_by_value is not None: |
| 213 | self.capture_by_value = capture_by_value |
| 214 | elif self.outer_graph is not None and isinstance( |
| 215 | self.outer_graph, FuncGraph): |
| 216 | self.capture_by_value = self.outer_graph.capture_by_value |
| 217 | else: |
| 218 | self.capture_by_value = False |
| 219 | |
| 220 | self._building_function = True |
| 221 | # Map from resource tensor name to last op (in program order) which uses |
| 222 | # this tensor. Used to enforce that execution order matches program order |
| 223 | # for resource tensors. |
| 224 | self._last_op_using_resource_tensor = {} |
| 225 | |
| 226 | graph = self.outer_graph |
| 227 | |
| 228 | if context.executing_eagerly(): |
nothing calls this directly
no test coverage detected