当前位置: 首页>>代码示例>>Python>>正文


Python caffe.proto方法代码示例

本文整理汇总了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) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:25,代码来源:mean_image.py

示例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 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:9,代码来源:caffe_parser.py

示例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.') 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:11,代码来源:caffe_parser.py

示例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) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:17,代码来源:caffe_parser.py

示例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) 
开发者ID:tensorpack,项目名称:dataflow,代码行数:34,代码来源:loadcaffe.py

示例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) 
开发者ID:MTCloudVision,项目名称:mxnet-dssd,代码行数:9,代码来源:convert_symbol.py

示例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) 
开发者ID:anonymous-author1,项目名称:DDRL,代码行数:12,代码来源:loadcaffe.py

示例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 [] 
开发者ID:microsoft,项目名称:MMdnn,代码行数:12,代码来源:caffe_emitter.py

示例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) 
开发者ID:microsoft,项目名称:petridishnn,代码行数:34,代码来源:loadcaffe.py


注:本文中的caffe.proto方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。