У меня есть NN-код, и я пытаюсь понять и устранить ошибку. Таким образом, размер партии равен 10
batchsize = 10
, и это итерация поезда и тестовая итерация. train
и test
определены ранее.
train_iter = iterators.SerialIterator(train, batchsize)
test_iter = iterators.SerialIterator(test, batchsize)
from chainer import optimizers
optimizer = optimizers.Adam()
optimizer.setup(model)
Итак, это код, и я сталкиваюсь с этой ошибкой (следующее):
while((train_iter.epoch < max_epoch) and needStudy):
train_batch = train_iter.next()
x, t = concat_examples(train_batch)
# print(t)
y = model(x)
loss = F.mean_squared_error(y, t)
model.cleargrads()
loss.backward()
optimizer.update()
if train_iter.is_new_epoch:
print("epoch", train_iter.epoch, "loss=", loss.data, end=" ")
loss_X.append(train_iter.epoch)
loss_Y.append(loss.data)
while True:
test_batch = test_iter.next()
x_test, t_test = concat_examples(test_batch)
y_test = model(x_test)
loss_test = F.mean_squared_error(y_test, t_test)
if test_iter.is_new_epoch:
test_iter.epoch = 0
test_iter.current_position = 0
test_iter.is_new_epoch = False
test_iter._pushed_position = None
break
print("test_loss=", loss_test.data)
loss_Y_test.append(loss_test.data)
study_loss = loss_test.data
if study_loss < studyThreshold:
needStudy = False
print("loss is less than threshold value")
Я сталкиваюсь с ошибкой:
KeyError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2656 try:
-> 2657 return self._engine.get_loc(key)
2658 except KeyError:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
KeyError: 21062
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-312-af73cdb88d0f> in <module>
1 while((train_iter.epoch < max_epoch) and needStudy):
----> 2 train_batch = train_iter.next()
3 x, t = concat_examples(train_batch)
4 # print(t)
5 y = model(x)
~\Anaconda3\lib\site-packages\chainer\iterators\serial_iterator.py in __next__(self)
75 raise StopIteration
76
---> 77 batch = [self.dataset[index] for index in indices]
78 return batch
79
~\Anaconda3\lib\site-packages\chainer\iterators\serial_iterator.py in <listcomp>(.0)
75 raise StopIteration
76
---> 77 batch = [self.dataset[index] for index in indices]
78 return batch
79
~\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
2925 if self.columns.nlevels > 1:
2926 return self._getitem_multilevel(key)
-> 2927 indexer = self.columns.get_loc(key)
2928 if is_integer(indexer):
2929 indexer = [indexer]
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2657 return self._engine.get_loc(key)
2658 except KeyError:
-> 2659 return self._engine.get_loc(self._maybe_cast_indexer(key))
2660 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2661 if indexer.ndim > 1 or indexer.size > 1:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
KeyError: 21062
Любая идея?