| # The download codes are from: https://github.com/arbabenko/GNOIMI/blob/master/downloadDeep1B.py | |
| import subprocess | |
| from pathlib import Path | |
| import argparse | |
| def process_args(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--root", default="./deep1b", help="The path to the data directory") | |
| def merge_batches(root, prefix, batch_n): | |
| """ | |
| Helper function to merge batches into a single file | |
| Args: | |
| root: The path to the data directory. | |
| prefix: "base" or "learn" | |
| batch_n: The number of batches to be downloaded | |
| """ | |
| cat = "cat " | |
| for n in range(batch_n): | |
| filename = "{}/{}_{}".format(prefix, prefix, str(n).zfill(2)) # e.g., base/base_00 | |
| cat += " " + str(root / filename) | |
| cat += " > " + str(root / f"{prefix}.fvecs") # e.g.: cat ./deep1b/base_00 ./deep1b/base_01 ... > ./deep1b/base.fvecs | |
| subprocess.run(cat, shell=True) | |
| if __name__ == '__main__': | |
| args = process_args() | |
| root = Path(args.root) | |
| root.mkdir(exist_ok=True, parents=True) # Create root directory if it doesn't exist | |
| ops = args.ops | |
| merge_batches(root, "base", 37) | |