-
Notifications
You must be signed in to change notification settings - Fork 36
/
collate.py
52 lines (43 loc) · 1.41 KB
/
collate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from argparse import ArgumentParser
from pathlib import Path
import pickle
import numpy as np
from tqdm import tqdm
def collate(root, size: str):
targets = [p.stem for p in (root / size / "full").iterdir()]
Y_np = np.array(
[
np.load(root / size / "full" / f"{target}.npy")
for target in tqdm(targets, "no pruning", leave=False)
]
)
Y_p = np.array(
[
np.load(root / size / "prune" / f"{target}.npy")
for target in tqdm(targets, "pruning", leave=False)
]
)
return Y_np, Y_p, targets
def main():
parser = ArgumentParser()
parser.add_argument(
"root", metavar="ROOT", type=Path, help="the root directory containing all DOCKSTRING runs"
)
parser.add_argument(
"-s", "--sizes", nargs="+", required=True, help="the batch sizes to process"
)
parser.add_argument(
"-o",
"--output",
default=Path("dockstring"),
type=Path,
help="the base output filename. Files will be named OUTPUT-SIZE-{Y,targets}.{npy,pkl}",
)
args = parser.parse_args()
for size in tqdm(args.sizes, "sizes", leave=False):
Y_np, Y_p, targets = collate(args.root, size)
Y = np.stack((Y_np, Y_p))
np.save(f"{args.output}-{size}-Y.npy", Y)
Path(f"{args.output}-{size}-targets.pkl").write_bytes(pickle.dumps(targets))
if __name__ == "__main__":
main()