Пример #1
0
def _rename_versioned_blob_in_proto(
    proto: caffe2_pb2.NetDef,
    old_name: str,
    new_name: str,
    version: int,
    ssa: List[Tuple[List[Tuple[str, int]], List[Tuple[str, int]]]],
    start_versions: Dict[str, int],
    end_versions: Dict[str, int],
):
    """ In given proto, rename all blobs with matched version """
    # Operater list
    for op, i_th_ssa in zip(proto.op, ssa):
        versioned_inputs, versioned_outputs = i_th_ssa
        for i in range(len(op.input)):
            if versioned_inputs[i] == (old_name, version):
                op.input[i] = new_name
        for i in range(len(op.output)):
            if versioned_outputs[i] == (old_name, version):
                op.output[i] = new_name
    # external_input
    if start_versions.get(old_name, 0) == version:
        for i in range(len(proto.external_input)):
            if proto.external_input[i] == old_name:
                proto.external_input[i] = new_name
    # external_output
    if end_versions.get(old_name, 0) == version:
        for i in range(len(proto.external_output)):
            if proto.external_output[i] == old_name:
                proto.external_output[i] = new_name
def fakeFp16FuseOps(net : NetDef) -> NetDef:
    net_str = net.SerializeToString()

    out_str = C.fakeFp16FuseOps(net_str)
    out_net = NetDef()
    out_net.ParseFromString(out_str)

    return out_net
Пример #3
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from caffe2.python import workspace, model_helper
from caffe2.proto.caffe2_pb2 import NetDef
import numpy as np
exec_data = "./squeezenet/exec_net.pb"
predict_data = "./squeezenet/predict_net.pb"
init_net = NetDef()
init_net.ParseFromString(open(exec_data).read())
predict_net = NetDef()
predict_net.ParseFromString(open(predict_data).read())

# print(predict_net)
predict_net.name = "myfirstnet"
init_net.name = "mynet"

workspace.CreateNet(init_net)
workspace.CreateNet(predict_net)
workspace.RunNet(predict_net.name)