本文整理汇总了Python中caffe.proto方法的典型用法代码示例。如果您正苦于以下问题:Python caffe.proto方法的具体用法?Python caffe.proto怎么用?Python caffe.proto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caffe
的用法示例。
在下文中一共展示了caffe.proto方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: protoBlobFileToND
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import proto [as 别名]
def protoBlobFileToND(proto_file):
data = ''
file = open(proto_file, "r")
if not file:
raise Exception("ERROR (" + proto_file + ")!")
data = file.read()
file.close()
if caffe_flag:
mean_blob = caffe.proto.caffe_pb2.BlobProto()
else:
mean_blob = caffe_parse.caffe_pb2.BlobProto()
mean_blob.ParseFromString(data)
img_mean_np = np.array(mean_blob.data)
img_mean_np = img_mean_np.reshape(
mean_blob.channels, mean_blob.height, mean_blob.width
)
# swap channels from Caffe BGR to RGB
img_mean_np2 = img_mean_np
img_mean_np[0] = img_mean_np2[2]
img_mean_np[2] = img_mean_np2[0]
return mx.nd.array(img_mean_np)
示例2: read_prototxt
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import proto [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 [as 别名]
# 或者: from caffe import proto [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 [as 别名]
# 或者: from caffe import proto [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)
示例5: get_caffe_pb
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import proto [as 别名]
def get_caffe_pb():
"""
Get caffe protobuf.
Returns:
The imported caffe protobuf module.
"""
dir = get_dataset_path('caffe')
caffe_pb_file = os.path.join(dir, 'caffe_pb2.py')
if not os.path.isfile(caffe_pb_file):
download(CAFFE_PROTO_URL, dir)
assert os.path.isfile(os.path.join(dir, 'caffe.proto'))
cmd = "protoc --version"
version, ret = subproc_call(cmd, timeout=3)
if ret != 0:
sys.exit(1)
try:
version = version.decode('utf-8')
version = float('.'.join(version.split(' ')[1].split('.')[:2]))
assert version >= 2.7, "Require protoc>=2.7 for Python3"
except Exception:
logger.exception("protoc --version gives: " + str(version))
raise
cmd = 'cd {} && protoc caffe.proto --python_out .'.format(dir)
ret = os.system(cmd)
assert ret == 0, \
"Command `{}` failed!".format(cmd)
assert os.path.isfile(caffe_pb_file), caffe_pb_file
import imp
return imp.load_source('caffepb', caffe_pb_file)
示例6: read_proto_solver_file
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import proto [as 别名]
def read_proto_solver_file(file_path):
solver_config = ''
if caffe_flag:
solver_config = caffe.proto.caffe_pb2.NetParameter()
else:
solver_config = caffe_parse.caffe_pb2.NetParameter()
return read_proto_file(file_path, solver_config)
示例7: get_caffe_pb
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import proto [as 别名]
def get_caffe_pb():
dir = get_dataset_path('caffe')
caffe_pb_file = os.path.join(dir, 'caffe_pb2.py')
if not os.path.isfile(caffe_pb_file):
proto_path = download(CAFFE_PROTO_URL, dir)
ret = os.system('cd {} && protoc caffe.proto --python_out .'.format(dir))
assert ret == 0, \
"caffe proto compilation failed! Did you install protoc?"
import imp
return imp.load_source('caffepb', caffe_pb_file)
示例8: get_layer_list
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import proto [as 别名]
def get_layer_list(self):
try:
from caffe.proto import caffe_pb2
layer = caffe_pb2.LayerParameter()
param_list = [f.name for f in layer.DESCRIPTOR.fields if f.name.endswith('_param')]
layer_list = [type(getattr(layer, s)).__name__ for s in param_list]
layer_list = [s[:-len('Parameter')] for s in layer_list]
return layer_list
except:
return []
示例9: get_caffe_pb
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import proto [as 别名]
def get_caffe_pb():
"""
Get caffe protobuf.
Returns:
The imported caffe protobuf module.
"""
dir = get_dataset_path('caffe')
caffe_pb_file = os.path.join(dir, 'caffe_pb2.py')
if not os.path.isfile(caffe_pb_file):
download(CAFFE_PROTO_URL, dir)
assert os.path.isfile(os.path.join(dir, 'caffe.proto'))
if sys.version_info.major == 3:
cmd = "protoc --version"
version, ret = subproc_call(cmd, timeout=3)
if ret != 0:
sys.exit(1)
try:
version = version.decode('utf-8')
version = float('.'.join(version.split(' ')[1].split('.')[:2]))
assert version >= 2.7, "Require protoc>=2.7 for Python3"
except Exception:
logger.exception("protoc --version gives: " + str(version))
raise
cmd = 'cd {} && protoc caffe.proto --python_out .'.format(dir)
ret = os.system(cmd)
assert ret == 0, \
"Command `{}` failed!".format(cmd)
assert os.path.isfile(caffe_pb_file), caffe_pb_file
import imp
return imp.load_source('caffepb', caffe_pb_file)