MCPcopy
hub / github.com/OpenPPL/ppq / build

Method build

ppq/parser/caffe_parser.py:37–71  ·  view source on GitHub ↗
(self, prototxt_path: str, caffemodel_path: str)

Source from the content-addressed store, hash-verified

35 return network
36
37 def build(self, prototxt_path: str, caffemodel_path: str) -> BaseGraph:
38 network = self.load_graph_and_format(prototxt_path, caffemodel_path)
39 graph = BaseGraph(name=network.name, built_from=NetworkFramework.CAFFE)
40 input_shape = get_input_shape(network)
41 input_names = list(input_shape.keys())
42
43 activation_shape = input_shape
44 top_name_set = set()
45 for layer in network.layer:
46 if layer.type not in caffe_import_map:
47 logger.error(f'{layer.type} Caffe OP is not supported in PPQ import parser yet')
48 raise NotImplementedError(f'{layer.type} Caffe OP is not supported in PPQ import parser yet')
49 input_shape = [activation_shape[k] for k in layer.bottom]
50 caffe_layer = caffe_import_map[layer.type](graph, layer, input_shape)
51 graph = caffe_layer.trans()
52 activation_shape.update([(k, v) for k, v in zip(layer.top, caffe_layer.out_shape)])
53
54 # statistic top_name and get final out var name
55 for name in layer.bottom:
56 if name in top_name_set:
57 top_name_set.remove(name)
58 for name in layer.top:
59 top_name_set.add(name)
60
61 # add input and output for graph
62 try:
63 for var_name in input_names:
64 if var_name not in graph.variables: continue
65 graph.inputs[var_name] = graph.variables[var_name]
66 for var_name in top_name_set:
67 graph.outputs[var_name] = graph.variables[var_name]
68 except KeyError as e:
69 raise KeyError(
70 'seems you got an input/output variable that is not linked to any operation.')
71 return graph

Callers

nothing calls this directly

Calls 7

load_graph_and_formatMethod · 0.95
BaseGraphClass · 0.90
get_input_shapeFunction · 0.85
errorMethod · 0.80
updateMethod · 0.80
addMethod · 0.80
transMethod · 0.45

Tested by

no test coverage detected