码迷,mamicode.com
首页 > 其他好文 > 详细

caffe 动态库

时间:2018-05-24 12:03:39      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:names   instant   cti   stat   问题:   eve   boost   1.5   \n   

createdll.h
#ifndef CREARDLL_H_
#define CREARDLL_H_

extern "C" _declspec(dllexport) int add(int x, int y);/*_declspec(dllexport)声明一个导出函数,是说这个函数要从本DLL导出,我要给别人用。*/
int add(int x, int y);  //求和函数

#endif


createdll.cpp
#include"stdafx.h"  //注意不要忘了添加这个头文件
#include"creatdll.h"
#include<iostream>

int add(int x, int y)
{
    return x + y;
}


调用
#include<iostream>
#pragma comment(lib,"makeDLL.lib")

_declspec(dllimport) int add(int x, int y); //_declspec(dllimport)声明一个导入函数,是说这个函数是从别的DLL导入,我要用。

int main()
{
    std::cout << "2 + 3 = " << add(2, 3) << std::endl;

    std::cin.get();
    return 0;
}

 

 


#define CPU_ONLY


包含目录:
F:\caffe-windows\include

F:\NugetPackages\boost.1.59.0.0\lib\native\include

F:\NugetPackages\glog.0.3.3.0\build\native\include

F:\NugetPackages\gflags.2.1.2.1\build\native\include

F:\NugetPackages\protobuf-v120.2.6.1\build\native\include

F:\NugetPackages\OpenBLAS.0.2.14.1\lib\native\include

F:\NugetPackages\OpenCV.2.4.10\build\native\include

 

库目录:
F:\NugetPackages\lmdb-v120-clean.0.9.14.0\lib\native\lib\x64

F:\NugetPackages\LevelDB-vc120.1.2.0.0\build\native\lib\x64\v120\Release

F:\NugetPackages\OpenCV.2.4.10\build\native\lib\x64\v120\Release

F:\caffe-windows\Build\x64\Release

F:\opencv2.4.10\build\x64\vc12\lib

F:\NugetPackages\boost_date_time-vc120.1.59.0.0\lib\native\address-model-64\lib

F:\NugetPackages\boost_filesystem-vc120.1.59.0.0\lib\native\address-model-64\lib

F:\NugetPackages\boost_system-vc120.1.59.0.0\lib\native\address-model-64\lib

F:\NugetPackages\glog.0.3.3.0\build\native\lib\x64\v120\Release\dynamic

F:\NugetPackages\boost_thread-vc120.1.59.0.0\lib\native\address-model-64\lib

F:\NugetPackages\boost_chrono-vc120.1.59.0.0\lib\native\address-model-64\lib

F:\NugetPackages\gflags.2.1.2.1\build\native\x64\v120\static\Lib

F:\NugetPackages\hdf5-v120-complete.1.8.15.2\lib\native\lib\x64

F:\NugetPackages\protobuf-v120.2.6.1\build\native\lib\x64\v120\Release

F:\NugetPackages\OpenBLAS.0.2.14.1\lib\native\lib\x64


连接库
libboost_date_time-vc120-mt-1_59.lib
libboost_filesystem-vc120-mt-1_59.lib
libboost_system-vc120-mt-1_59.lib
libglog.lib
libcaffe.lib
gflags.lib
gflags_nothreads.lib
hdf5.lib
hdf5_hl.lib
libprotobuf.lib
libopenblas.dll.a
Shlwapi.lib
LevelDb.lib
lmdb.lib

E:\opencversiyio\build\x64\vc12\lib\opencv_video2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_objdetect2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_core2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_highgui2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_imgproc2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_ts2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_nonfree2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_ocl2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_photo2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_stitching2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_superres2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_videostab2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_calib3d2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_contrib2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_features2d2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_flann2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_gpu2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_legacy2410.lib
E:\opencversiyio\build\x64\vc12\lib\opencv_ml2410.lib

 

//注册问题

#include "caffe/common.hpp" 
#include "caffe/layers/input_layer.hpp" 
#include "caffe/layers/inner_product_layer.hpp" 
#include "caffe/layers/dropout_layer.hpp" 
#include "caffe/layers/conv_layer.hpp" 
#include "caffe/layers/relu_layer.hpp" 

#include "caffe/layers/pooling_layer.hpp" 
#include "caffe/layers/lrn_layer.hpp" 
#include "caffe/layers/softmax_layer.hpp" 
#include "caffe/layers/normalize_layer.hpp"
#include "caffe/layers/permute_layer.hpp"
#include "caffe/layers/flatten_layer.hpp"
#include "caffe/layers/prior_box_layer.hpp"
#include "caffe/layers/concat_layer.hpp"
#include "caffe/layers/reshape_layer.hpp"
#include "caffe/layers/softmax_layer.hpp"
#include "caffe/layers/detection_output_layer.hpp"


namespace caffe
{
extern INSTANTIATE_CLASS(InputLayer);
extern INSTANTIATE_CLASS(ConvolutionLayer);
REGISTER_LAYER_CLASS(Convolution);
extern INSTANTIATE_CLASS(InnerProductLayer);
extern INSTANTIATE_CLASS(DropoutLayer);
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(NormalizeLayer);
//REGISTER_LAYER_CLASS(Normalize);
extern INSTANTIATE_CLASS(PermuteLayer);
//REGISTER_LAYER_CLASS(Permute);
extern INSTANTIATE_CLASS(FlattenLayer);
extern INSTANTIATE_CLASS(PriorBoxLayer);
extern INSTANTIATE_CLASS(ConcatLayer);
extern INSTANTIATE_CLASS(ReshapeLayer);
extern INSTANTIATE_CLASS(SoftmaxLayer);
REGISTER_LAYER_CLASS(Softmax);
extern INSTANTIATE_CLASS(DetectionOutputLayer);
}

#endif

这时还会遇到一个麻烦的问题,添加了REGISTER_LAYER_CLASS()他会报重复注册,去掉这一句又报不认识这一层。
在layer_factory.hpp里做如下更改可以解决这个问题:

把static void AddCreator(const string& type, Creator creator){}里的:
    CHECK_EQ(registry.count(type), 0)<< "Layer type " << type << " already registered.";
    registry[type] = creator;

改为:

if (registry.count(type) != 0)
{
std::cout<< "Layer type " << type << " already registered.     ";
}
else
{
registry[type] = creator;
}
这样就能确保只注册一次了。

 

caffe 动态库

标签:names   instant   cti   stat   问题:   eve   boost   1.5   \n   

原文地址:https://www.cnblogs.com/crazybird123/p/9081445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!