當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.MakeArgument方法代碼示例

本文整理匯總了Python中caffe2.python.utils.MakeArgument方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.MakeArgument方法的具體用法?Python utils.MakeArgument怎麽用?Python utils.MakeArgument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在caffe2.python.utils的用法示例。


在下文中一共展示了utils.MakeArgument方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_max

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def get_max(self, op, tensor, tensor_idx, tensor_name, max_name):
        global iteration_idx
        name = max_name + "_" + str(tensor_idx)
        op_hist_name = tensor_name + "_" + max_name + "_" + str(tensor_idx)

        arg = self.get_arg(op, name)
        if iteration_idx < self.kl_iter_num_for_range:
            max_min = np.array([np.max(tensor), np.min(tensor)]).astype(np.float32)
            if arg is not None:
                orig_max = arg.floats[0]
                orig_min = arg.floats[1]
                cur_max = max(orig_max, max_min[0])
                cur_min = min(orig_min, max_min[1])
                max_min = np.array([cur_max, cur_min]).astype(np.float32)
                self.remove_arg(op, name)
            # save max vaules in predict_def as operator arguments
            max_arg = utils.MakeArgument(name, max_min)
            op.arg.extend([max_arg])
        else:
            assert arg is not None
            max_val = arg.floats[0]
            min_val = arg.floats[1]
            self.get_kl_hist(tensor, min_val, max_val, op_hist_name) 
開發者ID:intel,項目名稱:optimized-models,代碼行數:25,代碼來源:calibrator.py

示例2: update_max

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def update_max(self, op, max_name, tensor_idx, tensor_name):
        """update the max data of the collected data"""
        global hist
        global hist_edges
        global iteration_idx

        name = max_name + "_" + str(tensor_idx)
        hist_name = tensor_name + "_" + max_name + "_" + str(tensor_idx)

        P_sum = iteration_idx - self.kl_iter_num_for_range
        arg = self.get_arg(op, name)
        assert arg is not None
        max_val = arg.floats[0]
        min_val = arg.floats[1]

        hist_iter = hist[hist_name]
        hist_edges_iter = hist_edges[hist_name]
        layer_max = self.get_optimal_scaling_factor(hist_iter, hist_edges_iter,
                                                    P_sum, max_val, min_val)

        self.remove_arg(op, name)
        max_arg = utils.MakeArgument(name, np.array([layer_max]).astype(np.float32))
        # save max vaules in predict_def as operator arguments
        op.arg.extend([max_arg]) 
開發者ID:intel,項目名稱:optimized-models,代碼行數:26,代碼來源:calibrator.py

示例3: check_set_pb_arg

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def check_set_pb_arg(pb, arg_name, arg_attr, arg_value, allow_override=False):
    arg = get_pb_arg(pb, arg_name)
    if arg is None:
        arg = putils.MakeArgument(arg_name, arg_value)
        assert hasattr(arg, arg_attr)
        pb.arg.extend([arg])
    if allow_override and getattr(arg, arg_attr) != arg_value:
        logger.warning(
            "Override argument {}: {} -> {}".format(arg_name, getattr(arg, arg_attr), arg_value)
        )
        setattr(arg, arg_attr, arg_value)
    else:
        assert arg is not None
        assert getattr(arg, arg_attr) == arg_value, "Existing value {}, new value {}".format(
            getattr(arg, arg_attr), arg_value
        ) 
開發者ID:facebookresearch,項目名稱:detectron2,代碼行數:18,代碼來源:shared.py

示例4: add_bbox_ops

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def add_bbox_ops(args, net, blobs):
    new_ops = []
    new_external_outputs = []

    # Operators for bboxes
    op_box = core.CreateOperator(
        "BBoxTransform",
        ['rpn_rois', 'bbox_pred', 'im_info'],
        ['pred_bbox'],
        weights=cfg.MODEL.BBOX_REG_WEIGHTS,
        apply_scale=False,
        correct_transform_coords=True,
    )
    new_ops.extend([op_box])

    blob_prob = 'cls_prob'
    blob_box = 'pred_bbox'
    op_nms = core.CreateOperator(
        "BoxWithNMSLimit",
        [blob_prob, blob_box],
        ['score_nms', 'bbox_nms', 'class_nms'],
        arg=[
            putils.MakeArgument("score_thresh", cfg.TEST.SCORE_THRESH),
            putils.MakeArgument("nms", cfg.TEST.NMS),
            putils.MakeArgument("detections_per_im", cfg.TEST.DETECTIONS_PER_IM),
            putils.MakeArgument("soft_nms_enabled", cfg.TEST.SOFT_NMS.ENABLED),
            putils.MakeArgument("soft_nms_method", cfg.TEST.SOFT_NMS.METHOD),
            putils.MakeArgument("soft_nms_sigma", cfg.TEST.SOFT_NMS.SIGMA),
        ]
    )
    new_ops.extend([op_nms])
    new_external_outputs.extend(['score_nms', 'bbox_nms', 'class_nms'])

    net.Proto().op.extend(new_ops)
    net.Proto().external_output.extend(new_external_outputs) 
開發者ID:yihui-he,項目名稱:KL-Loss,代碼行數:37,代碼來源:convert_pkl_to_pb.py

示例5: save_net

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def save_net(INIT_NET, PREDICT_NET, model) :

    with open(PREDICT_NET, 'wb') as f:
        f.write(model.net._net.SerializeToString())
    init_net = caffe2_pb2.NetDef()
    for param in model.params:
        #print param
        blob = workspace.FetchBlob(param)
        shape = blob.shape
        op = core.CreateOperator("GivenTensorFill", [], [param],arg=[ utils.MakeArgument("shape", shape),utils.MakeArgument("values", blob)])
        init_net.op.extend([op])
    init_net.op.extend([core.CreateOperator("ConstantFill", [], ["data"], shape=get_data(1)[0][0,:,:,:].shape)])
    with open(INIT_NET, 'wb') as f:
        f.write(init_net.SerializeToString()) 
開發者ID:peterneher,項目名稱:peters-stuff,代碼行數:16,代碼來源:segmentation_no_db_example.py

示例6: save_net

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def save_net(INIT_NET, PREDICT_NET, model) :

    with open(PREDICT_NET, 'wb') as f:
        f.write(model.net._net.SerializeToString())
    init_net = caffe2_pb2.NetDef()
    for param in model.params:
        blob = workspace.FetchBlob(param)
        shape = blob.shape
        op = core.CreateOperator("GivenTensorFill", [], [param],arg=[ utils.MakeArgument("shape", shape),utils.MakeArgument("values", blob)])
        init_net.op.extend([op])
    init_net.op.extend([core.CreateOperator("ConstantFill", [], ["data"], shape=(1,30,30))])
    with open(INIT_NET, 'wb') as f:
        f.write(init_net.SerializeToString()) 
開發者ID:peterneher,項目名稱:peters-stuff,代碼行數:15,代碼來源:classification_no_db_example.py

示例7: get_max_min

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def get_max_min(self, op, tensor, tensor_idx, tensor_name, name):
        #name = name + "_" + str(tensor_idx)
        arg = self.get_arg(op, name)
        max_min = np.array([np.max(tensor), min(np.min(tensor), 0)]).astype(np.float32)
        if arg is not None:
            orig_max = arg.floats[0]
            orig_min = arg.floats[1]
            cur_max = max(orig_max, max_min[0])
            cur_min = min(orig_min, max_min[1])
            max_min = np.array([cur_max, cur_min]).astype(np.float32)
            self.remove_arg(op, name)
        # save max and min vaules in predict_def as operator arguments
        max_arg = utils.MakeArgument(name, max_min)
        op.arg.extend([max_arg]) 
開發者ID:intel,項目名稱:optimized-models,代碼行數:16,代碼來源:calibrator.py

示例8: AddArgument

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def AddArgument(op, key, value):
    """Makes an argument based on the value type."""
    op.arg.extend([utils.MakeArgument(key, value)])

################################################################################
# Common translators for layers.
################################################################################ 
開發者ID:intel,項目名稱:optimized-models,代碼行數:9,代碼來源:caffe_translator.py

示例9: AddTensor

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def AddTensor(init_net, name, blob):
    ''' Create an operator to store the tensor 'blob',
        run the operator to put the blob to workspace.
        uint8 is stored as an array of string with one element.
    '''
    from caffe2.python import core, utils
    kTypeNameMapper = {
        np.dtype('float32'): "GivenTensorFill",
        np.dtype('int32'): "GivenTensorIntFill",
        np.dtype('int64'): "GivenTensorInt64Fill",
        np.dtype('uint8'): "GivenTensorStringFill",
    }

    shape = blob.shape
    values = blob
    # pass array of uint8 as a string to save storage
    # storing uint8_t has a large overhead for now
    if blob.dtype == np.dtype('uint8'):
        shape = [1]
        values = [str(blob.data)]

    op = core.CreateOperator(
        kTypeNameMapper[blob.dtype],
        [], [name],
        arg=[
            utils.MakeArgument("shape", shape),
            utils.MakeArgument("values", values),
        ]
    )
    init_net.op.extend([op]) 
開發者ID:intel,項目名稱:optimized-models,代碼行數:32,代碼來源:common_caffe2.py

示例10: CreateByOutputName

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def CreateByOutputName(init_def, index, name, shape, values, device_opts):
    from caffe2.python import core, utils
    new_op = core.CreateOperator(
               "GivenTensorFill",
               [],
               [name],
               arg=[utils.MakeArgument("shape", shape),
                    utils.MakeArgument("values", values)],
                    device_option = device_opts
    )
    init_tmp = init_def.op[index:]
    del init_def.op[index:]
    init_def.op.extend([new_op])
    init_def.op.extend(init_tmp) 
開發者ID:intel,項目名稱:optimized-models,代碼行數:16,代碼來源:common_caffe2.py

示例11: add_bbox_ops

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def add_bbox_ops(args, net, blobs):
    new_ops = []
    new_external_outputs = []

    # Operators for bboxes
    op_box = core.CreateOperator(
        "BBoxTransform",
        ["rpn_rois", "bbox_pred", "im_info"],
        ["pred_bbox"],
        weights=cfg.MODEL.BBOX_REG_WEIGHTS,
        apply_scale=False,
        correct_transform_coords=True,
    )
    new_ops.extend([op_box])

    blob_prob = "cls_prob"
    blob_box = "pred_bbox"
    op_nms = core.CreateOperator(
        "BoxWithNMSLimit",
        [blob_prob, blob_box],
        ["score_nms", "bbox_nms", "class_nms"],
        arg=[
            putils.MakeArgument("score_thresh", cfg.TEST.SCORE_THRESH),
            putils.MakeArgument("nms", cfg.TEST.NMS),
            putils.MakeArgument("detections_per_im", cfg.TEST.DETECTIONS_PER_IM),
            putils.MakeArgument("soft_nms_enabled", cfg.TEST.SOFT_NMS.ENABLED),
            putils.MakeArgument("soft_nms_method", cfg.TEST.SOFT_NMS.METHOD),
            putils.MakeArgument("soft_nms_sigma", cfg.TEST.SOFT_NMS.SIGMA),
        ],
    )
    new_ops.extend([op_nms])
    new_external_outputs.extend(["score_nms", "bbox_nms", "class_nms"])

    net.Proto().op.extend(new_ops)
    net.Proto().external_output.extend(new_external_outputs) 
開發者ID:facebookresearch,項目名稱:Detectron,代碼行數:37,代碼來源:convert_pkl_to_pb.py

示例12: FusePadConv

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import MakeArgument [as 別名]
def FusePadConv(predict_def, model_info):
    """
    For models converted from torch
    """
    pad_index = -100
    pad_indexes = []
    for i, op in enumerate(predict_def.op):
        if op.type == "PadImage":
            pad_index = i + 1
        elif op.type == "Conv" or op.type == "ConvFusion":
            if (pad_index == i):
                pad_indexes.append(i - 1)
            pad_index = -100
    rm_cnt = 0
    for j in pad_indexes:
        index = j - rm_cnt
        pad_op = predict_def.op[index]
        conv_op = predict_def.op[index + 1]
        if (pad_op.type != "PadImage" or
               (conv_op.type != "Conv" and conv_op.type != "ConvFusion")):
            logging.info("Found error in Conv compatibility!")
            continue
       
        
        if model_info["model_type"] != "prototext":
            pad_value = None
            for i in range(len(pad_op.arg)):
                if pad_op.arg[i].name == "pads":
                    pad_value = pad_op.arg[i].ints
                    max_col = max(pad_value[0], pad_value[2])
                    max_row = max(pad_value[1], pad_value[3])
                    pad_value = [max_col, max_row, max_col, max_row]
             
            from caffe2.python import core, utils
            for i in range(len(conv_op.arg)):
                if conv_op.arg[i].name == "pads":
                    del predict_def.op[index+1].arg[i]
            predict_def.op[index+1].arg.extend([utils.MakeArgument("pads", pad_value)])

        predict_def.op[index+1].input[0] = pad_op.input[0]
        # Delete pad op
        del predict_def.op[index]
        rm_cnt += 1 
    logging.warning("[OPT] Merged {} padImage ops into Conv ops by folding"
                    .format(rm_cnt)) 
開發者ID:intel,項目名稱:optimized-models,代碼行數:47,代碼來源:common_caffe2.py


注:本文中的caffe2.python.utils.MakeArgument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。