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
评论列表
文章目录