本文整理汇总了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
示例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
示例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()))
示例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()))
示例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