windows平台下caffe可视化配置

平台环境

windows8.1,visual studio 2013 ,Anaconda2(本文安装路径为C:\Anaconda2),暂时无GPU支持

步骤

1.编译pycaffe

  • 从https://github.com/happynear/caffe-windows下载caffe,编译过程不再赘述,只讲pycaffe编译过程配置。
  • 配置python和numpy所需的头文件和库文件。打开 Property Manager ,在Release|x64 中添加项Python,如下图:
    windows平台下caffe可视化配置_第1张图片
  • 用记事本打开Python.props修改文件内容如下:
 
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <IncludePath>C:\Anaconda2\include;C:\Anaconda2\Lib\site-packages\numpy\core\include;$(IncludePath)IncludePath>
    <LibraryPath>C:\Anaconda2\libs;$(LibraryPath)LibraryPath>
  PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <AdditionalDependencies>python27.lib;%(AdditionalDependencies)AdditionalDependencies>
    Link>
  ItemDefinitionGroup>
  <ItemGroup/>
Project>
  • 以上路径可以根据实际情况改变
  • 编译输出路径为../../python/caffe,打开输出路径将整个输出路径中的caffe 文件夹拷贝到C:\Anaconda2\Lib中

2. 安装protobuf的python版本

  • 从https://github.com/google/protobuf/releases下载相应的python版protobuf,根据readme安装,注意python环境变量配置为Anaconda的安装目录
  • 新建文件visualization.bat,visualization.py内容分别如下
  • visualization.bat:
 SET Path=D:\caffe\caffe-windows\3rdparty\bin;D:\Program Files\opencv\x64\vc12\bin;D:\caffe\caffe-windows\bin;C:\Anaconda2;
 python visualization.py
pause
  • visualization.py:显示vgg的conv1_1层(vggnet模型和网络文件下载:http://www.robots.ox.ac.uk/~vgg/software/vgg_face/)
 # -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import numpy as np
import matplotlib.pyplot as plt
import os,sys,caffe
def show_feature(data, padsize=1, padval=0):
    data -= data.min()
    data /= data.max()

    # force the number of filters to be square
    n = int(np.ceil(np.sqrt(data.shape[0])))
    padding = ((0, n ** 2 - data.shape[0]), (0, padsize), (0, padsize)) + ((0, 0),) * (data.ndim - 3)
    data = np.pad(data, padding, mode='constant', constant_values=(padval, padval))

    # tile the filters into an image
    data = data.reshape((n, n) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(range(4, data.ndim + 1)))
    data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:])
    plt.imshow(data)
    plt.axis('off')
    plt.show()
if __name__ == '__main__':
    plt.rcParams['figure.figsize'] = (8, 8)
    plt.rcParams['image.interpolation'] = 'nearest'
    plt.rcParams['image.cmap'] = 'gray'
    net = caffe.Net('D:/caffe/vgg_face_caffe/VGG_FACE_deploy_back.prototxt',
                'D:/caffe/vgg_face_caffe/VGG_FACE.caffemodel',
                caffe.TEST)
    print [(k, v[0].data.shape) for k, v in net.params.items()]
    weight = net.params["conv1_1"][0].data
    print weight.shape
    show_feature(weight.transpose(0, 2, 3, 1))

3.运行visualization.bat

windows平台下caffe可视化配置_第2张图片

  • 可以参照博客http://www.cnblogs.com/denny402/p/5103425.html输出其他层

你可能感兴趣的:(caffe,caffe)