本文整理汇总了Python中caffe2.proto.caffe2_pb2.TensorProto方法的典型用法代码示例。如果您正苦于以下问题:Python caffe2_pb2.TensorProto方法的具体用法?Python caffe2_pb2.TensorProto怎么用?Python caffe2_pb2.TensorProto使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caffe2.proto.caffe2_pb2
的用法示例。
在下文中一共展示了caffe2_pb2.TensorProto方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dtype_name_to_id
# 需要导入模块: from caffe2.proto import caffe2_pb2 [as 别名]
# 或者: from caffe2.proto.caffe2_pb2 import TensorProto [as 别名]
def dtype_name_to_id(name):
return TensorProto.DataType.Value(name)
示例2: dtype_id_to_name
# 需要导入模块: from caffe2.proto import caffe2_pb2 [as 别名]
# 或者: from caffe2.proto.caffe2_pb2 import TensorProto [as 别名]
def dtype_id_to_name(dtype_int):
return fixstr(TensorProto.DataType.Name(dtype_int))
示例3: remove_spatial_bn_layers
# 需要导入模块: from caffe2.proto import caffe2_pb2 [as 别名]
# 或者: from caffe2.proto.caffe2_pb2 import TensorProto [as 别名]
def remove_spatial_bn_layers(caffenet, caffenet_weights):
# Layer types associated with spatial batch norm
remove_types = ['BatchNorm', 'Scale']
def _remove_layers(net):
for i in reversed(range(len(net.layer))):
if net.layer[i].type in remove_types:
net.layer.pop(i)
# First remove layers from caffenet proto
_remove_layers(caffenet)
# We'll return these so we can save the batch norm parameters
bn_layers = [
layer for layer in caffenet_weights.layer if layer.type in remove_types
]
_remove_layers(caffenet_weights)
def _create_tensor(arr, shape, name):
t = caffe2_pb2.TensorProto()
t.name = name
t.data_type = caffe2_pb2.TensorProto.FLOAT
t.dims.extend(shape.dim)
t.float_data.extend(arr)
assert len(t.float_data) == np.prod(t.dims), 'Data size, shape mismatch'
return t
bn_tensors = []
for (bn, scl) in zip(bn_layers[0::2], bn_layers[1::2]):
assert bn.name[len('bn'):] == scl.name[len('scale'):], 'Pair mismatch'
blob_out = 'res' + bn.name[len('bn'):] + '_bn'
bn_mean = np.asarray(bn.blobs[0].data)
bn_var = np.asarray(bn.blobs[1].data)
scale = np.asarray(scl.blobs[0].data)
bias = np.asarray(scl.blobs[1].data)
std = np.sqrt(bn_var + 1e-5)
new_scale = scale / std
new_bias = bias - bn_mean * scale / std
new_scale_tensor = _create_tensor(
new_scale, bn.blobs[0].shape, blob_out + '_s'
)
new_bias_tensor = _create_tensor(
new_bias, bn.blobs[0].shape, blob_out + '_b'
)
bn_tensors.extend([new_scale_tensor, new_bias_tensor])
return bn_tensors