2018年11月27日星期二

tf faster rcnn推导测试集计算mAP报错

训练完毕后运行./experiments/scripts/test_faster_rcnn.sh 0 pascal_voc res101
测试mAP,报错:
and the problem:
VOC07 metric? Yes
000001
Traceback (most recent call last):
File "./tools/test_net.py", line 90, in
test_net(net, imdb, max_per_image=args.max_per_image, vis=args.vis)
File "/home/rs/myGithub/py-faster-rcnn/tools/../lib/fast_rcnn/test.py", line 295, in test_net
imdb.evaluate_detections(all_boxes, output_dir)
File "/home/rs/myGithub/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 322, in evaluate_detections
self._do_python_eval(output_dir)
File "/home/rs/myGithub/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 285, in _do_python_eval
use_07_metric=use_07_metric)
File "/home/rs/myGithub/py-faster-rcnn/tools/../lib/datasets/voc_eval.py", line 127, in voc_eval
R = [obj for obj in recs[imagename] if obj['name'] == classname]
KeyError: '000001'
解决方法:
had the same problem with an old annotation cache. Just delete it
rm data/VOCdevkit2007/annotations_cache/annots.pkl and run the program again.
You should also delete the roidb cache:
rm data/cache/voc_2007_trainval_gt_roidb.pkl


PS:如要可视化测试结果,可在CPU电脑上运行tf-faster-rcnn/tools/demo_one.py程序。






2018年11月22日星期四

tf faster rcnn 训练自己的数据集


1 按照https://github.com/endernewton/tf-faster-rcnn中介绍步骤安装项目。

2 用自己的数据集替换VOC2007数据集文件夹。

3 修改lib/datasets/pascal_voc.py中

self._classes = ('__background__',  # always index 0       "defect0","defect1","defect2","defect3","defect4","defect5","defect6","defect7","defect8","defect9")####################
 
4 lib/datasets/factory.py和experiments/scripts/train_faster_rcnn, experiments/scripts/test_faster_rcnn中,因为自己数据集名称和VOC2007一致,暂不用修改。

5 开始训练

./experiments/scripts/train_faster_rcnn.sh 0 pascal_voc res101
注意每次训练前删除output和data/cache文件夹。

训练时其它可能需要修改的参数:
1)修改迭代次数:experiments/scripts/train_faster_rcnn.sh文件中修改迭代次数
experiments/scripts/test_faster_rcnn.sh中也相应修改
2) 学习率设置:tf-faster-rcnn/lib/model/config.py文件中设置



6 tools/demo.py修改种类数
net.create_architecture("TEST", 11,#####################21


可能出现的错误:
1)InvalidArgumentError (see above for traceback): Nan in summary histogram for: 


it's because in the file 'pascal_voc.py', the function '_load_pascal_annotation' has an operation of make pixel indexes 0-based,the code is :
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
删除-1

2)assert(cfg.TRAIN.BATCH_SIZE % num_images == 0), 
ZeroDivisionError: integer division or modulo by zero

test.txt不能为空







2018年11月20日星期二

xml和json无法显示中文

解决办法:在相关语句中添加“encoding='utf-8'”。
如:

xmldoc.write(xmlpath+xmllist[i], encoding='utf-8')

json.dump(instance, open(save_path, 'w', encoding='utf-8'), ensure_ascii=False, indent=1)

with open(path, "r", encoding='utf-8') as f:

2018年11月19日星期一

ImportError: No module named Cython.Distutils

Ubuntu下使用tensorflow版faster-RCNN执行make命令报错

For python3 use
sudo apt-get install cython3
For python2 use
sudo apt-get install cython

2018年11月6日星期二

安装OpenCV3.4.2

from: https://cloud.tencent.com/developer/article/1329166

安装OpenCV3.4.2
注意:想要在OpenCV中玩转YOLOv3,必须安装OpenCV3.4.2版本及以上。
Python版安装方法
1# 推荐安装外挂版
2pip install opencv-contrib-python
3
4# 或者安装正常版
5pip install opencv-python

Failed to find TIFF library

ImportError: Failed to find TIFF library. Make sure that libtiff is installed and its location is listed in PATH|LD_LIBRARY_PATH|.. 解决方法: ...