第一个bug:使用了自己的voc数据集报错误却是coco的。
Traceback (most recent call last):
File “train.py”, line 1, in
from data import *
File “/home/bitnami/SSD/data/init.py”, line 3, in
from .coco import COCODetection, COCOAnnotationTransform, COCO_CLASSES, COCO_ROOT, get_label_map
File “/home/bitnami/SSD/data/coco.py”, line 75, in
class COCODetection(data.Dataset):
File “/home/bitnami/SSD/data/coco.py”, line 87, in COCODetection
target_transform=COCOAnnotationTransform(), dataset_name=‘MS COCO’):
File “/home/bitnami/SSD/data/coco.py”, line 47, in init
self.label_map = get_label_map(osp.join(COCO_ROOT, ‘coco_labels.txt’))
File “/home/bitnami/SSD/data/coco.py”, line 35, in get_label_map
labels = open(label_file, ‘r’)
FileNotFoundError: [Errno 2] No such file or directory: ‘/home/bitnami/data/coco/coco_labels.txt’
方法把 from .coco import COCODetection, COCOAnnotationTransform, COCO_CLASSES, COCO_ROOT, get_label_map:删掉
还在报错coco的!继续删掉
Traceback (most recent call last):
File “train.py”, line 255, in
train()
File “train.py”, line 84, in train
if args.dataset_root == COCO_ROOT:
NameError: name ‘COCO_ROOT’ is not defined
我的是2007 不是2012 ,把2012去掉!
FileNotFoundError: [Errno 2] No such file or directory: ‘/home/bitnami/GraDataset/VOCdevkit/VOC2012/ImageSets/Main/trainval.txt’
xml的类别有大写的字眼,在读取的时候回自动转化为小写所以我们的voc_classses改为小写即可!写大写会发现找不到的问题!
后来又遇到的问题:
pytorch的版本问题:具体修改:
https://github.com/amdegroot/ssd.pytorch/issues/173
参考这里:
I solve the problem if your python torch version is 1.0.1. The solution as follow 1-3 steps:
step1 and step2 change the multibox_loss.py!
step1: switch the two lines 97,98:
loss_c = loss_c.view(num, -1)
loss_c[pos] = 0 # filter out pos boxes for now
step2: change the line114 N = num_pos.data.sum() to
N = num_pos.data.sum().double()
loss_l = loss_l.double()
loss_c = loss_c.double()
setp 3 change the train.py!
step3: change the line188,189,193,196:
loss_l.data[0] >> loss_l.data
loss_c.data[0] >> loss_c.data
loss.data[0] >> loss.data
还有config.py的 类别要+1 因为SSD把背景当作一类。不然会报错!
loss 出现NAN
I set the lr 1e-7 and the batch size 16 to solve the problem finally TAT…
成功!