dump_hdf5.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:c3d-misc 作者: escorciav 项目源码 文件源码
def read_feature(filename, keep_shape=False):
    """Read feature (a.k.a blob) dump by C3D.

    Parameters
    ----------
    filename : str
        Fullpath of file to read.
    keep_shape : bool
        Reshape feature to the shape reported.

    Outputs
    -------
    feature : ndarray
        numpy array of features
    s : tuple
        shape of original feature

    Note: It accomplishes the same purpose of this code:
        C3D/examples/c3d_feature_extraction/script/read_binary_blob.m

    """
    s_parr, d_parr = array.array('i'), array.array('f')
    with open(filename, 'rb') as f:
        s_parr.fromfile(f, 5)
        s = np.array(s_parr)
        m = np.cumprod(s)[-1]

        d_parr.fromfile(f, m)

    feature = np.array(d_parr)
    if keep_shape:
        feature = feature.reshape(s)
    return feature, s
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号