###前提・実現したいこと
Pycharmを使用してChainerをGPU環境で使用したい
###発生している問題・エラーメッセージ
Traceback (most recent call last): File "/home/hoge/PycharmProjects/ML/TELL/train_mnistttt", line 7, in <module> import chainer File "/home/hoge/.pyenv/versions/anaconda3-5.0.1/envs/py2/lib/python3.6/site-packages/chainer/__init__.py", line 15, in <module> from chainer import functions # NOQA File "/home/hoge/.pyenv/versions/anaconda3-5.0.1/envs/py2/lib/python3.6/site-packages/chainer/functions/__init__.py", line 105, in <module> from chainer.functions.connection.dilated_convolution_2d import dilated_convolution_2d # NOQA File "/home/hoge/.pyenv/versions/anaconda3-5.0.1/envs/py2/lib/python3.6/site-packages/chainer/functions/connection/dilated_convolution_2d.py", line 13, in <module> libcudnn = cuda.cudnn.cudnn AttributeError: module 'cupy.cudnn' has no attribute 'cudnn' Process finished with exit code 1
###該当のソースコード
Python3.6(Anaconda環境)
1from __future__ import print_function 2 3import argparse 4 5import chainer 6import chainer.functions as F 7import chainer.links as L 8from chainer import training 9from chainer.training import extensions 10 11 12 13# Network definition 14class MLP(chainer.Chain): 15 16 def __init__(self, n_units, n_out): 17 super(MLP, self).__init__() 18 with self.init_scope(): 19 # the size of the inputs to each layer will be inferred 20 self.l1 = L.Linear(None, n_units) # n_in -> n_units 21 self.l2 = L.Linear(None, n_units) # n_units -> n_units 22 self.l3 = L.Linear(None, n_out) # n_units -> n_out 23 24 def __call__(self, x): 25 h1 = F.relu(self.l1(x)) 26 h2 = F.relu(self.l2(h1)) 27 return self.l3(h2) 28 29 30def main(): 31 parser = argparse.ArgumentParser(description='Chainer example: MNIST') 32 parser.add_argument('--batchsize', '-b', type=int, default=100, 33 help='Number of images in each mini-batch') 34 parser.add_argument('--epoch', '-e', type=int, default=20, 35 help='Number of sweeps over the dataset to train') 36 parser.add_argument('--frequency', '-f', type=int, default=-1, 37 help='Frequency of taking a snapshot') 38 parser.add_argument('--gpu', '-g', type=int, default=-1, 39 help='GPU ID (negative value indicates CPU)') 40 parser.add_argument('--out', '-o', default='result', 41 help='Directory to output the result') 42 parser.add_argument('--resume', '-r', default='', 43 help='Resume the training from snapshot') 44 parser.add_argument('--unit', '-u', type=int, default=1000, 45 help='Number of units') 46 parser.add_argument('--noplot', dest='plot', action='store_false', 47 help='Disable PlotReport extension') 48 args = parser.parse_args() 49 50 print('GPU: {}'.format(args.gpu)) 51 print('# unit: {}'.format(args.unit)) 52 print('# Minibatch-size: {}'.format(args.batchsize)) 53 print('# epoch: {}'.format(args.epoch)) 54 print('') 55 56 # Set up a neural network to train 57 # Classifier reports softmax cross entropy loss and accuracy at every 58 # iteration, which will be used by the PrintReport extension below. 59 model = L.Classifier(MLP(args.unit, 10)) 60 if args.gpu >= 0: 61 # Make a specified GPU current 62 chainer.cuda.get_device_from_id(args.gpu).use() 63 model.to_gpu() # Copy the model to the GPU 64 65 # Setup an optimizer 66 optimizer = chainer.optimizers.Adam() 67 optimizer.setup(model) 68 69 # Load the MNIST dataset 70 train, test = chainer.datasets.get_mnist() 71 72 train_iter = chainer.iterators.SerialIterator(train, args.batchsize) 73 test_iter = chainer.iterators.SerialIterator(test, args.batchsize, 74 repeat=False, shuffle=False) 75 76 # Set up a trainer 77 updater = training.updater.StandardUpdater(train_iter, optimizer, device=args.gpu) 78 trainer = training.Trainer(updater, (args.epoch, 'epoch'), out=args.out) 79 80 # Evaluate the model with the test dataset for each epoch 81 trainer.extend(extensions.Evaluator(test_iter, model, device=args.gpu)) 82 83 # Dump a computational graph from 'loss' variable at the first iteration 84 # The "main" refers to the target link of the "main" optimizer. 85 trainer.extend(extensions.dump_graph('main/loss')) 86 87 # Take a snapshot for each specified epoch 88 frequency = args.epoch if args.frequency == -1 else max(1, args.frequency) 89 trainer.extend(extensions.snapshot(), trigger=(frequency, 'epoch')) 90 91 # Write a log of evaluation statistics for each epoch 92 trainer.extend(extensions.LogReport()) 93 94 # Save two plot images to the result dir 95 if args.plot and extensions.PlotReport.available(): 96 trainer.extend( 97 extensions.PlotReport(['main/loss', 'validation/main/loss'], 98 'epoch', file_name='loss.png')) 99 trainer.extend( 100 extensions.PlotReport( 101 ['main/accuracy', 'validation/main/accuracy'], 102 'epoch', file_name='accuracy.png')) 103 104 # Print selected entries of the log to stdout 105 # Here "main" refers to the target link of the "main" optimizer again, and 106 # "validation" refers to the default name of the Evaluator extension. 107 # Entries other than 'epoch' are reported by the Classifier link, called by 108 # either the updater or the evaluator. 109 trainer.extend(extensions.PrintReport( 110 ['epoch', 'main/loss', 'validation/main/loss', 111 'main/accuracy', 'validation/main/accuracy', 'elapsed_time'])) 112 113 # Print a progress bar to stdout 114 trainer.extend(extensions.ProgressBar()) 115 116 if args.resume: 117 # Resume from a snapshot 118 chainer.serializers.load_npz(args.resume, trainer) 119 120 # Run the training 121 trainer.run() 122 123 124if __name__ == '__main__': 125 main() 126
###試したこと
・Anacondaをインストール、anaconda searchでパッケージを検索してインストール
→PycharmのProject Interpreterに出てこない
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
OS:Ubuntu 16.04
Pycharm:2017.3.1
Python:3.6(Anaconda)、3.5(System)
コンソール上で上記ソースの.pyファイルを実行するとGPUにて動作する。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。