训练Pytorch深度学习模型出现StopIteration

训练一个深度学习检测模型,突然出现:
在这里插入图片描述
是因为next(batch_iterator),可能迭代器读出来的数据为空。

 # load train data
 # 原先代码
 images, targets = next(batch_iterator)
 # 更改为:
 try:
     images, targets = next(batch_iterator)
 except:
     batch_iterator = iter(data_loader)
     images, targets = next(batch_iterator)

猜你喜欢

转载自blog.csdn.net/weixin_50557558/article/details/139455964