train_mnist.py 上的 IOError

IOError on train_mnist.py

在Ubuntu15.10 64bit和python2.7上执行train_mnist.py时,报错(IOError: [Errno 2] No such file or directory: 'result/cg.dot')发生在下面。让我知道如何解决它。

survey@SURVEY-C11:~/chainer/examples/mnist$ python train_mnist.py
GPU: -1
# unit: 1000
# Minibatch-size: 100
# epoch: 20

Traceback (most recent call last):
  File "train_mnist.py", line 115, in <module>
    main()
  File "train_mnist.py", line 112, in main
    trainer.run()
  File "/home/survey/anaconda2/lib/python2.7/site-packages/chainer/training/trainer.py", line 292, in run
    entry.extension(self)
  File "/home/survey/anaconda2/lib/python2.7/site-packages/chainer/training/extensions/computational_graph.py", line 57, in dump_graph
    with open(out_path, 'w') as f:
IOError: [Errno 2] No such file or directory: 'result/cg.dot'

open(..., 'w') 不会为您创建中间目录;确保目录 result 存在。

import os
# Make sure the result directory exist
if not os.path.exists('result'):
    os.path.mkdir('result')

...