1:lisa下载地址:http://cvrr.ucsd.edu/LISA/datasets.html
2:解压缩后,使用python tools/splitAnnotationFiles.py
将数据集划分成训练集和测试集的csv描述文件。
3:转化csv为json格式。
import mmcv
import os
import sys
import json
import cv2
import numpy as npclass_names = ['stop', 'speedLimitUrdbl', 'speedLimit25', 'pedestrianCrossing', 'speedLimit35', 'turnLeft', 'slow', 'speedLimit15', 'speedLimit45', 'rightLaneMustTurn', 'signalAhead', 'keepRight', 'laneEnds', 'school', 'merge', 'addedLane', 'rampSpeedAdvisory40', 'rampSpeedAdvisory45', 'curveRight', 'speedLimit65', 'truckSpeedLimit55', 'thruMergeLeft', 'speedLimit30', 'stopAhead', 'yield', 'thruMergeRight', 'dip', 'schoolSpeedLimit25', 'thruTrafficMergeLeft', 'noRightTurn', 'rampSpeedAdvisory35', 'curveLeft', 'rampSpeedAdvisory20', 'noLeftTurn', 'zoneAhead25', 'zoneAhead45', 'doNotEnter', 'yieldAhead', 'roundabout', 'turnRight', 'speedLimit50', 'rampSpeedAdvisoryUrdbl', 'rampSpeedAdvisory50', 'speedLimit40', 'speedLimit55', 'doNotPass', 'intersection']def _2coco(files):coco_anno = {'info': {}, 'images': [], 'licenses': [], 'annotations': [], 'categories': []}coco_anno['categories'] = [{'supercategory': j, 'id': i+1, 'name': j} for i,j in enumerate(class_names)]img_id = 0anno_id = 0img_ids = mmcv.list_from_file(files)for i in range(1,len(img_ids)):im_i = img_ids[i].split(';')file_name = im_i[0]cf = 1for z in range(0,len(coco_anno['images'])):if file_name == coco_anno['images'][z]['file_name']:im_id = coco_anno['images'][z]['id']cf = 2if cf == 1:img_id += 1img_ = cv2.imread(file_name)ih,iw = img_.shape[:2]img_info = {}img_info['id'] = img_idimg_info['file_name'] = file_nameimg_info['height'] = ihimg_info['width'] = iwcoco_anno['images'].append(img_info)cls_name = im_i[1]x1 = float(im_i[2])y1 = float(im_i[3])x2 = float(im_i[4])y2 = float(im_i[5])if x2 < x1 or y2 < y1:print('bbox not valid: ',file_name)continueanno_id += 1bb = [x1, y1, x2 - x1, y2 - y1]categery_id = class_names.index(cls_name) + 1area = (x2 - x1) * (y2 - y1)anno_info = {}anno_info['segmentation'] = []anno_info['area'] = areaif cf == 2:anno_info['image_id'] = im_idif cf == 1:anno_info['image_id'] = img_idanno_info['bbox'] = bbanno_info['iscrowd'] = 0anno_info['category_id'] = categery_idanno_info['id'] = anno_idcoco_anno['annotations'].append(anno_info)return coco_anno_coco = _2coco('split1.csv')
data_dir = sys.path[0]
with open(os.path.join(data_dir, 'coco_train.json'), 'w') as f:json.dump(_coco, f, ensure_ascii=False, indent=2)
print('done')
_coco = _2coco('split2.csv')
with open(os.path.join(data_dir, 'coco_test.json'), 'w') as f:json.dump(_coco, f, ensure_ascii=False, indent=2)
print('done')
4:安装mmdetection。此部分安装mmcv比较麻烦,原因是之前安装的mmcv会和mmcv-full冲突,直接用conda建一个新环境吧。我弄了俩三小时才弄明白。。。
5:mmdetction,我在用的过程中,发现准确率只有在第一个epoch的第一次是百分之九十,其余全是100,后来看代码发现是rpn_head里的Num_class是1,我修改成47后,直接报吐核错误。把per_gpu降到1还不行,试了一下voc,发现num_class是40。其中有个Bug:
```pythondef load_annotations(self, ann_file):"""Load annotation from XML style ann_file.Args:ann_file (str): Path of XML file.Returns:list[dict]: Annotation info from XML file."""data_infos = []print("ann_file:",ann_file)img_ids = mmcv.list_from_file(ann_file)for img_id in img_ids:# print(img_id)img_id = img_id.split(' ')[0]filename = f'JPEGImages/{img_id}.jpg'xml_path = osp.join(self.img_prefix, 'Annotations',f'{img_id}.xml')tree = ET.parse(xml_path)
img_id = img_id.split(’ ')[0],这行需要加上去,在xml_style.py文件中,不然会连 -1
也作为图片名字读取了。
6:faster_rcnn pytorch 链接:https://github.com/jwyang/faster-rcnn.pytorch
需要注意:使用torch0.4+torchvision0.2.0,以及用cuda9.0,再报错重新make一下。