Return the list of external input/output of sub-graph, each element is tuple of the name and corresponding version in predict_net. external input/output is defined the same way as caffe2 NetDef.
(
predict_net: caffe2_pb2.NetDef, sub_graph_op_indices: List[int]
)
| 748 | |
| 749 | |
| 750 | def get_sub_graph_external_input_output( |
| 751 | predict_net: caffe2_pb2.NetDef, sub_graph_op_indices: List[int] |
| 752 | ) -> Tuple[List[Tuple[str, int]], List[Tuple[str, int]]]: |
| 753 | """ |
| 754 | Return the list of external input/output of sub-graph, |
| 755 | each element is tuple of the name and corresponding version in predict_net. |
| 756 | |
| 757 | external input/output is defined the same way as caffe2 NetDef. |
| 758 | """ |
| 759 | ssa, versions = core.get_ssa(predict_net) |
| 760 | |
| 761 | all_inputs = [] |
| 762 | all_outputs = [] |
| 763 | for op_id in sub_graph_op_indices: |
| 764 | all_inputs += [inp for inp in ssa[op_id][0] if inp not in all_inputs] |
| 765 | all_outputs += list(ssa[op_id][1]) # ssa output won't repeat |
| 766 | |
| 767 | # for versioned blobs, external inputs are just those blob in all_inputs |
| 768 | # but not in all_outputs |
| 769 | ext_inputs = [inp for inp in all_inputs if inp not in all_outputs] |
| 770 | |
| 771 | # external outputs are essentially outputs of this subgraph that are used |
| 772 | # outside of this sub-graph (including predict_net.external_output) |
| 773 | all_other_inputs = sum( |
| 774 | (ssa[i][0] for i in range(len(ssa)) if i not in sub_graph_op_indices), |
| 775 | [(outp, versions[outp]) for outp in predict_net.external_output], |
| 776 | ) |
| 777 | ext_outputs = [outp for outp in all_outputs if outp in set(all_other_inputs)] |
| 778 | |
| 779 | return ext_inputs, ext_outputs |
| 780 | |
| 781 | |
| 782 | class DiGraph: |
no outgoing calls
no test coverage detected