Creates a new `WhileContext` from protocol buffer. Args: context_def: `WhileContextDef` protocol buffer. import_scope: Optional `string`. Name scope to add.
(self, context_def, import_scope=None)
| 1472 | self._graph = ops.get_default_graph() |
| 1473 | |
| 1474 | def _init_from_proto(self, context_def, import_scope=None): |
| 1475 | """Creates a new `WhileContext` from protocol buffer. |
| 1476 | |
| 1477 | Args: |
| 1478 | context_def: `WhileContextDef` protocol buffer. |
| 1479 | import_scope: Optional `string`. Name scope to add. |
| 1480 | """ |
| 1481 | assert isinstance(context_def, control_flow_pb2.WhileContextDef) |
| 1482 | # Create from context_def. |
| 1483 | g = ops.get_default_graph() |
| 1484 | self._name = ops.prepend_name_scope(context_def.context_name, import_scope) |
| 1485 | if context_def.maximum_iterations_name: |
| 1486 | self._maximum_iterations = g.as_graph_element( |
| 1487 | ops.prepend_name_scope(context_def.maximum_iterations_name, |
| 1488 | import_scope)) |
| 1489 | else: |
| 1490 | self._maximum_iterations = None |
| 1491 | self._parallel_iterations = context_def.parallel_iterations |
| 1492 | self._back_prop = context_def.back_prop |
| 1493 | self._swap_memory = context_def.swap_memory |
| 1494 | self._pivot_for_pred = g.as_graph_element( |
| 1495 | ops.prepend_name_scope(context_def.pivot_for_pred_name, import_scope)) |
| 1496 | # We use this node to control constants created by the body lambda. |
| 1497 | self._pivot_for_body = g.as_graph_element( |
| 1498 | ops.prepend_name_scope(context_def.pivot_for_body_name, import_scope)) |
| 1499 | # The boolean tensor for loop termination condition. Used in code |
| 1500 | # generation for gradient computation. |
| 1501 | self._pivot = g.as_graph_element( |
| 1502 | ops.prepend_name_scope(context_def.pivot_name, import_scope)) |
| 1503 | # The list of exit tensors for loop variables. |
| 1504 | self._loop_exits = [ |
| 1505 | g.as_graph_element(ops.prepend_name_scope(exit_name, import_scope)) |
| 1506 | for exit_name in context_def.loop_exit_names |
| 1507 | ] |
| 1508 | # The list of enter tensors for loop variables. |
| 1509 | self._loop_enters = [ |
| 1510 | g.as_graph_element(ops.prepend_name_scope(enter_name, import_scope)) |
| 1511 | for enter_name in context_def.loop_enter_names |
| 1512 | ] |
| 1513 | super(WhileContext, self).__init__( |
| 1514 | values_def=context_def.values_def, import_scope=import_scope) |
| 1515 | |
| 1516 | # import_scope causes self.name to be different from the original serialized |
| 1517 | # context's name. Rewrite "frame_name" attrs with the new name. |
| 1518 | if import_scope: |
| 1519 | for tensor_name in self._values: |
| 1520 | op = g.as_graph_element(tensor_name).op |
| 1521 | if util.IsLoopEnter(op): |
| 1522 | # pylint: disable=protected-access |
| 1523 | op._set_attr("frame_name", |
| 1524 | attr_value_pb2.AttrValue(s=compat.as_bytes(self.name))) |
| 1525 | # pylint: enable=protected-access |
| 1526 | self._graph = ops.get_default_graph() |
| 1527 | |
| 1528 | @property |
| 1529 | def maximum_iterations(self): |
no test coverage detected