-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_mean.py
executable file
·38 lines (29 loc) · 1.01 KB
/
compute_mean.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
#!/usr/bin/env python
import argparse
import sys
import numpy as np
import chainer
def compute_mean(dataset):
print('compute mean image')
sum_image = 0
N = len(dataset)
for i, (image, _) in enumerate(dataset):
sum_image += image
sys.stderr.write('{} / {}\r'.format(i, N))
sys.stderr.flush()
sys.stderr.write('\n')
return sum_image / N
def main():
parser = argparse.ArgumentParser(description='Compute images mean array')
parser.add_argument('dataset',
help='Path to training image-label list file')
parser.add_argument('--root', '-R', default='.',
help='Root directory path of image files')
parser.add_argument('--output', '-o', default='mean.npy',
help='path to output mean array')
args = parser.parse_args()
dataset = chainer.datasets.LabeledImageDataset(args.dataset, args.root)
mean = compute_mean(dataset)
np.save(args.output, mean)
if __name__ == '__main__':
main()