Help us understand the problem. What is going on with this article?

普通のpython実行ファイル(argparseを含むファイル)をJupyter notebookで実行するときのメモ書き

More than 3 years have passed since last update.

普通に
https://github.com/pfnet/chainer/blob/master/examples/mnist/train_mnist.py
などサンプルpythonファイルをjupyterで実行すると下記のようなエラーが出る.

usage: __main__.py [-h] [--batchsize BATCHSIZE] [--epoch EPOCH] [--gpu GPU]
                   [--out OUT] [--resume RESUME] [--unit UNIT]
__main__.py: error: unrecognized arguments: -f /run/user/2049/jupyter/kernel-84d4df02-bc59-4802-9d99-c3228bb4e71f.json
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2


/home/mil/watanabe/.pyenv/versions/anaconda3-4.2.0/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

このようにargsまわりでエラーが出る.

そんなときは"easydict"を入れて,

pip install easydict

下記のように変更すれば手っ取り早く試せる.

sample.py
# parser = argparse.ArgumentParser(description='Chainer example: MNIST')
# parser.add_argument('--batchsize', '-b', type=int, default=100,
#                     help='Number of images in each mini-batch')
# parser.add_argument('--epoch', '-e', type=int, default=20,
#                     help='Number of sweeps over the dataset to train')
# parser.add_argument('--gpu', '-g', type=int, default=-1,
#                     help='GPU ID (negative value indicates CPU)')
# parser.add_argument('--out', '-o', default='result',
#                     help='Directory to output the result')
# parser.add_argument('--resume', '-r', default='',
#                     help='Resume the training from snapshot')
# parser.add_argument('--unit', '-u', type=int, default=1000,
#                     help='Number of units')
# args = parser.parse_args()
import easydict
args = easydict.EasyDict({
        "batchsize": 100,
        "epoch": 20,
        "gpu": 0,
        "out": "result",
        "resume": False,
        "unit": 1000
})
LittleWat
ロボコンでメカ屋として機械作ってからの、機械学習の学習中〆(.. )カリカリッ!! からの swiftの学習中〆(.. )カリカリッ!!  からのフルスタックへのtry中〆(.. )カリカリッ!!
https://littlewat.hatenadiary.jp/
kddi
KDDIは、通信を中心に周辺ビジネスを拡大する「通信とライフデザインの融合」をより一層推進し、国内はもとよりグローバルにおいても、5G/IoT時代における新たな価値創造を実現し、お客さまの期待を超える新たな体験価値の提供を追求してまいります。
http://www.kddi.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした