MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / identify_reshape_sub_graph

Function identify_reshape_sub_graph

detectron2/export/shared.py:855–879  ·  view source on GitHub ↗

Idenfity the reshape sub-graph in a protobuf. The reshape sub-graph is defined as matching the following pattern: (input_blob) -> Op_1 -> ... -> Op_N -> (new_shape) -─┐ └-------------------------------------------> Reshape -> (output_blob) Return: List of sub-graph

(predict_net: caffe2_pb2.NetDef)

Source from the content-addressed store, hash-verified

853
854
855def identify_reshape_sub_graph(predict_net: caffe2_pb2.NetDef) -> List[List[int]]:
856 """
857 Idenfity the reshape sub-graph in a protobuf.
858 The reshape sub-graph is defined as matching the following pattern:
859
860 (input_blob) -> Op_1 -> ... -> Op_N -> (new_shape) -─┐
861 └-------------------------------------------> Reshape -> (output_blob)
862
863 Return:
864 List of sub-graphs, each sub-graph is represented as a list of indices
865 of the relavent ops, [Op_1, Op_2, ..., Op_N, Reshape]
866 """
867
868 ssa, _ = core.get_ssa(predict_net)
869
870 ret = []
871 for i, op in enumerate(predict_net.op):
872 if op.type == "Reshape":
873 assert len(op.input) == 2
874 input_ssa = ssa[i][0]
875 data_source = input_ssa[0]
876 shape_source = input_ssa[1]
877 op_indices = _get_dependency_chain(ssa, shape_source, data_source)
878 ret.append(op_indices + [i])
879 return ret
880
881
882def remove_reshape_for_fc(predict_net, params):

Callers 1

remove_reshape_for_fcFunction · 0.85

Calls 1

_get_dependency_chainFunction · 0.85

Tested by

no test coverage detected