faster-rcnn pytorch训练自己的数据集并测试(个人记录)

faster-rcnn pytorch训练自己的数据集并测试(个人记录)

参考文章:Faster-RCNN.pytorch的搭建、使用过程详解(适配PyTorch 1.0以上版本

训练train

我使用的训练命令:

CUDA_VISIBLE_DEVICES=0 python trainval_net.py --dataset pascal_voc --net vgg16 --epochs 20 --bs 1 --nw 2 --lr 1e-2 --lr_decay_step 8 --use_tfb --cuda

遇到的错误:

Traceback (most recent call last):
  File "trainval_net.py", line 28, in <module>
    from roi_data_layer.roibatchLoader import roibatchLoader
  File "/home/woo/detectron1.0/faster-rcnn.pytorch-pytorch-1.0/lib/roi_data_layer/roibatchLoader.py", line 14, in <module>
    from roi_data_layer.minibatch import get_minibatch, get_minibatch
  File "/home/woo/detectron1.0/faster-rcnn.pytorch-pytorch-1.0/lib/roi_data_layer/minibatch.py", line 17, in <module>
    from model.utils.blob import prep_im_for_blob, im_list_to_blob
  File "/home/woo/detectron1.0/faster-rcnn.pytorch-pytorch-1.0/lib/model/utils/blob.py", line 15, in <module>
    import cv2
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type

原因及解决办法:
在"/home/woo/detectron1.0/faster-rcnn.pytorch-pytorch-1.0/lib/model/utils/blob.py"文件开头(import cv2之前)添加

import sys
sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages')

测试 test

我使用的测试命令:

python test_net.py --dataset pascal_voc --net vgg16 --checksession 1 --checkepoch 20 --checkpoint 138 --cuda

遇到的错误:

Traceback (most recent call last):
  File "test_net.py", line 328, in <module>
    imdb.evaluate_detections(all_boxes, output_dir)
  File "/home/woo/detectron1.0/faster-rcnn.pytorch-pytorch-1.0/lib/datasets/pascal_voc.py", line 354, in evaluate_detections
    self._do_python_eval(output_dir)
  File "/home/woo/detectron1.0/faster-rcnn.pytorch-pytorch-1.0/lib/datasets/pascal_voc.py", line 317, in _do_python_eval
    use_07_metric=use_07_metric)
  File "/home/woo/detectron1.0/faster-rcnn.pytorch-pytorch-1.0/lib/datasets/voc_eval.py", line 134, in voc_eval
    R = [obj for obj in recs[imagename] if obj['name'] == classname]
KeyError: '000112'

原因及解决办法:
主要原因是文件夹中还保留有原数据集训练和测试时产生的缓存,导致在测试自己的数据集时先读取了原来的缓存,比如:原数据集中需要读取几千张图片,而现数据集只有几百张,所以报错。
解决方法是在训练和测试前删除原有的缓存文件.pkl:
删除/home/woo/detectron1.0/faster-rcnn.pytorch-pytorch-1.0/data/VOCdevkit/VOC2007/ImageSets/Main/test.txt_annots.pkl
删除/home/woo/detectron1.0/faster-rcnn.pytorch-pytorch-1.0/data/VOCdevkit/annotations_cache
删除/home/woo/detectron1.0/faster-rcnn.pytorch-pytorch-1.0/data/cache

你可能感兴趣的:(深度学习)