Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. def apply_op(self, op_type_name, name=None, **keywords):
  2. # pylint: disable=g-doc-args
  3. """ Add a node invoking a registered Op to a graph.
  4. (skip other explaination)
  5. """
  6. # Determine the graph context.
  7. try:
  8. g = ops._get_graph_from_inputs(_Flatten(keywords.values()))
  9. except AssertionError as e:
  10. raise RuntimeError(
  11. "Cannot determine graph for Op '%s' due to: %s"
  12. % (op_type_name, e.message))
  13. """
  14. ...
  15. (Skip detail)
  16. ...
  17. """
  18. with g.as_default(), ops.name_scope(name) as scope:
  19. """
  20. ...
  21. (Skip detail)
  22. ...
  23. """
  24. with _MaybeColocateWith(must_colocate_inputs):
  25. # Add Op to graph
  26. op = g.create_op(op_type_name, inputs, output_types, name=scope,
  27. input_types=input_types, attrs=attr_protos,
  28. op_def=op_def)
  29. if output_structure:
  30. outputs = op.outputs
  31. res = _Restructure(ops.convert_n_to_tensor(outputs), output_structure)
  32. if isinstance(res, list) and not res and op_def.is_stateful:
  33. return op
  34. else:
  35. return res
  36. else:
  37. return op
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement