【caffe-Windows】微软官方caffe之 Python接口配置及图片生成实例

前言

发现许多代码还是用python写的,所以还是配置一下接口吧,虽然博主不会Python,咳咳。在这里使用的python安装包是anaconda2,注意使用Python2.7版本的那个安装包

官网地址:https://www.continuum.io/downloads

百度云:链接:http://pan.baidu.com/s/1nvrrfQx 密码:1jg5

测试的实例是2015年一篇利用噪声生成一张真实图片的代码,使用的caffe+python时下

注意一下,我第一安装的时候竟然没有jupyter notebook,所以卸载了一下,又重新安装了一次anaconda,安装过程直接各种下一步就行了。

测试方法是直接在dos输入jupyter notebook,看是否有一个网页弹出来。

C:\Users\Bingo>jupyter notebook
[I 10:16:40.512 NotebookApp] [nb_conda_kernels] enabled, 2 kernels found
[I 10:16:41.680 NotebookApp] 鉁?nbpresent HTML export ENABLED
[W 10:16:41.680 NotebookApp] 鉁?nbpresent PDF export DISABLED: No module named n
bbrowserpdf.exporters.pdf
[I 10:16:41.690 NotebookApp] [nb_conda] enabled
[I 10:16:41.812 NotebookApp] [nb_anacondacloud] enabled
[I 10:16:42.140 NotebookApp] Serving notebooks from local directory: C:\Users\Bi
ngo
[I 10:16:42.140 NotebookApp] 0 active kernels
[I 10:16:42.141 NotebookApp] The Jupyter Notebook is running at: http://localhos
t:8888/
[I 10:16:42.141 NotebookApp] Use Control-C to stop this server and shut down all
 kernels (twice to skip confirmation).


第一步

编译caffe接口,修改配置文件CommonSettings.props:

第13行:

        true
第48行:

        C:\Program Files\Anaconda2\
然后保存,去编译 Release版本的pycaffe,好像如果编译Debug版本会出现python27_d.lib找不到什么的。


等编译完成以后,有如下文件夹:


直接将caffe这个文件夹拷贝到C:\Program Files\Anaconda2\Lib\site-packages即可。


第二步

试试import caffe

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Bingo>python
Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.
1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import caffe
这一步应该会出现不同的问题,我出现的是
ImportError: No module named google.protobuf.internal
这个错误,反正只要跟protobuf相关的错误,你就直接在dos下安装,方法是:
C:\windows\system32>conda install protobuf

【PS】此处有的读者使用这个命令安装可能出现问题,如果不行的话就用pip install protobuf 安装吧,因为我当时用pip安装出问题了,所以只写了conda安装方法,两个都试试吧

然后就会慢慢安装,安装过程如下:

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\windows\system32>conda install protobuf
Fetching package metadata ..........Could not connect to https://repo.continuum
io/pkgs/free/win-64/
........
Solving package specifications: ..........

Package plan for installation in environment C:\Program Files\Anaconda2:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    conda-env-2.5.2            |           py27_0          66 KB  conda-forge
    conda-4.1.12               |           py27_0         263 KB  conda-forge
    protobuf-3.0.0             |       py27_vc9_0        11.1 MB  conda-forge
    ------------------------------------------------------------
                                           Total:        11.4 MB

The following NEW packages will be INSTALLED:

    conda-env: 2.5.2-py27_0     conda-forge
    protobuf:  3.0.0-py27_vc9_0 conda-forge [vc9]

The following packages will be SUPERCEDED by a higher-priority channel:

    conda:     4.2.9-py27_0                 --> 4.1.12-py27_0 conda-forge

Proceed ([y]/n)? y

Fetching packages ...
conda-env-2.5. 100% |###############################| Time: 0:00:01  35.70 kB/s
conda-4.1.12-p 100% |###############################| Time: 0:00:03  71.46 kB/s
protobuf-3.0.0 100% |###############################| Time: 0:02:02  94.90 kB/s
Extracting packages ...
[      COMPLETE      ]|##################################################| 100%
Unlinking packages ...
[      COMPLETE      ]|##################################################| 100%
Linking packages ...
[      COMPLETE      ]|##################################################| 100%

C:\windows\system32>
安装完毕,再去试试能否导入caffe:

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Bingo>python
Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.
1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import caffe
C:\Program Files\Anaconda2\lib\site-packages\caffe\pycaffe.py:13: RuntimeWarning
: to-Python converter for class boost::shared_ptr > alre
ady registered; second conversion method ignored.
  from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
C:\Program Files\Anaconda2\lib\site-packages\caffe\pycaffe.py:13: RuntimeWarning
: to-Python converter for class boost::shared_ptr > alr
eady registered; second conversion method ignored.
  from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
C:\Program Files\Anaconda2\lib\site-packages\caffe\pycaffe.py:13: RuntimeWarning
: to-Python converter for class boost::shared_ptr > a
lready registered; second conversion method ignored.
  from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
>>>
我这里有三个warning,看网上说不用管即可,如果有轻微强迫症,不想看到warning,可以去google上搜一下,有 解决方案,需要修改cpp文件的东西,接下来我们引入一下实例看看效果。

第三步:

使用的实例是Texture Synthesis with Convolutional Neural Networks这篇论文的代码,主要实现的是利用噪声生成一张真实图片。
原文地址:https://arxiv.org/abs/1505.07376

github地址:https://github.com/leongatys/DeepTextures

百度云地址:链接:http://pan.baidu.com/s/1qYaqcZ6 密码:5cm9

使用方法是先打开jupyter notebook

【注意】此处打开的路径是你的代码解压以后的位置


Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Bingo>E:

E:\>cd E:\caffe-code\DeepTextures-master

E:\caffe-code\DeepTextures-master>jupyter notebook
[I 10:38:58.658 NotebookApp] [nb_conda_kernels] enabled, 2 kernels found
[I 10:38:59.819 NotebookApp] 鉁?nbpresent HTML export ENABLED
[W 10:38:59.819 NotebookApp] 鉁?nbpresent PDF export DISABLED: No module named n
bbrowserpdf.exporters.pdf
[I 10:38:59.829 NotebookApp] [nb_conda] enabled
[I 10:38:59.951 NotebookApp] [nb_anacondacloud] enabled
[I 10:39:00.283 NotebookApp] Serving notebooks from local directory: E:\caffe-co
de\DeepTextures-master
[I 10:39:00.283 NotebookApp] 0 active kernels
[I 10:39:00.283 NotebookApp] The Jupyter Notebook is running at: http://localhos
t:8888/
[I 10:39:00.285 NotebookApp] Use Control-C to stop this server and shut down all
 kernels (twice to skip confirmation).
然后浏览器弹出的页面会有当前目录的文件:



然后点击Example.ipynb,使用快捷键shift+Enter逐步运行,最后会出现一个迭代生成过程,就是一张图片一闪一闪的,但是我看其它人的都是由一个iteration数字在上面,不过不管怎么样,这样就是在生成图片了:



你可能感兴趣的:(caffe)