def get_fisher_vectors_from_folder(self, folder, limit):
"""
:param str folder: Folder Name
:param int limit: Number of images to read from each folder
:return: fisher vectors for images in given folder
:rtype: np.array
"""
files = glob.glob(folder + "/*.jpg")[:limit]
with ProcessPoolExecutor() as pool:
futures = pool.map(self._worker, files)
desc = 'Creating Fisher Vectors {} images of folder {}'.format(len(files), os.path.split(folder)[-1])
futures = tqdm.tqdm(futures, total=len(files), desc=desc, unit='image', ncols=120)
vectors = [f for f in futures if f is not None and len(f) > 0]
max_shape = np.array([v.shape[0] for v in vectors]).max()
vectors = [v for v in vectors if v.shape[0] == max_shape]
# return np.array(vectors) # Can't do np.float32, because all images may not have same number of features
return np.float32(vectors)
评论列表
文章目录