質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

Chainer

Chainerは、国産の深層学習フレームワークです。あらゆるニューラルネットワークをPythonで柔軟に書くことができ、学習させることが可能。GPUをサポートしており、複数のGPUを用いた学習も直感的に記述できます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

537閲覧

windowsでcudnnを使う方法

退会済みユーザー

退会済みユーザー

総合スコア0

Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

Chainer

Chainerは、国産の深層学習フレームワークです。あらゆるニューラルネットワークをPythonで柔軟に書くことができ、学習させることが可能。GPUをサポートしており、複数のGPUを用いた学習も直感的に記述できます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

1クリップ

投稿2017/10/27 04:23

###前提・実現したいこと
windows10環境下のchainerでcudnnを用いた学習を行いたいです。

###発生している問題・エラーメッセージ
GPUを用いたプログラムの実行はできるものの、cudnnを用いた学習ができません。
環境は以下です。
OS: Windows10
CPU: core i7-7700K
GPU: nvidia GeForce GTX 1080Ti
CUDA: v9.0
CUDNN: v7.0
chainer: v3.0
実行環境: PyCharm

C:\Users\user\AppData\Local\Continuum\anaconda3\python.exe C:/Users/user/Desktop/chainer-master/examples/word2vec/train_word2vec.py C:\Users\user\AppData\Local\Continuum\anaconda3\lib\site-packages\cupy\core\fusion.py:659: FutureWarning: cupy.core.fusion is experimental. The interface can change in the future. util.experimental('cupy.core.fusion') C:\Users\user\Desktop\chainer-master\chainer\cuda.py:84: UserWarning: cuDNN is not enabled. Please reinstall CuPy after you install cudnn (see https://docs-cupy.chainer.org/en/stable/install.html#install-cupy-with-cudnn-and-nccl). 'cuDNN is not enabled.\n'

###該当のソースコード(chainer公式のword2vecプログラム)

python

1#!/usr/bin/env python 2"""Sample script of word embedding model. 3 4This code implements skip-gram model and continuous-bow model. 5""" 6import argparse 7import collections 8 9import numpy as np 10import six 11 12import chainer 13from chainer import cuda 14import chainer.functions as F 15import chainer.initializers as I 16import chainer.links as L 17import chainer.optimizers as O 18from chainer import reporter 19from chainer import training 20from chainer.training import extensions 21 22 23parser = argparse.ArgumentParser() 24parser.add_argument('--gpu', '-g', default=0, type=int, 25 help='GPU ID (negative value indicates CPU)') 26parser.add_argument('--unit', '-u', default=100, type=int, 27 help='number of units') 28parser.add_argument('--window', '-w', default=5, type=int, 29 help='window size') 30parser.add_argument('--batchsize', '-b', type=int, default=1000, 31 help='learning minibatch size') 32parser.add_argument('--epoch', '-e', default=20, type=int, 33 help='number of epochs to learn') 34parser.add_argument('--model', '-m', choices=['skipgram', 'cbow'], 35 default='skipgram', 36 help='model type ("skipgram", "cbow")') 37parser.add_argument('--negative-size', default=5, type=int, 38 help='number of negative samples') 39parser.add_argument('--out-type', '-o', choices=['hsm', 'ns', 'original'], 40 default='hsm', 41 help='output model type ("hsm": hierarchical softmax, ' 42 '"ns": negative sampling, "original": no approximation)') 43parser.add_argument('--out', default='result', 44 help='Directory to output the result') 45parser.add_argument('--test', dest='test', action='store_true') 46parser.set_defaults(test=False) 47 48args = parser.parse_args() 49 50if args.gpu >= 0: 51 chainer.cuda.get_device_from_id(args.gpu).use() 52 cuda.check_cuda_available() 53 54print('GPU: {}'.format(args.gpu)) 55print('# unit: {}'.format(args.unit)) 56print('Window: {}'.format(args.window)) 57print('Minibatch-size: {}'.format(args.batchsize)) 58print('# epoch: {}'.format(args.epoch)) 59print('Training model: {}'.format(args.model)) 60print('Output type: {}'.format(args.out_type)) 61print('') 62 63 64class ContinuousBoW(chainer.Chain): 65 66 def __init__(self, n_vocab, n_units, loss_func): 67 super(ContinuousBoW, self).__init__() 68 69 with self.init_scope(): 70 self.embed = L.EmbedID( 71 n_vocab, n_units, initialW=I.Uniform(1. / n_units)) 72 self.loss_func = loss_func 73 74 def __call__(self, x, context): 75 e = self.embed(context) 76 h = F.sum(e, axis=1) * (1. / context.shape[1]) 77 loss = self.loss_func(h, x) 78 reporter.report({'loss': loss}, self) 79 return loss 80 81 82class SkipGram(chainer.Chain): 83 84 def __init__(self, n_vocab, n_units, loss_func): 85 super(SkipGram, self).__init__() 86 87 with self.init_scope(): 88 self.embed = L.EmbedID( 89 n_vocab, n_units, initialW=I.Uniform(1. / n_units)) 90 self.loss_func = loss_func 91 92 def __call__(self, x, context): 93 e = self.embed(context) 94 shape = e.shape 95 x = F.broadcast_to(x[:, None], (shape[0], shape[1])) 96 e = F.reshape(e, (shape[0] * shape[1], shape[2])) 97 x = F.reshape(x, (shape[0] * shape[1],)) 98 loss = self.loss_func(e, x) 99 reporter.report({'loss': loss}, self) 100 return loss 101 102 103class SoftmaxCrossEntropyLoss(chainer.Chain): 104 105 def __init__(self, n_in, n_out): 106 super(SoftmaxCrossEntropyLoss, self).__init__() 107 with self.init_scope(): 108 self.out = L.Linear(n_in, n_out, initialW=0) 109 110 def __call__(self, x, t): 111 return F.softmax_cross_entropy(self.out(x), t) 112 113 114class WindowIterator(chainer.dataset.Iterator): 115 116 def __init__(self, dataset, window, batch_size, repeat=True): 117 self.dataset = np.array(dataset, np.int32) 118 self.window = window 119 self.batch_size = batch_size 120 self._repeat = repeat 121 122 self.order = np.random.permutation( 123 len(dataset) - window * 2).astype(np.int32) 124 self.order += window 125 self.current_position = 0 126 self.epoch = 0 127 self.is_new_epoch = False 128 129 def __next__(self): 130 if not self._repeat and self.epoch > 0: 131 raise StopIteration 132 133 i = self.current_position 134 i_end = i + self.batch_size 135 position = self.order[i: i_end] 136 w = np.random.randint(self.window - 1) + 1 137 offset = np.concatenate([np.arange(-w, 0), np.arange(1, w + 1)]) 138 pos = position[:, None] + offset[None, :] 139 context = self.dataset.take(pos) 140 center = self.dataset.take(position) 141 142 if i_end >= len(self.order): 143 np.random.shuffle(self.order) 144 self.epoch += 1 145 self.is_new_epoch = True 146 self.current_position = 0 147 else: 148 self.is_new_epoch = False 149 self.current_position = i_end 150 151 return center, context 152 153 @property 154 def epoch_detail(self): 155 return self.epoch + float(self.current_position) / len(self.order) 156 157 def serialize(self, serializer): 158 self.current_position = serializer('current_position', 159 self.current_position) 160 self.epoch = serializer('epoch', self.epoch) 161 self.is_new_epoch = serializer('is_new_epoch', self.is_new_epoch) 162 if self._order is not None: 163 serializer('_order', self._order) 164 165 166def convert(batch, device): 167 center, context = batch 168 if device >= 0: 169 center = cuda.to_gpu(center) 170 context = cuda.to_gpu(context) 171 return center, context 172 173 174if args.gpu >= 0: 175 cuda.get_device_from_id(args.gpu).use() 176 177train, val, _ = chainer.datasets.get_ptb_words() 178counts = collections.Counter(train) 179counts.update(collections.Counter(val)) 180n_vocab = max(train) + 1 181 182if args.test: 183 train = train[:100] 184 val = val[:100] 185 186vocab = chainer.datasets.get_ptb_words_vocabulary() 187index2word = {wid: word for word, wid in six.iteritems(vocab)} 188 189print('n_vocab: %d' % n_vocab) 190print('data length: %d' % len(train)) 191 192if args.out_type == 'hsm': 193 HSM = L.BinaryHierarchicalSoftmax 194 tree = HSM.create_huffman_tree(counts) 195 loss_func = HSM(args.unit, tree) 196 loss_func.W.data[...] = 0 197elif args.out_type == 'ns': 198 cs = [counts[w] for w in range(len(counts))] 199 loss_func = L.NegativeSampling(args.unit, cs, args.negative_size) 200 loss_func.W.data[...] = 0 201elif args.out_type == 'original': 202 loss_func = SoftmaxCrossEntropyLoss(args.unit, n_vocab) 203else: 204 raise Exception('Unknown output type: {}'.format(args.out_type)) 205 206if args.model == 'skipgram': 207 model = SkipGram(n_vocab, args.unit, loss_func) 208elif args.model == 'cbow': 209 model = ContinuousBoW(n_vocab, args.unit, loss_func) 210else: 211 raise Exception('Unknown model type: {}'.format(args.model)) 212 213if args.gpu >= 0: 214 model.to_gpu() 215 216 217optimizer = O.Adam() 218optimizer.setup(model) 219 220train_iter = WindowIterator(train, args.window, args.batchsize) 221val_iter = WindowIterator(val, args.window, args.batchsize, repeat=False) 222updater = training.StandardUpdater( 223 train_iter, optimizer, converter=convert, device=args.gpu) 224trainer = training.Trainer(updater, (args.epoch, 'epoch'), out=args.out) 225 226trainer.extend(extensions.Evaluator( 227 val_iter, model, converter=convert, device=args.gpu)) 228trainer.extend(extensions.LogReport()) 229trainer.extend(extensions.PrintReport( 230 ['epoch', 'main/loss', 'validation/main/loss'])) 231trainer.extend(extensions.ProgressBar()) 232trainer.run() 233 234with open('word2vec.model', 'w') as f: 235 f.write('%d %d\n' % (len(index2word), args.unit)) 236 w = cuda.to_cpu(model.embed.W.data) 237 for i, wi in enumerate(w): 238 v = ' '.join(map(str, wi)) 239 f.write('%s %s\n' % (index2word[i], v)) 240

###試したこと
環境変数のpathの設定をいじったり、chainerやcupyをインストールしなおしたりしましたが、成功しませんでした。

無知で申し訳ありません。どうかご回答をお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

CUDA: v8.0
CUDNN: v6.0
chainer: v3.1.0
で試してみたところ私はうまくいきましたよ!!

投稿2017/11/17 17:14

mmss

総合スコア46

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

https://github.com/chainer/chainer/blob/v3.0.0/chainer/cuda.py#L62
このインポート分が通るか確認して、

https://github.com/chainer/chainer/blob/v3.0.0/chainer/cuda.py#L60
この環境変数がどういう値を持っているかチェックする、

の2点が最初の一歩だと思います。

投稿2017/10/27 10:53

YouheiSakurai

総合スコア6142

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問