-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgenerate.py
executable file
·46 lines (35 loc) · 1.19 KB
/
generate.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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import numpy as np
import argparse
import chainer
from chainer import serializers
from chainer import Variable
from chainer import cuda
import dataset
import network
from PIL import Image
def generate():
parser = argparse.ArgumentParser()
parser.add_argument('--gpu', '-g', type=int, default=-1)
parser.add_argument('--model', '-m', type=str, default=None)
parser.add_argument('--id', '-i', type=int, default=0)
parser.add_argument('--inf', type=int, default=10)
parser.add_argument('--outf', type=int, default=10)
args = parser.parse_args()
test = dataset.MovingMnistDataset(0, 10000, args.inf, args.outf)
model = network.MovingMnistNetwork(sz=[128, 64, 64], n=2, directory="img/")
if args.model != None:
print( "loading model from " + args.model )
serializers.load_npz(args.model, model)
x, t = test[args.id]
x = np.expand_dims(x, 0)
t = np.expand_dims(t, 0)
if args.gpu >= 0:
cuda.get_device_from_id(0).use()
model.to_gpu()
x = cuda.cupy.array(x)
t = cuda.cupy.array(t)
res = model(Variable(x), Variable(t))
if __name__ == '__main__':
generate()