MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / load

Method load

imperative/python/megengine/utils/network.py:64–94  ·  view source on GitHub ↗

r"""Loads a computing graph as a Network object. Args: model_path: file path of mge model. outspec: only load the subgraph with outspec as its endpoints.

(cls, model_path: str, outspec: List[str] = None)

Source from the content-addressed store, hash-verified

62
63 @classmethod
64 def load(cls, model_path: str, outspec: List[str] = None):
65 r"""Loads a computing graph as a Network object.
66
67 Args:
68 model_path: file path of mge model.
69 outspec: only load the subgraph with outspec as its endpoints.
70 """
71 self = cls()
72 ret = G.load_graph(model_path)
73 outputs, self._metadata = ret.output_vars_list, ret.metadata
74 if outspec is not None:
75 output_spec = outspec.copy()
76 all_vars = get_dep_vars(outputs) + outputs
77 new_outputs = {}
78 for i in all_vars:
79 if i.name in output_spec:
80 new_outputs[i.name] = i
81 output_spec.remove(i.name)
82 assert len(output_spec) == 0, "Can not find {} in this model".format(
83 output_spec
84 )
85 outputs = [new_outputs[i] for i in outspec]
86 self._orig_outputs = outputs
87 for x in self._orig_outputs:
88 self.output_vars.append(self._get_var(x))
89 self.add_dep_oprs()
90 for x in self._orig_inputs:
91 self.input_vars.append(self._get_var(x))
92
93 self.graph = self._orig_outputs[0].graph
94 return self
95
96 def _compile(self):
97 self.all_oprs_map = {}

Callers 15

loadFunction · 0.45
load_single_graphMethod · 0.45
mainFunction · 0.45
make_data_given_descFunction · 0.45
mainFunction · 0.45
visualizeFunction · 0.45
mainFunction · 0.45
load_single_graphFunction · 0.45
load_mem_infoFunction · 0.45
_add_oprMethod · 0.45
_get_varMethod · 0.45
load_trace_eventsFunction · 0.45

Calls 7

_get_varMethod · 0.95
add_dep_oprsMethod · 0.95
get_dep_varsFunction · 0.85
copyMethod · 0.45
removeMethod · 0.45
formatMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected