本文整理汇总了Python中caffe2.python.caffe_translator.TranslateModel方法的典型用法代码示例。如果您正苦于以下问题:Python caffe_translator.TranslateModel方法的具体用法?Python caffe_translator.TranslateModel怎么用?Python caffe_translator.TranslateModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caffe2.python.caffe_translator
的用法示例。
在下文中一共展示了caffe_translator.TranslateModel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_and_convert_caffe_model
# 需要导入模块: from caffe2.python import caffe_translator [as 别名]
# 或者: from caffe2.python.caffe_translator import TranslateModel [as 别名]
def load_and_convert_caffe_model(prototxt_file_name, caffemodel_file_name):
caffenet = caffe_pb2.NetParameter()
caffenet_weights = caffe_pb2.NetParameter()
text_format.Merge(open(prototxt_file_name).read(), caffenet)
caffenet_weights.ParseFromString(open(caffemodel_file_name).read())
# C2 conv layers current require biases, but they are optional in C1
# Add zeros as biases is they are missing
add_missing_biases(caffenet_weights)
# We only care about getting parameters, so remove layers w/o parameters
remove_layers_without_parameters(caffenet, caffenet_weights)
# BatchNorm is not implemented in the translator *and* we need to fold Scale
# layers into the new C2 SpatialBN op, hence we remove the batch norm layers
# and apply custom translations code
bn_weights = remove_spatial_bn_layers(caffenet, caffenet_weights)
# Set num, channel, height and width for blobs that use shape.dim instead
normalize_shape(caffenet_weights)
# Translate the rest of the model
net, pretrained_weights = caffe_translator.TranslateModel(
caffenet, caffenet_weights
)
pretrained_weights.protos.extend(bn_weights)
return net, pretrained_weights