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


Python utils.Caffe2TensorToNumpyArray方法代碼示例

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


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

示例1: _GetLegacyDims

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import Caffe2TensorToNumpyArray [as 別名]
def _GetLegacyDims(net, net_params, dummy_input, legacy_pad_ops):
    dim_map = {}
    ws = workspace.C.Workspace()
    for param in net_params.protos:
        ws.create_blob(param.name) \
            .feed(utils.Caffe2TensorToNumpyArray(param))
    external_input = net.op[0].input[0]
    ws.create_blob(external_input).feed(dummy_input)
    # Get dimensions with legacy pad
    for i in range(len(net.op)):
        op_def = net.op[i]
        ws._run_operator(op_def.SerializeToString())
        if i in legacy_pad_ops:
            output = op_def.output[0]
            blob_legacy = ws.fetch_blob(output)
            dim_map[i] = blob_legacy.shape
    return dim_map 
開發者ID:intel,項目名稱:optimized-models,代碼行數:19,代碼來源:caffe_translator.py

示例2: _GetBlobDimMap

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import Caffe2TensorToNumpyArray [as 別名]
def _GetBlobDimMap(net, net_params, dummy_input):
    dim_map = {}
    ws = workspace.C.Workspace()
    for param in net_params.protos:
        ws.create_blob(param.name) \
          .feed(utils.Caffe2TensorToNumpyArray(param))
    external_input = net.op[0].input[0]
    ws.create_blob(external_input).feed(dummy_input)
    # Get dimensions with legacy pad
    for i in range(len(net.op)):
        op_def = net.op[i]
        ws._run_operator(op_def.SerializeToString())
        for output in op_def.output:
            blob = ws.fetch_blob(output)
            dim_map[output] = blob.shape
    return dim_map 
開發者ID:intel,項目名稱:optimized-models,代碼行數:18,代碼來源:caffe_translator.py

示例3: pickle_weights

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import Caffe2TensorToNumpyArray [as 別名]
def pickle_weights(out_file_name, weights):
    blobs = {
        normalize_resnet_name(blob.name): utils.Caffe2TensorToNumpyArray(blob)
        for blob in weights.protos
    }
    save_object(blobs, out_file_name)
    print('Wrote blobs:')
    print(sorted(blobs.keys())) 
開發者ID:yihui-he,項目名稱:KL-Loss,代碼行數:10,代碼來源:pickle_caffe_blobs.py

示例4: pickle_weights

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import Caffe2TensorToNumpyArray [as 別名]
def pickle_weights(out_file_name, weights):
    blobs = {
        normalize_resnet_name(blob.name): utils.Caffe2TensorToNumpyArray(blob)
        for blob in weights.protos
    }
    with open(out_file_name, 'w') as f:
        pickle.dump(blobs, f, protocol=pickle.HIGHEST_PROTOCOL)
    print('Wrote blobs:')
    print(sorted(blobs.keys())) 
開發者ID:fyangneil,項目名稱:Clustered-Object-Detection-in-Aerial-Image,代碼行數:11,代碼來源:pickle_caffe_blobs.py

示例5: _RemoveLegacyPad

# 需要導入模塊: from caffe2.python import utils [as 別名]
# 或者: from caffe2.python.utils import Caffe2TensorToNumpyArray [as 別名]
def _RemoveLegacyPad(net, net_params, input_dims):
    legacy_pad_ops = []
    for i in range(len(net.op)):
        op_def = net.op[i]
        if re.match(r'^(Conv|ConvTranspose|MaxPool|AveragePool)(\dD)?$',
                    op_def.type):
            for arg in op_def.arg:
                if arg.name == 'legacy_pad':
                    legacy_pad_ops.append(i)
                    break
    if legacy_pad_ops:
        n, c, h, w = input_dims
        dummy_input = np.random.randn(n, c, h, w).astype(np.float32)
        dim_map = _GetLegacyDims(net, net_params, dummy_input, legacy_pad_ops)

        # Running with the legacy pad argument removed
        # compare the dimensions and adjust pad argument when necessary
        ws = workspace.C.Workspace()

        external_input = net.op[0].input[0]
        ws.create_blob(external_input).feed_blob(dummy_input)
        for param in net_params.protos:
            ws.create_blob(param.name) \
              .feed_blob(utils.Caffe2TensorToNumpyArray(param))

        for i in range(len(net.op)):
            op_def = net.op[i]
            if i in legacy_pad_ops:
                arg_map = {}
                for arg in op_def.arg:
                    arg_map[arg.name] = arg
                pads = _GetLegacyPadArgs(op_def, arg_map)
                # remove legacy pad arg
                for j in range(len(op_def.arg)):
                    arg = op_def.arg[j]
                    if arg.name == 'legacy_pad':
                        del op_def.arg[j]
                        break
                output = op_def.output[0]
                # use a new name to avoid the interference with inplace
                nonlegacy_output = output + '_nonlegacy'
                op_def.output[0] = nonlegacy_output
                ws._run_operator(op_def.SerializeToString())
                blob_nonlegacy = ws.fetch_blob(nonlegacy_output)
                # reset output name
                op_def.output[0] = output

                dim1 = dim_map[i]
                dim2 = blob_nonlegacy.shape
                _AdjustDims(op_def, arg_map, pads, dim1, dim2)

            ws._run_operator(op_def.SerializeToString())
    return net 
開發者ID:intel,項目名稱:optimized-models,代碼行數:55,代碼來源:caffe_translator.py


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