回答編集履歴
3
fixed xp to np on code
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
```Python
|
3
3
|
if model.train:
|
4
4
|
x = chainer.Variable(np.asarray(inp[0]))
|
5
|
-
t = chainer.Variable(
|
5
|
+
t = chainer.Variable(np.asarray(inp[1]))
|
6
6
|
optimizer.update(model, x, t)
|
7
7
|
if not graph_generated:
|
8
8
|
with open('graph.dot', 'w') as o:
|
@@ -13,7 +13,7 @@
|
|
13
13
|
else:
|
14
14
|
with chainer.no_backprop_mode():
|
15
15
|
x = chainer.Variable(np.asarray(inp[0]))
|
16
|
-
t = chainer.Variable(
|
16
|
+
t = chainer.Variable(np.asarray(inp[1]))
|
17
17
|
model(x, t)
|
18
18
|
res_q.put((float(model.loss.data), float(model.accuracy.data)))
|
19
19
|
del x, t
|
2
fixed code
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
やはり,`optimizer.update()`が`with chainer.no_backprop_mode():`の中にあるのは望ましくないと思われます.
|
2
2
|
```Python
|
3
|
-
if model.train:
|
3
|
+
if model.train:
|
4
4
|
x = chainer.Variable(np.asarray(inp[0]))
|
5
5
|
t = chainer.Variable(xp.asarray(inp[1]))
|
6
6
|
optimizer.update(model, x, t)
|
1
fix code
test
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
やはり,`optimizer.update()`が`with chainer.no_backprop_mode():`の中にあるのは望ましくないと思われます.
|
2
2
|
```Python
|
3
|
+
if model.train:
|
3
|
-
x = chainer.Variable(np.asarray(inp[0]))
|
4
|
+
x = chainer.Variable(np.asarray(inp[0]))
|
4
|
-
with chainer.no_backprop_mode():
|
5
5
|
t = chainer.Variable(xp.asarray(inp[1]))
|
6
|
-
if model.train:
|
7
6
|
optimizer.update(model, x, t)
|
8
7
|
if not graph_generated:
|
9
8
|
with open('graph.dot', 'w') as o:
|
@@ -12,24 +11,10 @@
|
|
12
11
|
print('generated graph', file=sys.stderr)
|
13
12
|
graph_generated = True
|
14
13
|
else:
|
14
|
+
with chainer.no_backprop_mode():
|
15
|
+
x = chainer.Variable(np.asarray(inp[0]))
|
16
|
+
t = chainer.Variable(xp.asarray(inp[1]))
|
15
17
|
model(x, t)
|
16
18
|
res_q.put((float(model.loss.data), float(model.accuracy.data)))
|
17
19
|
del x, t
|
18
20
|
```
|
19
|
-
もしかしたら,`t`を定義するときもここから外す必要があるかも.そのときはこう.
|
20
|
-
```Python
|
21
|
-
x = chainer.Variable(np.asarray(inp[0]), volatile = not model.train)
|
22
|
-
t = chainer.Variable(xp.asarray(inp[1]), volatile = not model.train)
|
23
|
-
if model.train:
|
24
|
-
optimizer.update(model, x, t)
|
25
|
-
if not graph_generated:
|
26
|
-
with open('graph.dot', 'w') as o:
|
27
|
-
o.write(computational_graph.build_computational_graph(
|
28
|
-
(model.loss,)).dump())
|
29
|
-
print('generated graph', file=sys.stderr)
|
30
|
-
graph_generated = True
|
31
|
-
else:
|
32
|
-
model(x, t)
|
33
|
-
res_q.put((float(model.loss.data), float(model.accuracy.data)))
|
34
|
-
del x, t
|
35
|
-
```
|