Find corresponding op/tensor in a different graph. Args: target: A `tf.Tensor` or a `tf.Operation` belonging to the original graph. dst_graph: The graph in which the corresponding graph element must be found. dst_scope: A scope which is prepended to the name to look for. src_scope
(target, dst_graph, dst_scope="", src_scope="")
| 504 | |
| 505 | |
| 506 | def find_corresponding_elem(target, dst_graph, dst_scope="", src_scope=""): |
| 507 | """Find corresponding op/tensor in a different graph. |
| 508 | |
| 509 | Args: |
| 510 | target: A `tf.Tensor` or a `tf.Operation` belonging to the original graph. |
| 511 | dst_graph: The graph in which the corresponding graph element must be found. |
| 512 | dst_scope: A scope which is prepended to the name to look for. |
| 513 | src_scope: A scope which is removed from the original of `target` name. |
| 514 | |
| 515 | Returns: |
| 516 | The corresponding tf.Tensor` or a `tf.Operation`. |
| 517 | |
| 518 | Raises: |
| 519 | ValueError: if `src_name` does not start with `src_scope`. |
| 520 | TypeError: if `target` is not a `tf.Tensor` or a `tf.Operation` |
| 521 | KeyError: If the corresponding graph element cannot be found. |
| 522 | """ |
| 523 | src_name = target.name |
| 524 | if src_scope: |
| 525 | src_scope = scope_finalize(src_scope) |
| 526 | if not src_name.startswidth(src_scope): |
| 527 | raise ValueError("{} does not start with {}".format(src_name, src_scope)) |
| 528 | src_name = src_name[len(src_scope):] |
| 529 | |
| 530 | dst_name = src_name |
| 531 | if dst_scope: |
| 532 | dst_scope = scope_finalize(dst_scope) |
| 533 | dst_name = dst_scope + dst_name |
| 534 | |
| 535 | if isinstance(target, tf_ops.Tensor): |
| 536 | return dst_graph.get_tensor_by_name(dst_name) |
| 537 | if isinstance(target, tf_ops.Operation): |
| 538 | return dst_graph.get_operation_by_name(dst_name) |
| 539 | raise TypeError("Expected tf.Tensor or tf.Operation, got: {}", type(target)) |
| 540 | |
| 541 | |
| 542 | def find_corresponding(targets, dst_graph, dst_scope="", src_scope=""): |
no test coverage detected