-
Notifications
You must be signed in to change notification settings - Fork 25
/
compute_mean_var.py
41 lines (28 loc) · 1023 Bytes
/
compute_mean_var.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
import argparse
import os
import numpy as np
from src.dataset import image_paths
from src.image_np import dct2, load_image
from src.math import log_scale, welford
def main(args):
paths = list()
for data in args.DATASETS:
paths += image_paths(data)[:args.AMOUNT]
images = map(load_image, paths)
images = map(dct2, images)
mean, var = welford(images)
os.makedirs(args.output, exist_ok=True)
np.save(open(f"{args.output}/mean.npy", "wb+"), mean)
np.save(open(f"{args.output}/var.npy", "wb+"), var)
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"AMOUNT", help="Amount of images to use", type=int)
parser.add_argument(
"DATASETS", help="Directories over which to compute.", type=str, nargs="+")
output = "saved_mean_var"
parser.add_argument(
"--output", "-o", help=f"Output direcotory. Default: {output}", default=output)
return parser.parse_args()
if __name__ == "__main__":
main(parse_args())