Chainerを利用して18万文ほどのデータの分類を行っています。
プログラムの一部を以下に記しました。
python
1train_iter = iterators.SerialIterator(train,batch) 2test_iter = iterators.SerialIterator(test,batch,False,False) 3 4class logis(chainer.Chain): 5 def __init__(self): 6 super().__init__() 7 8 with self.init_scope(): 9 self.l1 = L.Linear(None,2) 10 11 12 def forward(self,x): 13 h = F.softmax(self.l1(x)) 14 return h 15 16pred = logis() 17net = L.Classifier(pred) 18gpu_id = 0 19if gpu_id >= 0: 20 net.to_gpu(gpu_id) 21optimizer = optimizers.Adam().setup(net) 22updater = training.StandardUpdater(train_iter, optimizer, device=0) 23trainer = training.Trainer(updater, (30,'epoch'), out="a") 24 25trainer.extend(extensions.LogReport(trigger=(1, 'epoch'), log_name='log')) 26trainer.extend(extensions.PrintReport(['epoch', 'iteration', 'main/loss', 'main/accuracy', 'elapsed_time'])) 27 28trainer.run()
やりたいこと
今までは下記のようにテストデータ全体に対するAccuracyを求めていました。
test_evaluator = extensions.Evaluator(test_iter, net, device=gpu_id) results = test_evaluator() print('Test accuracy:', results['main/accuracy'])
テストデータ全体ではなく、任意の1つのデータに対してのsoftmaxの確率の出力を行いたいです。
回答1件
あなたの回答
tips
プレビュー