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