【Caffe C++】VS2013下 配置 Caffe属性文件

新建一个工程,添加新的属性文件,名字为: 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;
}

运行结果

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

穆友航

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值