aws_lambda/pytorch/source/caffe2/python/onnx/onnxifi.py
def onnxifi_caffe2_net(
        pred_net,
        input_shapes,
        infer_shapes=False,
        debug=False):
    """
    Transform the caffe2_net by collapsing ONNXIFI-runnable nodes into Onnxifi c2 ops
    """
    # Inject an fake input tensor to help popluate the shape if we
    # do not do shape inference
    shape_hints = {}
    external_inputs = []
    if not infer_shapes:
        for k, v in input_shapes.items():
            need_input_tensor = True
            if workspace.HasBlob(k):
                itensor = workspace.FetchBlob(k)
                if itensor.shape == v:
                    need_input_tensor = False
            if need_input_tensor:
                workspace.FeedBlob(k, np.random.randn(*v).astype(np.float32))
                external_inputs.append(k)

    for k, v in input_shapes.items():
        shape_hints[k] = v
    pred_net_str = C.onnxifi(pred_net.SerializeToString(),
                             external_inputs,
                             shape_hints,
                             infer_shapes,
                             debug)
    pred_net_cut = caffe2_pb2.NetDef()
    pred_net_cut.ParseFromString(pred_net_str)
    return pred_net_cut

    Transform the caffe2_net by collapsing ONNXIFI-runnable nodes into Onnxifi c2 ops
    
Transform the caffe2_net by collapsing ONNXIFI-runnable nodes into Onnxifi c2 ops
Transform the caffe2_net by collapsing ONNXIFI - runnable nodes into Onnxifi c2 ops
def onnxifi_caffe2_net(
        pred_net,
        input_shapes,
        infer_shapes=False,
        debug=False):
    shape_hints = {}
    external_inputs = []
    if not infer_shapes:
        for k, v in input_shapes.items():
            need_input_tensor = True
            if workspace.HasBlob(k):
                itensor = workspace.FetchBlob(k)
                if itensor.shape == v:
                    need_input_tensor = False
            if need_input_tensor:
                workspace.FeedBlob(k, np.random.randn(*v).astype(np.float32))
                external_inputs.append(k)
    for k, v in input_shapes.items():
        shape_hints[k] = v
    pred_net_str = C.onnxifi(pred_net.SerializeToString(),
                             external_inputs,
                             shape_hints,
                             infer_shapes,
                             debug)
    pred_net_cut = caffe2_pb2.NetDef()
    pred_net_cut.ParseFromString(pred_net_str)
    return pred_net_cut
def onnxifi_caffe2_net ( pred_net , input_shapes , infer_shapes = False , debug = False ) : shape_hints = { } external_inputs = [ ] if not infer_shapes : for k , v in input_shapes . items ( ) : need_input_tensor = True if workspace . HasBlob ( k ) : itensor = workspace . FetchBlob ( k ) if itensor . shape == v : need_input_tensor = False if need_input_tensor : workspace . FeedBlob ( k , np . random . randn ( * v ) . astype ( np . float32 ) ) external_inputs . append ( k ) for k , v in input_shapes . items ( ) : shape_hints [ k ] = v pred_net_str = C . onnxifi ( pred_net . SerializeToString ( ) , external_inputs , shape_hints , infer_shapes , debug ) pred_net_cut = caffe2_pb2 . NetDef ( ) pred_net_cut . ParseFromString ( pred_net_str ) return pred_net_cut
Transform the caffe2_net by collapsing ONNXIFI-runnable nodes into Onnxifi c2 ops
Transform the caffe2_net by collapsing ONNXIFI - runnable nodes into Onnxifi c2 ops
"""
    Transform the caffe2_net by collapsing ONNXIFI-runnable nodes into Onnxifi c2 ops
    """ # Inject an fake input tensor to help popluate the shape if we # do not do shape inference
pred_net
input_shapes
infer_shapes
debug