Windows7平台下基于Caffe框架,Python2.7配置 Faster-RCNN:
Caffe编译采用Vsiual Studio 2013
Step 1:安装cuda7.5(cuda 的支持依赖对显卡没有版本限制,凡是出现在列表中的显卡均是支持cuda各版本的,请放心使用)
https://developer.nvidia.com/cuda-75-downloads-archive
Step 2:下载cuDNN 5.0 (请根据cuda的版本选择相应的支持包)
https://developer.nvidia.com/cudnn
Step 3:下载Windows版Caffe
https://github.com/Microsoft/caffe
Step 4:编译caffe的libcaffe需要mcrosoft.net 3.5的支持(编译中出现无法读取libcaffe.lib的错误表示没有安装mcrosofe .net 3.5)
https://www.microsoft.com/en-us/download/details.aspx?id=21
Step 5:下载python的包含库Miniconda2 (其中已经包含了一个版本的Python因此不需要单独下载安装python)
https://conda.io/miniconda.html
Step 5.1: 安装numpy的库
Pip install numpy
Step 5.2: 在opencv下的Python文件夹下找到cv2.pyd将其考到Miniconda2的目录下
Step 5.3: 安装PIL-1.1.7.win32-py2.7的时候,不能再注册表中识别出来python2.7
新建一个register.py 文件,把一下代码贴进去,保存
# #script to register Python 2.0 or later for use with win32all #and other extensions that require Python registry settings # #written by Joakim Loew for Secret Labs AB / PythonWare # #source: #http://www.pythonware.com/products/works/articles/regpy20.htm # #modified by Valentine Gogichashvili as described in http://www.mail-archive.com/[email protected]/msg10512.html import sys from _winreg import * #tweak as necessary version= sys.version[:3] installpath= sys.prefix regpath= "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) installkey= "InstallPath" pythonkey= "PythonPath" pythonpath= "%s;%s\\Lib\\;%s\\DLLs\\" % ( installpath, installpath, installpath ) def RegisterPy(): try: reg = OpenKey(HKEY_CURRENT_USER,regpath) except EnvironmentError as e: try: reg = CreateKey(HKEY_CURRENT_USER,regpath) SetValue(reg, installkey, REG_SZ,installpath) SetValue(reg, pythonkey, REG_SZ,pythonpath) CloseKey(reg) except: print"*** Unable to register!" return print"--- Python", version, "is now registered!" return if (QueryValue(reg, installkey) == installpath and QueryValue(reg, pythonkey) ==pythonpath): CloseKey(reg) print"=== Python", version, "is already registered!" return CloseKey(reg) print"*** Unable to register!" print"*** You probably have another Python installation!" if__name__ == "__main__": RegisterPy()
运行代码,显示如下:
Step 5.4:安装python-yaml库
http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe
运行并安装
Step 6:复制Windows下CommonSettings.props.example,后缀改为CommonSettings.props
Step 6:修改 caffe-master/windows下的CommonSettings.props 文件修改内容如下
(此处用Python的外部接口做试验因此Modify 1 中MATLAB依赖设置成false,Modify 3可以不用修改)
Modify 1:
<PropertyGroup Label="UserMacros"> <BuildDir>$(SolutionDir)..\Build</BuildDir> <!--NOTE: CpuOnlyBuild and UseCuDNNflags can't be set at the same time.--> <CpuOnlyBuild>false</CpuOnlyBuild> <UseCuDNN>true</UseCuDNN> <CudaVersion>7.5</CudaVersion> <!-- NOTE: If Python support isenabled, PythonDir (below) needs to be set tothe root of your Python installation. If your Python installation does not contain debug libraries, debug build will not work.--> <PythonSupport>true</PythonSupport> <!-- NOTE: If Matlab support isenabled, MatlabDir (below) needs to be set to the root of your Matlab installation. --> <MatlabSupport>false</MatlabSupport> <CudaDependencies></CudaDependencies> <!-- Set CUDAarchitecture suitable for your GPU. Setting proper architecture is important to mimize your run and compile time.--> <CudaArchitecture>compute_35,sm_35;compute_52,sm_52</CudaArchitecture> <!--CuDNN 3 and 4 are supported --> <CuDnnPath>D:\cudnn-7.0-win-x64-v3.0-prod\</CuDnnPath> <ScriptsDir>$(SolutionDir)\scripts</ScriptsDir> </PropertyGroup>
Modify 2:
<PropertyGroupCondition="'$(PythonSupport)'=='true'"> <PythonDir>D:\Miniconda2\</PythonDir> <LibraryPath>$(PythonDir)\libs;$(LibraryPath)</LibraryPath> <IncludePath>$(PythonDir)\include;$(IncludePath)</IncludePath> </PropertyGroup>
Modify 3:
<PropertyGroupCondition="'$(MatlabSupport)'=='true'"> <MatlabDir>M:\ProgramFiles\MATLAB\R2015b</MatlabDir> <LibraryPath>$(MatlabDir)\extern\lib\win64\microsoft;$(LibraryPath)</LibraryPath> <IncludePath>$(MatlabDir)\extern\include;$(IncludePath)</IncludePath> </PropertyGroup>
(如果编译matlab的外部接口,此处还需要修改include目录路径,因为不同版本中matlab的include路径不一样)
Step 7:运行caffe,windows文件夹下的Caffe.sln, 生成libcaffe工程
(然后会弹出一个窗口,Nuget所需要的第三方库,可能会未响应,慢慢等吧)
Step 8: 修改caffe工程文件libcaffe.vcxproj和libcaffe.vcxproj.filters
修改libcaffe.vcxproj文件
在157行加入:
<ClCompile Include="..\..\src\caffe\layers\roi_pooling_layer.cpp"/>
在265行加入:
<ClInclude Include="..\..\include\caffe\layers\roi_pooling_layer.hpp"/>
在344行加入:
<CudaCompile Include="..\..\src\caffe\layers\roi_pooling_layer.cu" />
修改libcaffe.vcxproj.filters文件
在291行加入:
<ClCompileInclude="..\..\src\caffe\layers\roi_pooling_layer.cpp"> <Filter>src\layers</Filter> </ClCompile>
在569行加入:
<ClIncludeInclude="..\..\include\caffe\layers\roi_pooling_layer.hpp"> <Filter>include\layers</Filter> </ClInclude>
在781行加入:
<CudaCompileInclude="..\..\src\caffe\layers\roi_pooling_layer.cu"> <Filter>cu\layers</Filter> </CudaCompile>
(这一步是为了针对Checkfailed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: ROIPooling的错误)
Step 9:编译生成caffe的python外部依赖接口(在解决方案上点击右键,选择但启动项目,选择pycaffe进行编译)
Step 10: 将生成的python接口下的caffe(此接口在build文件夹下)拷贝到Miniconda2的目录下和frcnn的caffe-master目录下
Step 11: 更改frcnn下的lib,从网上下载windows版的lib
https://codeload.github.com/MrGF/py-faster-rcnn-windows/zip/master
Step 12: 下载faster-rcnn-models
http://www.cs.berkeley.edu/~rbg/faster-rcnn-data/faster_rcnn_models.tgz
http://www.cs.berkeley.edu/~rbg/faster-rcnn-data/imagenet_models.tgz
http://www.cs.berkeley.edu/~rbg/fast-rcnn-data/selective_search_data.tgz
Step 13:运行faster-rcnn demo.py程序
报错: AttributeError:‘ProposalLayer’ object has no attribute ‘param_str_’
修改param_str_为param_str,完成编译
报错: keyerror:’1’
将第64行改为cfg_key= ‘TEST’#str(self.phase), demo可以正常运行