當前位置: 首頁>>代碼示例>>Python>>正文


Python caffe_pb2.BlobProto方法代碼示例

本文整理匯總了Python中caffe.proto.caffe_pb2.BlobProto方法的典型用法代碼示例。如果您正苦於以下問題:Python caffe_pb2.BlobProto方法的具體用法?Python caffe_pb2.BlobProto怎麽用?Python caffe_pb2.BlobProto使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在caffe.proto.caffe_pb2的用法示例。


在下文中一共展示了caffe_pb2.BlobProto方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_missing_biases

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import BlobProto [as 別名]
def add_missing_biases(caffenet_weights):
    for layer in caffenet_weights.layer:
        if layer.type == 'Convolution' and len(layer.blobs) == 1:
            num_filters = layer.blobs[0].shape.dim[0]
            bias_blob = caffe_pb2.BlobProto()
            bias_blob.data.extend(np.zeros(num_filters))
            bias_blob.num, bias_blob.channels, bias_blob.height = 1, 1, 1
            bias_blob.width = num_filters
            layer.blobs.extend([bias_blob]) 
開發者ID:yihui-he,項目名稱:KL-Loss,代碼行數:11,代碼來源:pickle_caffe_blobs.py

示例2: array_to_blobproto

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import BlobProto [as 別名]
def array_to_blobproto(arr, diff=None):
    """Converts a 4-dimensional array to blob proto. If diff is given, also
    convert the diff. You need to make sure that arr and diff have the same
    shape, and this function does not do sanity check.
    """
    if arr.ndim != 4:
        raise ValueError('Incorrect array shape.')
    blob = caffe_pb2.BlobProto()
    blob.num, blob.channels, blob.height, blob.width = arr.shape
    blob.data.extend(arr.astype(float).flat)
    if diff is not None:
        blob.diff.extend(diff.astype(float).flat)
    return blob 
開發者ID:XiaohangZhan,項目名稱:mix-and-match,代碼行數:15,代碼來源:io.py

示例3: array_to_blobproto

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import BlobProto [as 別名]
def array_to_blobproto(arr, diff=None):
    """Converts a N-dimensional array to blob proto. If diff is given, also
    convert the diff. You need to make sure that arr and diff have the same
    shape, and this function does not do sanity check.
    """
    blob = caffe_pb2.BlobProto()
    blob.shape.dim.extend(arr.shape)
    blob.data.extend(arr.astype(float).flat)
    if diff is not None:
        blob.diff.extend(diff.astype(float).flat)
    return blob 
開發者ID:QinganZhao,項目名稱:Deep-Learning-Based-Structural-Damage-Detection,代碼行數:13,代碼來源:io.py

示例4: load_mean_bgr

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import BlobProto [as 別名]
def load_mean_bgr():
    """ bgr mean pixel value image, [0, 255]. [height, width, 3] """
    with open("data/ResNet_mean.binaryproto", mode='rb') as f:
        data = f.read()
    blob = caffe_pb2.BlobProto()
    blob.ParseFromString(data)

    mean_bgr = caffe.io.blobproto_to_array(blob)[0]
    assert mean_bgr.shape == (3, 224, 224)

    return mean_bgr.transpose((1, 2, 0)) 
開發者ID:ry,項目名稱:tensorflow-resnet,代碼行數:13,代碼來源:convert.py

示例5: get_transformer

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import BlobProto [as 別名]
def get_transformer(deploy_file, mean_file=None):
    """
    Returns an instance of caffe.io.Transformer

    Arguments:
    deploy_file -- path to a .prototxt file

    Keyword arguments:
    mean_file -- path to a .binaryproto file (optional)
    """
    network = caffe_pb2.NetParameter()
    with open(deploy_file) as infile:
        text_format.Merge(infile.read(), network)

    dims = network.input_dim

    t = caffe.io.Transformer(
            inputs = {'data': dims}
            )
    t.set_transpose('data', (2,0,1)) # transpose to (channels, height, width)

    # color images
    if dims[1] == 3:
        # channel swap
        t.set_channel_swap('data', (2,1,0))

    if mean_file:
        # set mean pixel
        with open(mean_file) as infile:
            blob = caffe_pb2.BlobProto()
            blob.MergeFromString(infile.read())
            if blob.HasField('shape'):
                blob_dims = blob.shape
                assert len(blob_dims) == 4, 'Shape should have 4 dimensions - shape is "%s"' % blob.shape
            elif blob.HasField('num') and blob.HasField('channels') and \
                    blob.HasField('height') and blob.HasField('width'):
                blob_dims = (blob.num, blob.channels, blob.height, blob.width)
            else:
                raise ValueError('blob does not provide shape or 4d dimensions')
            pixel = np.reshape(blob.data, blob_dims[1:]).mean(1).mean(1)
            t.set_mean('data', pixel)

    return t 
開發者ID:dropbox,項目名稱:hocrux,代碼行數:45,代碼來源:example.py


注:本文中的caffe.proto.caffe_pb2.BlobProto方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。