新建一个工程,添加新的属性文件,名字为: Caffe_x64.props。
所有caffe需要的配置如下。
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IncludePath>H:\NugetPackages\OpenCV.2.4.10\build\native\include;H:\NugetPackages\OpenBLAS.0.2.14.1\lib\native\include;H:\NugetPackages\protobuf-v120.2.6.1\build\native\include;H:\NugetPackages\glog.0.3.3.0\build\native\include;H:\NugetPackages\gflags.2.1.2.1\build\native\include;H:\NugetPackages\boost.1.59.0.0\lib\native\include;H:\CaffeDIY_SegNet\include\caffe;H:\CaffeDIY_SegNet\include;$(IncludePath)</IncludePath>
<LibraryPath>H:\NugetPackages\OpenCV.2.4.10\build\native\lib\x64\v120\Release;H:\NugetPackages\hdf5-v120-complete.1.8.15.2\lib\native\lib\x64;H:\NugetPackages\OpenBLAS.0.2.14.1\lib\native\lib\x64;H:\NugetPackages\gflags.2.1.2.1\build\native\x64\v120\dynamic\Lib;H:\NugetPackages\glog.0.3.3.0\build\native\lib\x64\v120\Release\dynamic;H:\NugetPackages\protobuf-v120.2.6.1\build\native\lib\x64\v120\Release;H:\NugetPackages\boost_chrono-vc120.1.59.0.0\lib\native\address-model-64\lib;H:\NugetPackages\boost_system-vc120.1.59.0.0\lib\native\address-model-64\lib;H:\NugetPackages\boost_thread-vc120.1.59.0.0\lib\native\address-model-64\lib;H:\NugetPackages\boost_filesystem-vc120.1.59.0.0\lib\native\address-model-64\lib;H:\NugetPackages\boost_date_time-vc120.1.59.0.0\lib\native\address-model-64\lib;H:\CaffeDIY_SegNet\Build\x64\Release;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Label="Globals">
<CudaToolkitCustomDir>
</CudaToolkitCustomDir>
</PropertyGroup>
<ItemDefinitionGroup>
<Link>
<AdditionalDependencies>libcaffe.lib;libprotobuf.lib;libglog.lib;gflags.lib;libopenblas.dll.a;hdf5.lib;hdf5_hl.lib;cublas.lib;cublas_device.lib;cuda.lib;cudadevrt.lib;cudnn.lib;cudart.lib;cufft.lib;cudart_static.lib;cufftw.lib;cusparse.lib;cusolver.lib;curand.lib;nppc.lib;opencv_highgui2410.lib;opencv_core2410.lib;opencv_imgproc2410.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<CudaCompile>
<TargetMachinePlatform>64</TargetMachinePlatform>
</CudaCompile>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
测试代码:
caffe_layer.h
#include<caffe/common.hpp>
#include<caffe/proto/caffe.pb.h>
#include<caffe/layers/batch_norm_layer.hpp>
#include<caffe/layers/bias_layer.hpp>
#include <caffe/layers/concat_layer.hpp>
#include <caffe/layers/conv_layer.hpp>
#include <caffe/layers/dropout_layer.hpp>
#include<caffe/layers/input_layer.hpp>
#include <caffe/layers/inner_product_layer.hpp>
#include "caffe/layers/lrn_layer.hpp"
#include <caffe/layers/pooling_layer.hpp>
#include <caffe/layers/relu_layer.hpp>
#include "caffe/layers/softmax_layer.hpp"
#include<caffe/layers/scale_layer.hpp>
namespace caffe
{
extern INSTANTIATE_CLASS(BatchNormLayer);
extern INSTANTIATE_CLASS(BiasLayer);
extern INSTANTIATE_CLASS(InputLayer);
extern INSTANTIATE_CLASS(InnerProductLayer);
extern INSTANTIATE_CLASS(DropoutLayer);
extern INSTANTIATE_CLASS(ConvolutionLayer);
REGISTER_LAYER_CLASS(Convolution);
extern INSTANTIATE_CLASS(ReLULayer);
REGISTER_LAYER_CLASS(ReLU);
extern INSTANTIATE_CLASS(PoolingLayer);
REGISTER_LAYER_CLASS(Pooling);
extern INSTANTIATE_CLASS(LRNLayer);
REGISTER_LAYER_CLASS(LRN);
extern INSTANTIATE_CLASS(SoftmaxLayer);
REGISTER_LAYER_CLASS(Softmax);
extern INSTANTIATE_CLASS(ScaleLayer);
extern INSTANTIATE_CLASS(ConcatLayer);
}
main.cpp
#include<caffe.hpp>
#include <string>
#include <vector>
#include "caffe_layer.h"
using namespace caffe;
using namespace std;
int main() {
//string net_file = "H:/CaffeExamples/Caltech256/ResNet50/ResNet-50-deploy.prototxt";
//string weight_file = "H:/CaffeExamples/Caltech256/ResNet50/model/caltech256_ResNet__iter_110000.caffemodel";
string net_file = "H:/CaffeExamples/GTSRB/cifar10_quick.prototxt";
string weight_file = "H:/CaffeExamples/GTSRB/GTSRB_iter_5000.caffemodel";
Caffe::set_mode(Caffe::GPU);
Caffe::SetDevice(0);
Phase phase = TEST;
boost::shared_ptr<Net<float>> net(new caffe::Net<float>(net_file, phase));
net->CopyTrainedLayersFrom(weight_file);
vector<string> blob_names=net->blob_names();
for (int i = 0; i < blob_names.size(); i++){
cout << blob_names.at(i) << endl;
}
return 0;
}
运行结果