1. 运行
1.1 运行环境
(1) Pytorch
(2) tqdm
(3) tensorboard_logger
1.2 问题
Traceback (most recent call last):
File "C:/Users/xpb/PycharmProjects/MatchingNetworks-pytorch/mainOmniglot.py", line 47, in <module>
samples_per_class=samples_per_class)
File "C:\Users\xpb\PycharmProjects\MatchingNetworks-pytorch\datasets\omniglotNShot.py", line 45, in __init__
self.x.append(np.array(temp[temp.keys()[classes]]))
TypeError: 'dict_keys' object does not support indexing
问题原因: 这是由于python3改变了dict.keys,返回的是dict_keys对象,支持iterable 但不支持indexable,我们可以将其明确的转化成list:
解决方法:
self.x.append(np.array(temp[list(temp.keys())[classes]]))
2.3 memory error
内存太小
for sample in range(100):
2.4
Traceback (most recent call last):
File "C:/Users/xpb/PycharmProjects/MatchingNetworks-pytorch/mainOmniglot.py", line 55, in <module>
total_c_loss, total_accuracy = obj_oneShotBuilder.run_training_epoch(total_train_batches=total_train_batches)
File "C:\Users\xpb\PycharmProjects\MatchingNetworks-pytorch\experiments\OneShotBuilder.py", line 115, in run_training_epoch
iter_out = "tr_loss: {}, tr_accuracy: {}".format(c_loss_value.data[0], acc.data[0])
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
解决方法:
# iter_out = "tr_loss: {}, tr_accuracy: {}".format(c_loss_value.data[0], acc.data[0])
iter_out = "tr_loss: {}, tr_accuracy: {}".format(c_loss_value.item(), acc.item())
# total_c_loss += c_loss_value.data[0]
# total_accuracy += acc.data[0]
total_c_loss += c_loss_value.item()
total_accuracy += acc.item()
参考资料
问题解决
[1] TypeError: 'dict_keys' object does not support indexing
代码
[1] AntreasAntoniou/MatchingNetworks
[2] gitabcworld/MatchingNetworks
[3] cnichkawde/MatchingNetwork
网友评论