Created
September 14, 2020 12:32
-
-
Save CharlesLiu7/0496773a8a21934a746e3fd496f11e0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: UTF-8 -*- | |
| """ | |
| Python script to read SIFT1B dataset files, including .bvecs, .ivecs, .fvecs | |
| Dataset source: http://corpus-texmex.irisa.fr/ | |
| """ | |
| import numpy as np | |
| def bvecs_read(fname): | |
| a = np.fromfile(fname, dtype=np.int32, count=1) | |
| b = np.fromfile(fname, dtype=np.uint8) | |
| d = a[0] | |
| return b.reshape(-1, d + 4)[:, 4:].copy() | |
| def ivecs_read(fname): | |
| a = np.fromfile(fname, dtype='int32') | |
| d = a[0] | |
| return a.reshape(-1, d + 1)[:, 1:].copy() | |
| def fvecs_read(fname): | |
| return ivecs_read(fname).view('float32') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment