使用Faster-RCNN进行指定GPU训练(续)

时间:2022-07-23
本文章向大家介绍使用Faster-RCNN进行指定GPU训练(续),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
  1. 今天接着昨天的实验继续跑“多GPU训练” python trainval_net.py --dataset pascal_voc --net res101 --bs 24 --nw 8 --lr $LEARING_RATE --lr_decay_step $DECAY_STEP --cuda --mGPUs # (pascal_voc.py self._classes 类别修改)
  2. 训练自己的数据集(步骤与之前样例中相同)
  3. 训练完成后对数据集进行处理,发现有些图片因为亮度不够或模糊而识别有误。下一步考虑怎么提高图片的清晰度,使识别率提高。
  4. 目前有个想法:
    1. 计算图片清晰度,如果清晰度不在某个范围的话,进行第二步操作;
    2. 调整图片的亮度和对比度,然后再进行清晰度计算。若清晰度达到要求,则输出;否则,继续调整,直到符合要求。

问题

  • 问题一:“多GPU训练”中出现ctx.input_sizes = tuple(map(lambda i: i.size(ctx.dim), inputs)) RuntimeError: dimension specified as 0 but tensor has no dimensions错误
    • 解决:在faster-rcnn.pytorch中的issue: multi gpu train errors!可以看到这个问题出现的比较多,其中有两条解决方案:
      1. the pytorch 1.0 branch works fine with multi GPU training(pytorch 1.0分支可以正常进行多GPU训练)。但因为太麻烦,我没有尝试。
      2. faster-rcnn.pytorch/lib/model/faster_rcnn/faster_rcnn.py中加入以下几行(经测试可行): rpn_loss_cls = torch.Tensor([0]).cuda() + rpn_loss_cls rpn_loss_bbox = torch.Tensor([0]).cuda() + rpn_loss_bbox RCNN_loss_cls = torch.Tensor([0]).cuda() + RCNN_loss_cls RCNN_loss_bbox = torch.Tensor([0]).cuda() + RCNN_loss_bbox
  • 问题二:assert (boxes[:, 2] >= boxes[:, 0]).all() AssertionError
    • 解决:将datasets/pascal_voc.py中的如下代码的"-1"删掉 bbox = obj.find('bndbox') # Make pixel indexes 0-based x1 = float(bbox.find('xmin').text) - 1 y1 = float(bbox.find('ymin').text) - 1 x2 = float(bbox.find('xmax').text) - 1 y2 = float(bbox.find('ymax').text) - 1
  • 问题三:raise ValueError("bg_num_rois = 0 and fg_num_rois = 0, this should not happen!")