當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。