Returns the object referred to by `obj`, as an `Operation` or `Tensor`. This function validates that `obj` represents an element of this graph, and gives an informative error message if it is not. This function is the canonical way to get/validate an object of one of the allowed ty
(self, obj, allow_tensor=True, allow_operation=True)
| 3582 | return new_ops |
| 3583 | |
| 3584 | def as_graph_element(self, obj, allow_tensor=True, allow_operation=True): |
| 3585 | """Returns the object referred to by `obj`, as an `Operation` or `Tensor`. |
| 3586 | |
| 3587 | This function validates that `obj` represents an element of this |
| 3588 | graph, and gives an informative error message if it is not. |
| 3589 | |
| 3590 | This function is the canonical way to get/validate an object of |
| 3591 | one of the allowed types from an external argument reference in the |
| 3592 | Session API. |
| 3593 | |
| 3594 | This method may be called concurrently from multiple threads. |
| 3595 | |
| 3596 | Args: |
| 3597 | obj: A `Tensor`, an `Operation`, or the name of a tensor or operation. Can |
| 3598 | also be any object with an `_as_graph_element()` method that returns a |
| 3599 | value of one of these types. Note: `_as_graph_element` will be called |
| 3600 | inside the graph's lock and so may not modify the graph. |
| 3601 | allow_tensor: If true, `obj` may refer to a `Tensor`. |
| 3602 | allow_operation: If true, `obj` may refer to an `Operation`. |
| 3603 | |
| 3604 | Returns: |
| 3605 | The `Tensor` or `Operation` in the Graph corresponding to `obj`. |
| 3606 | |
| 3607 | Raises: |
| 3608 | TypeError: If `obj` is not a type we support attempting to convert |
| 3609 | to types. |
| 3610 | ValueError: If `obj` is of an appropriate type but invalid. For |
| 3611 | example, an invalid string. |
| 3612 | KeyError: If `obj` is not an object in the graph. |
| 3613 | """ |
| 3614 | if self._finalized: |
| 3615 | return self._as_graph_element_locked(obj, allow_tensor, allow_operation) |
| 3616 | |
| 3617 | with self._lock: |
| 3618 | return self._as_graph_element_locked(obj, allow_tensor, allow_operation) |
| 3619 | |
| 3620 | def _as_graph_element_locked(self, obj, allow_tensor, allow_operation): |
| 3621 | """See `Graph.as_graph_element()` for details.""" |