本文整理汇总了Python中caffe_pb2.NetParameter方法的典型用法代码示例。如果您正苦于以下问题:Python caffe_pb2.NetParameter方法的具体用法?Python caffe_pb2.NetParameter怎么用?Python caffe_pb2.NetParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caffe_pb2
的用法示例。
在下文中一共展示了caffe_pb2.NetParameter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import caffe_pb2 [as 别名]
# 或者: from caffe_pb2 import NetParameter [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('caffemodel')
parser.add_argument('output')
args = parser.parse_args()
proto_path = 'weights/pspnet101_cityscapes_713.prototxt'
n_class = 19
input_size = (713, 713)
model = PSPNetResNet101(
n_class, None, input_size)
model(np.random.uniform(size=(1, 3) + input_size).astype(np.float32))
caffe_param = caffe_pb2.NetParameter()
caffe_param.MergeFromString(open(args.caffemodel, 'rb').read())
caffe_net = text_format.Merge(
open(proto_path).read(), caffe_pb2.NetParameter())
transfer(model, caffe_param, caffe_net)
serializers.save_npz(args.output, model)
示例2: read_prototxt
# 需要导入模块: import caffe_pb2 [as 别名]
# 或者: from caffe_pb2 import NetParameter [as 别名]
def read_prototxt(fname):
"""Return a caffe_pb2.NetParameter object that defined in a prototxt file
"""
proto = caffe_pb2.NetParameter()
with open(fname, 'r') as f:
text_format.Merge(str(f.read()), proto)
return proto
示例3: get_layers
# 需要导入模块: import caffe_pb2 [as 别名]
# 或者: from caffe_pb2 import NetParameter [as 别名]
def get_layers(proto):
"""Returns layers in a caffe_pb2.NetParameter object
"""
if len(proto.layer):
return proto.layer
elif len(proto.layers):
return proto.layers
else:
raise ValueError('Invalid proto file.')
示例4: read_caffemodel
# 需要导入模块: import caffe_pb2 [as 别名]
# 或者: from caffe_pb2 import NetParameter [as 别名]
def read_caffemodel(prototxt_fname, caffemodel_fname):
"""Return a caffe_pb2.NetParameter object that defined in a binary
caffemodel file
"""
if use_caffe:
caffe.set_mode_cpu()
net = caffe.Net(prototxt_fname, caffemodel_fname, caffe.TEST)
layer_names = net._layer_names
layers = net.layers
return (layers, layer_names)
else:
proto = caffe_pb2.NetParameter()
with open(caffemodel_fname, 'rb') as f:
proto.ParseFromString(f.read())
return (get_layers(proto), None)