当前位置: 首页>>代码示例>>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;未经允许,请勿转载。