天天看點

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:
           

繼續閱讀