热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Fasterrcnn训练自己的数据集

安装cpython,python-opencveasydictpipinstallcpythonpipinstalleasydictapt-getinstall

安装cpython,python-opencv easydict

pip install cpython
pip install easydict
apt-get install python-opencv

进如 py-faster-rcnn/lib 进行make操作

make

进入 py-faster-rcnn/caffe-fast-rcnn

cp Makefile.config.example Makefile.config

对Makefile.config文件进行配置,我的配置文件如下:

## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1# Uncomment if you're using OpenCV 3
# OPENCV_VERSION := 3# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr# CUDA architecture setting: going with all of them.
# For CUDA <6.0, comment the *_50 lines for compatibility.
CUDA_ARCH :&#61; -gencode arch&#61;compute_20,code&#61;sm_20 \-gencode arch&#61;compute_20,code&#61;sm_21 \-gencode arch&#61;compute_30,code&#61;sm_30 \-gencode arch&#61;compute_35,code&#61;sm_35 \-gencode arch&#61;compute_50,code&#61;sm_50 \-gencode arch&#61;compute_50,code&#61;compute_50# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS :&#61; atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE :&#61; /path/to/your/blas
# BLAS_LIB :&#61; /path/to/your/blas# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE :&#61; $(shell brew --prefix openblas)/include
# BLAS_LIB :&#61; $(shell brew --prefix openblas)/lib# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR :&#61; /usr/local
# MATLAB_DIR :&#61; /Applications/MATLAB_R2012b.app# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE :&#61; /usr/include/python2.7 \/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it&#39;s in root.
# ANACONDA_HOME :&#61; $(HOME)/anaconda
# PYTHON_INCLUDE :&#61; $(ANACONDA_HOME)/include \# $(ANACONDA_HOME)/include/python2.7 \# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES :&#61; boost_python3 python3.5m
# PYTHON_INCLUDE :&#61; /usr/include/python3.5m \
# /usr/lib/python3.5/dist-packages/numpy/core/include# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB :&#61; /usr/lib
# PYTHON_LIB :&#61; $(ANACONDA_HOME)/lib# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE &#43;&#61; $(dir $(shell python -c &#39;import numpy.core; print(numpy.core.__file__)&#39;))/include
# PYTHON_LIB &#43;&#61; $(shell brew --prefix numpy)/lib# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER :&#61; 1# Whatever else you find you need goes here.
INCLUDE_DIRS :&#61; $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS :&#61; $(PYTHON_LIB) /usr/local/lib /usr/lib# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS &#43;&#61; $(shell brew --prefix)/include
# LIBRARY_DIRS &#43;&#61; $(shell brew --prefix)/lib# Uncomment to use &#96;pkg-config&#96; to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG :&#61; 1BUILD_DIR :&#61; build
DISTRIBUTE_DIR :&#61; distribute# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG :&#61; 1# The ID of the GPU that &#39;make runtest&#39; will use to run unit tests.
TEST_GPUID :&#61; 0# enable pretty build (comment to see full commands)
Q ?&#61; &#64;

 配置完Makefile.config文件后&#xff0c;执行&#xff1a;

make -j4
make pycaffe

  • 数据制作&#xff1a;

目标检测数据集制作工具 labelImg https://blog.csdn.net/caicaiatnbu/article/details/85125018

 修改 ../py-faster-rcnn/data/VOCdevkit2007/VOC2007/ 目录下的 Annotations 和 JPEGImage 以及ImageSets/Main 三个文件夹&#xff0c;下面依次讲述这个三个文件夹

JPEGImage 文件夹保存着所有图片&#xff0c;这里我们所有图片的格式统一都是jpg&#xff0c;命名规则"000001.jpg"开始。

Annotation 文件夹保存着每张图片对应的XML文件&#xff0c;这里我们将我们的XML文件格式贴出来&#xff1a;

VOC2007000001.jpgUnknown49937430

ImageSets/Main 文件夹下包含4个.txt文件&#xff0c;分别为 train.txt val.txt trainval.txt test.txt &#xff0c;没给txt中保存都是图片的名称。

注意&#xff1a;trainval.txt 为 train.txt 和 val.txt的总和。train.txt 和 val.txt 里面保存的样本数一定要为偶数&#xff0c;否则会报错

  •  代码部分修改

修改 py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_rcnn_train.pt   和  stage2_fast_rcnn_train.pt 两个文件

name: "ZF"
layer {name: &#39;data&#39;type: &#39;Python&#39;top: &#39;data&#39;top: &#39;rois&#39;top: &#39;labels&#39;top: &#39;bbox_targets&#39;top: &#39;bbox_inside_weights&#39;top: &#39;bbox_outside_weights&#39;python_param {module: &#39;roi_data_layer.layer&#39;layer: &#39;RoIDataLayer&#39;param_str: "&#39;num_classes&#39;: 6" #按训练集类更改&#xff0c;该值为类别数&#43;1}
}layer {name: "cls_score"type: "InnerProduct"bottom: "fc7"top: "cls_score"param { lr_mult: 1.0 }param { lr_mult: 2.0 }inner_product_param {num_output: 6 #按训练集类更改&#xff0c;该值为类别数&#43;1weight_filler {type: "gaussian"std: 0.01}bias_filler {type: "constant"value: 0}}
}layer {name: "bbox_pred"type: "InnerProduct"bottom: "fc7"top: "bbox_pred"param { lr_mult: 1.0 }param { lr_mult: 2.0 }inner_product_param {num_output: 24 #按训练集类更改&#xff0c;该值为&#xff08;类别数&#43;1&#xff09;* 4weight_filler {type: "gaussian"std: 0.001}bias_filler {type: "constant"value: 0}}
}

修改 py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_rpn_train.pt  和 stage2_rpn_train.pt

name: "ZF"
layer {name: &#39;input-data&#39;type: &#39;Python&#39;top: &#39;data&#39;top: &#39;im_info&#39;top: &#39;gt_boxes&#39;python_param {module: &#39;roi_data_layer.layer&#39;layer: &#39;RoIDataLayer&#39;param_str: "&#39;num_classes&#39;: 6" #按训练集类更改&#xff0c;该值为类别数&#43;1}
}

修改py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/faster_rcnn_test.pt

layer {name: "cls_score"type: "InnerProduct"bottom: "fc7"top: "cls_score"inner_product_param {num_output: 6 #按训练集类更改&#xff0c;该值为类别数&#43;1}
}
layer {name: "bbox_pred"type: "InnerProduct"bottom: "fc7"top: "bbox_pred"inner_product_param {num_output: 24 #按训练集类更改&#xff0c;该值为&#xff08;类别数&#43;1&#xff09;* 4}
}

修改 py-faster-rcnn/lib/datasets/pascal_voc.py

注意 标签名尽可能为英文小写。否则会报bug

self._classes &#61; (&#39;__background__&#39;, # always index 0&#39;label_a&#39;,&#39;label_b&#39;,&#39;label_c&#39;,&#39;label_d&#39;,&#39;label_e&#39;)# &#39;aeroplane&#39;, &#39;bicycle&#39;, &#39;bird&#39;, &#39;boat&#39;,# &#39;bottle&#39;, &#39;bus&#39;, &#39;car&#39;, &#39;cat&#39;, &#39;chair&#39;,# &#39;cow&#39;, &#39;diningtable&#39;, &#39;dog&#39;, &#39;horse&#39;,# &#39;motorbike&#39;, &#39;person&#39;, &#39;pottedplant&#39;,# &#39;sheep&#39;, &#39;sofa&#39;, &#39;train&#39;, &#39;tvmonitor&#39;)

修改 py-faster-rcnn/lib/datasets/imdb.py

def append_flipped_images(self):num_images &#61; self.num_images#widths &#61; self._get_widths()widths &#61; [PIL.Image.open(self.image_path_at(i)).size[0]for i in xrange(self.num_images)]for i in xrange(num_images):boxes &#61; self.roidb[i][&#39;boxes&#39;].copy()oldx1 &#61; boxes[:, 0].copy()oldx2 &#61; boxes[:, 2].copy()boxes[:, 0] &#61; widths[i] - oldx2 - 1boxes[:, 2] &#61; widths[i] - oldx1 - 1for b in range(len(boxes)):if boxes[b][2] &#61; boxes[:, 0]).all()entry &#61; {&#39;boxes&#39; : boxes,&#39;gt_overlaps&#39; : self.roidb[i][&#39;gt_overlaps&#39;],&#39;gt_classes&#39; : self.roidb[i][&#39;gt_classes&#39;],&#39;flipped&#39; : True}self.roidb.append(entry)self._image_index &#61; self._image_index * 2

删除缓存文件

删除 py-faster-rcnn文件夹下所有的.pyc 文件 以及 data文件件下的cache文件夹&#xff0c;

删除 data/VOCdevkit2007/annotations_cache 文件夹

删除 py-faster-rcnn/lib/datasets/ 下的imdb.pyc 和 pascal_voc.pyc

 

开始训练&#xff1a;

./experiments/scripts/faster_rcnn_alt_opt.sh 0 ZF pascal_voc

 


推荐阅读
  • 本文介绍了如何使用Express App提供静态文件,同时提到了一些不需要使用的文件,如package.json和/.ssh/known_hosts,并解释了为什么app.get('*')无法捕获所有请求以及为什么app.use(express.static(__dirname))可能会提供不需要的文件。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Python已成为全球最受欢迎的编程语言之一,然而Python程序的安全运行存在一定的风险。本文介绍了Python程序安全运行需要满足的三个条件,即系统路径上的每个条目都处于安全的位置、"主脚本"所在的目录始终位于系统路径中、若python命令使用-c和-m选项,调用程序的目录也必须是安全的。同时,文章还提出了一些预防措施,如避免将下载文件夹作为当前工作目录、使用pip所在路径而不是直接使用python命令等。对于初学Python的读者来说,这些内容将有所帮助。 ... [详细]
  • 通过Anaconda安装tensorflow,并安装运行spyder编译器的完整教程
    本文提供了一个完整的教程,介绍了如何通过Anaconda安装tensorflow,并安装运行spyder编译器。文章详细介绍了安装Anaconda、创建tensorflow环境、安装GPU版本tensorflow、安装和运行Spyder编译器以及安装OpenCV等步骤。该教程适用于Windows 8操作系统,并提供了相关的网址供参考。通过本教程,读者可以轻松地安装和配置tensorflow环境,以及运行spyder编译器进行开发。 ... [详细]
  • 本文介绍了协程的概念和意义,以及使用greenlet、yield、asyncio、async/await等技术实现协程编程的方法。同时还介绍了事件循环的作用和使用方法,以及如何使用await关键字和Task对象来实现异步编程。最后还提供了一些快速上手的示例代码。 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文介绍了多因子选股模型在实际中的构建步骤,包括风险源分析、因子筛选和体系构建,并进行了模拟实证回测。在风险源分析中,从宏观、行业、公司和特殊因素四个角度分析了影响资产价格的因素。具体包括宏观经济运行和宏经济政策对证券市场的影响,以及行业类型、行业生命周期和行业政策对股票价格的影响。 ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • 基于dlib的人脸68特征点提取(眨眼张嘴检测)python版本
    文章目录引言开发环境和库流程设计张嘴和闭眼的检测引言(1)利用Dlib官方训练好的模型“shape_predictor_68_face_landmarks.dat”进行68个点标定 ... [详细]
  • 本文介绍了Composer依赖管理的重要性及使用方法。对于现代语言而言,包管理器是标配,而Composer作为PHP的包管理器,解决了PEAR的问题,并且使用简单,方便提交自己的包。文章还提到了使用Composer能够避免各种include的问题,避免命名空间冲突,并且能够方便地安装升级扩展包。 ... [详细]
  • Python操作MySQL(pymysql模块)详解及示例代码
    本文介绍了使用Python操作MySQL数据库的方法,详细讲解了pymysql模块的安装和连接MySQL数据库的步骤,并提供了示例代码。内容涵盖了创建表、插入数据、查询数据等操作,帮助读者快速掌握Python操作MySQL的技巧。 ... [详细]
  • 开源Keras Faster RCNN模型介绍及代码结构解析
    本文介绍了开源Keras Faster RCNN模型的环境需求和代码结构,包括FasterRCNN源码解析、RPN与classifier定义、data_generators.py文件的功能以及损失计算。同时提供了该模型的开源地址和安装所需的库。 ... [详细]
  • 本文总结了使用不同方式生成 Dataframe 的方法,包括通过CSV文件、Excel文件、python dictionary、List of tuples和List of dictionary。同时介绍了一些注意事项,如使用绝对路径引入文件和安装xlrd包来读取Excel文件。 ... [详细]
author-avatar
手机用户2502940097
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有