-
Notifications
You must be signed in to change notification settings - Fork 14
/
example.py
46 lines (34 loc) · 1.21 KB
/
example.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
import argparse
import numpy as np
import chainer
from chainer import cuda
from chainer import datasets
from chainer import serializers
from inception_score import Inception
from inception_score import inception_score
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--gpu', type=int, default=0)
parser.add_argument('--samples', type=int, default=-1)
parser.add_argument('--model', type=str, default='inception_score.model')
return parser.parse_args()
def main(args):
# Load trained model
model = Inception()
serializers.load_hdf5(args.model, model)
if args.gpu >= 0:
cuda.get_device(args.gpu).use()
model.to_gpu()
# Load images
train, test = datasets.get_cifar10(ndim=3, withlabel=False, scale=255.0)
# Use all 60000 images, unless the number of samples are specified
ims = np.concatenate((train, test))
if args.samples > 0:
ims = ims[:args.samples]
with chainer.no_backprop_mode(), chainer.using_config('train', False):
mean, std = inception_score(model, ims)
print('Inception score mean:', mean)
print('Inception score std:', std)
if __name__ == '__main__':
args = parse_args()
main(args)