本文整理匯總了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