def hsh_to_patches(self, hsh):
pp = extract_patches_2d(hsh.astype(int), (self.patch_size, self.patch_size))
# flatten 2nd and 3rd dimension:
pp = pp.reshape((pp.shape[0], -1))
# extract sample of patches:
max_patches = min(self.max_patches, pp.shape[0])
rr = [pp[x] for x in np.linspace(0, pp.shape[0], max_patches, endpoint=False).astype(int)]
# pack patches into numbers:
packed = [int(binascii.b2a_hex(''.join(np.packbits(x).view('c'))) or '0', 16) for x in rr]
return packed
评论列表
文章目录