Retrieves Graph element.
(obj)
| 1352 | |
| 1353 | |
| 1354 | def _as_graph_element(obj): |
| 1355 | """Retrieves Graph element.""" |
| 1356 | graph = ops.get_default_graph() |
| 1357 | if not isinstance(obj, six.string_types): |
| 1358 | if not hasattr(obj, "graph") or obj.graph != graph: |
| 1359 | raise ValueError("Passed %s should have graph attribute that is equal " |
| 1360 | "to current graph %s." % (obj, graph)) |
| 1361 | return obj |
| 1362 | if ":" in obj: |
| 1363 | element = graph.as_graph_element(obj) |
| 1364 | else: |
| 1365 | element = graph.as_graph_element(obj + ":0") |
| 1366 | # Check that there is no :1 (e.g. it's single output). |
| 1367 | try: |
| 1368 | graph.as_graph_element(obj + ":1") |
| 1369 | except (KeyError, ValueError): |
| 1370 | pass |
| 1371 | else: |
| 1372 | raise ValueError("Name %s is ambiguous, " |
| 1373 | "as this `Operation` has multiple outputs " |
| 1374 | "(at least 2)." % obj) |
| 1375 | return element |
no test coverage detected