Caffe2 - Python API
A deep learning, cross platform ML framework
onnxifi.py
1 ## @package onnx
2 #Module caffe2.python.onnx.onnxifi
3 
4 """
5 ONNXIFI a Caffe2 net
6 """
7 
8 from __future__ import absolute_import
9 from __future__ import division
10 from __future__ import print_function
11 from __future__ import unicode_literals
12 
13 from caffe2.proto import caffe2_pb2
14 from caffe2.python import core, workspace
16 import numpy as np
17 
18 
19 def onnxifi_caffe2_net(
20  pred_net,
21  input_shapes,
22  max_batch_size=1,
23  max_seq_size=1,
24  debug=False,
25  use_onnx=True,
26  black_list=None):
27  """
28  Transform the caffe2_net by collapsing ONNXIFI-runnable nodes into Onnxifi c2 ops
29  """
30  shape_hints = {}
31  for k, v in input_shapes.items():
32  shape_hints[k] = v
33  pred_net_str = C.onnxifi(pred_net.SerializeToString(),
34  shape_hints,
35  black_list if black_list else [],
36  max_batch_size,
37  max_seq_size,
38  debug,
39  use_onnx)
40  pred_net_cut = caffe2_pb2.NetDef()
41  pred_net_cut.ParseFromString(pred_net_str)
42  return pred_net_cut