天天看点

SSD-PyTorch训练自己的数据集问题汇总

代码链接:https://github.com/amdegroot/ssd.pytorch

运行train.py :

(1)ModuleNotFoundError: No module named 'cv2'

         安装opencv-python :pip install opencv-python

(2)FileNotFoundError: [Errno 2] No such file or directory

        修改路径指向自己的数据集:

        针对coco数据集,修改data/coco.py第11行

COCO_ROOT = osp.join(HOME, 'data/coco/')
           

        针对voc数据集,修改data/voc0712.py第28行

VOC_ROOT = osp.join(HOME, "data/VOCdevkit/")
           

(3)RuntimeError: randperm is only implemented for CPU

         torch/utils/data/sampler.py 第51行处内容如下

def _iter_(self)
    cpu = torch.device('cpu')
    return iter(torch.randperm(len(self.data_source),device = cpu).tolist())
           

(4)KeyError: 'Traceback (most recent call last):\n

         train.py第165行处内容改为如下

try:
    images, targets = next(bath_iterator)
except StopIteration:
    bath_iterator = iter(data_loader)
    images, targets = next(bath_iterator)
           

(5)RuntimeError: The shape of the mask [13, 8732] at index 0 does not match the shape of the indexed tensor [113516, 1] at index 0

         layers/modules/multibox_loss.py 第97、98行调换

loss_c = loss_c.view(num, -1)
loss_c[pos] = 0  # filter out pos boxes for now
           

         第114行将 N = num_pos.data.sum() 改为

N = num_pos.data.sum().double()
loss_l = loss_l.double()
loss_c = loss_c.double()
           

(6)RuntimeError: merge_sort: failed to synchronize: an illegal memory access was encountered

        调整学习率和bach_size,比如我把学习率改为0.001,bach_size设置为4,问题即可解决。

(7)完成训练

SSD-PyTorch训练自己的数据集问题汇总

运行eval.py:

(注意:以下两个问题新版源码已修正)

(1)ValueError: not enough values to unpack (expected 2, got 0)

         layers/functions/detection.py 第49行改为

if scores.size(0) == 0:
           

(2)IndexError: too many indices for tensor of dimension 1

         eval.py 第393行改为

if dets.size(0) == 0:
           

继续阅读