Skip to content

Instantly share code, notes, and snippets.

@CharlesLiu7
Created September 14, 2020 12:32
Show Gist options
  • Select an option

  • Save CharlesLiu7/0496773a8a21934a746e3fd496f11e0c to your computer and use it in GitHub Desktop.

Select an option

Save CharlesLiu7/0496773a8a21934a746e3fd496f11e0c to your computer and use it in GitHub Desktop.
# -*- 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