[SSD] SSD training of pytorch version

Code source for debugging: https://github.com/amdegroot/ssd.pytorch

surroundings:

  • python3.7
  • cuda10.0
  • cudnn7
  • pytorch1.2.0
  • torchvision0.4.0

Question 1

If you use VOC and there is no COCO data, then you need to comment out the COCO part. If you do not comment, you will get an error.

Solution

Directly comment out the COCO part in train.py and modify it as follows

    # if args.dataset == 'COCO':
    #     if args.dataset_root == VOC_ROOT:
    #         if not os.path.exists(COCO_ROOT):
    #             parser.error('Must specify dataset_root if specifying dataset')
    #         print("WARNING: Using default COCO dataset_root because " +
    #               "--dataset_root was not specified.")
    #         args.dataset_root = COCO_ROOT
    #     cfg = coco
    #     dataset = COCODetection(root=args.dataset_root,
    #                             transform=SSDAugmentation(cfg['min_dim'], MEANS)
    #                             )
    # elif args.dataset == 'VOC':
    #     if args.dataset_root == COCO_ROOT:
    #         parser.error('Must specify dataset if specifying dataset_root')
    #     cfg = voc
    #     dataset = VOCDetection(root=args.dataset_root,
    #                            transform=SSDAugmentation(cfg['min_dim'], MEANS)
    #                            )

    cfg = voc
    dataset = VOCDetection(root=args.dataset_root,
                           transform=SSDAugmentation(cfg['min_dim'], MEANS)
                           )

 Comment out the COCO part in data \ __ init__.py:

# from .coco import COCODetection, COCOAnnotationTransform, COCO_CLASSES, COCO_ROOT, get_label_map

Modify the HOME directory in data \ config.py:

# gets home dir cross platform
# HOME = os.path.expanduser("~")
HOME =  r"E:\standard_data\voc"

Modify the VOC_ROOT directory of data \ voc0712.py to:

VOC_ROOT = osp.join(HOME, "VOC2007_ORI\\VOCdevkit\\")

Question 2

In the ssds detection project, a bug was encountered in the multibox_loss.py which sought loss, and the error was:

IndexError: The shape of the mask [32, 2990] at index 0 does not match the shape of the indexed tensor [95680, 1] at index 0

The error code appears in:

loss_c[pos] = 0

Among them, the dimension dimensions of pos and loss_c are:

loss_c.size torch.Size([95680, 1])
pos.size torch.Size([32, 2990])

Solution

Around line 97 in multibox_loss.py, replace

loss_c[pos] = 0 # filter out pos boxes for now

To

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

Question 3

 Problem location

        loc_loss += loss_l.data[0]
        conf_loss += loss_c.data[0]
        if iteration % 1 == 0:
            print('timer: %.4f sec.' % (t1 - t0))
            print('iter ' + repr(iteration) + ' || Loss: %.4f ||' % (loss.data[0]), end=' ')

Solution

Modify the problem location above to

        loc_loss += loss_l.detach()
        # conf_loss += loss_c.data[0]
        conf_loss += loss_c.detach()
        if iteration % 1 == 0:
            print('timer: %.4f sec.' % (t1 - t0))
            print('iter ' + repr(iteration) + ' || Loss: %.4f ||' % (loss.detach()), end=' ')

 

Published 190 original articles · praised 497 · 2.60 million views +

Guess you like

Origin blog.csdn.net/u013066730/article/details/103988471