現在CNNを用いた株価騰落の分類を行うモデルを作成しています。
以前まできちんと動作していたのですがある時から急に
StopIterationのエラーが出て2回目以降の学習を繰り返してくれなくなりました。
調べてみても原因が全く分からず困っております。
以下エラー全文です
epoch main/loss main/accuracy validation/main/loss validation/main/accuracy elapsed_time
1 20.1328 0.509596 0.692708 0.526667 605.443
Exception in main training loop:
Traceback (most recent call last):
File "/Users/kojimakazuya/anaconda3/lib/python3.7/site-packages/chainer/training/trainer.py", line 316, in run
update()
File "/Users/kojimakazuya/anaconda3/lib/python3.7/site-packages/chainer/training/updaters/standard_updater.py", line 175, in update
self.update_core()
File "/Users/kojimakazuya/anaconda3/lib/python3.7/site-packages/chainer/training/updaters/standard_updater.py", line 180, in update_core
batch = iterator.next()
File "/Users/kojimakazuya/anaconda3/lib/python3.7/site-packages/chainer/iterators/serial_iterator.py", line 75, in next
raise StopIteration
Will finalize trainer extensions and updater before reraising the exception.
Traceback (most recent call last):
File "cnn.py", line 67, in <module>
trainer.run()
File "/Users/kojimakazuya/anaconda3/lib/python3.7/site-packages/chainer/training/trainer.py", line 349, in run
six.reraise(*exc_info)
File "/Users/kojimakazuya/anaconda3/lib/python3.7/site-packages/six.py", line 693, in reraise
raise value
File "/Users/kojimakazuya/anaconda3/lib/python3.7/site-packages/chainer/training/trainer.py", line 316, in run
update()
File "/Users/kojimakazuya/anaconda3/lib/python3.7/site-packages/chainer/training/updaters/standard_updater.py", line 175, in update
self.update_core()
File "/Users/kojimakazuya/anaconda3/lib/python3.7/site-packages/chainer/training/updaters/standard_updater.py", line 180, in update_core
batch = iterator.next()
File "/Users/kojimakazuya/anaconda3/lib/python3.7/site-packages/chainer/iterators/serial_iterator.py", line 75, in next
raise StopIteration
StopIteration
python
1 2import matplotlib.pyplot as plt 3import load_data 4import stock_data 5import img_to_vector 6import load_vector 7import numpy as np 8from sklearn.preprocessing import MinMaxScaler 9import chainer 10import chainer.links as L 11import chainer.functions as F 12from chainer import Chain, Variable, datasets, optimizers 13from chainer import report, training 14from chainer.training import extensions 15from chainer import iterators 16from chainer import serializers 17import chainer.cuda 18 19#データの準備 20sp500, topix500, usd_jpy = load_vector.load_vector() 21x_train, x_test = topix500[:2000], topix500[2000:] 22 23t_train, t_test = load_data.label(stock_data.teacher_dataset()[:2000]), load_data.label(stock_data.teacher_dataset()[2000:]) 24 25train = list(zip(x_train, t_train)) 26test = list(zip(x_test, t_test)) 27 28class CNN(Chain): 29 def __init__(self): 30 super(CNN, self).__init__() 31 with self.init_scope(): 32 self.cn1 = L.Convolution2D(None, 32, ksize=3, pad=1) 33 self.cn2 = L.Convolution2D(None, 32, ksize=3, pad=1) 34 self.fc1 = L.Linear(None, 100) 35 self.fc2 = L.Linear(100, 2) 36 37 def __call__(self, x, t=None): 38 h1 = F.max_pooling_2d(F.relu(self.cn1(x)), ksize=2, stride=2) 39 h2 = F.max_pooling_2d(F.relu(self.cn2(h1)), ksize=2, stride=2) 40 h3 = F.dropout(F.relu(self.fc1(h2))) 41 return self.fc2(h3) 42 43 44model = CNN() 45net = L.Classifier(model) 46optimizer = optimizers.Adam().setup(net) 47 48batchsize = 20 49train_iter = chainer.iterators.SerialIterator(train, batchsize, repeat=False, shuffle=True) 50test_iter = chainer.iterators.SerialIterator(test, batchsize, repeat=False, shuffle=True) 51 52updater = training.StandardUpdater(train_iter, optimizer, device=-1) # device=-1でCPUでの計算実行を指定 53 54epoch = 100 55trainer = training.Trainer(updater, (epoch, 'epoch'), out='result') 56 57# テストデータで評価 58trainer.extend(extensions.Evaluator(test_iter, net, device = -1)) 59 60# 学習を記録 61trainer.extend(extensions.LogReport(trigger=(1, 'epoch'))) 62 63# グラフに描画、保存 64trainer.extend(extensions.PlotReport(['main/loss', 'validation/main/loss'], x_key='epoch', file_name='cnn2_loss.png')) 65trainer.extend(extensions.PlotReport(['main/accuracy', 'validation/main/accuracy'], x_key='epoch', file_name='cnn2_accuracy.png')) 66trainer.extend(extensions.PrintReport(['epoch', 'main/loss', 'main/accuracy','validation/main/loss', 'validation/main/accuracy','elapsed_time']), trigger=(1, 'epoch')) 67 68trainer.run()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。