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


Python caffe_pb2.Datum方法代码示例

本文整理汇总了Python中caffe.proto.caffe_pb2.Datum方法的典型用法代码示例。如果您正苦于以下问题:Python caffe_pb2.Datum方法的具体用法?Python caffe_pb2.Datum怎么用?Python caffe_pb2.Datum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在caffe.proto.caffe_pb2的用法示例。


在下文中一共展示了caffe_pb2.Datum方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: array_to_datum

# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import Datum [as 别名]
def array_to_datum(arr, label=None):
    """Converts a 3-dimensional array to datum. If the array has dtype uint8,
    the output data will be encoded as a string. Otherwise, the output data
    will be stored in float format.
    """
    if arr.ndim != 3:
        raise ValueError('Incorrect array shape.')
    datum = caffe_pb2.Datum()
    datum.channels, datum.height, datum.width = arr.shape
    if arr.dtype == np.uint8:
        datum.data = arr.tostring()
    else:
        datum.float_data.extend(arr.astype(float).flat)
    if label is not None:
        datum.label = label
    return datum 
开发者ID:QinganZhao,项目名称:Deep-Learning-Based-Structural-Damage-Detection,代码行数:18,代码来源:io.py

示例2: array_to_datum

# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import Datum [as 别名]
def array_to_datum(arr, label=None):
    """Converts a 3-dimensional array to datum. If the array has dtype uint8,
    the output data will be encoded as a string. Otherwise, the output data
    will be stored in float format.
    """
    if arr.ndim != 3:
        raise ValueError('Incorrect array shape.')
    datum = caffe_pb2.Datum()
    datum.channels, datum.height, datum.width = arr.shape
    if arr.dtype == np.uint8:
        datum.data = arr.tostring()
    else:
        datum.float_data.extend(arr.flat)
    if label is not None:
        datum.label = label
    return datum 
开发者ID:TF2-Engine,项目名称:TF2,代码行数:18,代码来源:io.py

示例3: ReadPatches

# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import Datum [as 别名]
def ReadPatches(db, pairs, patch_height=64, patch_width=64):
    """Read patches from the given db handle. Each element in pairs is a
    pair of keys.

    Returns
    -------
    Two N * 1 * W * H array in a list, where N is the number of pairs.
    """
    N = len(pairs)
    patches = [np.zeros((N, 1, patch_height, patch_width),
                        dtype=np.float),
               np.zeros((N, 1, patch_height, patch_width),
                        dtype=np.float)]
    idx = 0  # Index to the next available patch in the patch array.
    parity = 0
    for pair in pairs:
        for key in pair:
            datum = caffe_pb2.Datum()
            datum.ParseFromString(db.Get(key))
            patches[parity][idx, 0, :, :] = \
                np.fromstring(datum.data, np.uint8).reshape(
                patch_height, patch_width)
            parity = 1 - parity

        idx += 1

    return patches 
开发者ID:hanxf,项目名称:matchnet,代码行数:29,代码来源:evaluate_matchnet.py

示例4: array_to_datum

# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import Datum [as 别名]
def array_to_datum(arr, label=0):
    """Converts a 3-dimensional array to datum. If the array has dtype uint8,
    the output data will be encoded as a string. Otherwise, the output data
    will be stored in float format.
    """
    if arr.ndim != 3:
        raise ValueError('Incorrect array shape.')
    datum = caffe_pb2.Datum()
    datum.channels, datum.height, datum.width = arr.shape
    if arr.dtype == np.uint8:
        datum.data = arr.tostring()
    else:
        datum.float_data.extend(arr.flat)
    datum.label = label
    return datum 
开发者ID:XiaohangZhan,项目名称:mix-and-match,代码行数:17,代码来源:io.py

示例5: forward

# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import Datum [as 别名]
def forward(self):
        return "mock this"

# class io:
#    @staticmethod
#    def array_to_datum(s):
#        return Datum() 
开发者ID:nigroup,项目名称:nideep,代码行数:9,代码来源:caffe_mock.py

示例6: main

# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import Datum [as 别名]
def main():
    # Parse input arguments.
    args = ParseArgs()

    # Read the 3Dpoint IDs from the info file.
    with open(args.info_file) as f:
        point_id = [int(line.split()[0]) for line in f]

    # Read the interest point from the interest file. The fields in each line
    # are: image_id, x, y, orientation, and scale. We parse all of them as float
    # even though image_id is integer.
    with open(args.interest_file) as f:
        interest = [[float(x) for x in line.split()] for line in f]

    # Create the output database, fail if exists.
    db = leveldb.LevelDB(args.output_db,
                         create_if_missing=True,
                         error_if_exists=True)

    # Add patches to the database in batch.
    batch = leveldb.WriteBatch()
    total = len(interest)
    processed = 0
    for i, metadata in enumerate(interest):
        datum = caffe_pb2.Datum()
        datum.channels, datum.height, datum.width = (1, 64, 64)

        # Extract the patch
        datum.data = GetPatchImage(i, args.container_dir).tostring()

        # Write 3D point ID into the label field.
        datum.label = point_id[i]

        # Write other metadata into float_data fields.
        datum.float_data.extend(metadata)
        batch.Put(str(i), datum.SerializeToString())
        processed += 1
        if processed % 1000 == 0:
            print processed, '/', total

            # Write the current batch.
            db.Write(batch, sync=True)

            # Verify the last written record.
            d = caffe_pb2.Datum()
            d.ParseFromString(db.Get(str(processed - 1)))
            assert (d.data == datum.data)

            # Start a new batch
            batch = leveldb.WriteBatch()
    db.Write(batch, sync=True) 
开发者ID:hanxf,项目名称:matchnet,代码行数:53,代码来源:generate_patch_db.py


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