senlinuc / caffe_ocr

主流ocr算法研究实验性的项目,目前实现了CNN+BLSTM+CTC架构
1.26k stars 535 forks source link

关于整合入linux版本caffe #10

Open ericshijian opened 6 years ago

ericshijian commented 6 years ago

您好,关于整合进linux版本caffe,目前卡在warp-ctc相关的几个层(编译总是报错),不知道是否需要特殊处理?

AllenDuane commented 6 years ago

@ericshijian 请问你是怎么合并到Linux的呢?具体过程能不能讲一下? 多谢啦

senlinuc commented 6 years ago

@ericshijian 编译问题解决了吗?具体是什么错误?

zhousteven commented 6 years ago

你好,请问如何将代码整合到linux系统进行编译?好像这个问题,能否给出步骤?

huiyang865 commented 6 years ago

有哪位大佬可以给出整合代码到linux系统中的具体步骤么?

zhousteven commented 6 years ago

我有整理好的代码,步骤没有记录,我今天放到百度盘上,然后我贴链接:http://pan.baidu.com/s/1o8mQBjW 密码:irzd

senlinuc commented 6 years ago

赞一个

onedreame commented 6 years ago

@zhousteven 你好,我用你编译的Linux版本的caffe用cmake编译会出现下面的错误 -- Found the following Boost libraries: -- python -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)

-- Caffe Configuration Summary -- General: -- Version : 1.0.0-rc4 -- Git : unknown -- System : Linux -- C++ compiler : /usr/bin/c++ -- Release CXX flags : -O3 -DNDEBUG -D_FORCE_INLINES -fPIC -Wall -Wno-sign-compare -Wno-uninitialized -- Debug CXX flags : -g -D_FORCE_INLINES -fPIC -Wall -Wno-sign-compare -Wno-uninitialized -- Build type : Release

-- BUILD_SHARED_LIBS : ON -- BUILD_python : ON -- BUILD_matlab : OFF -- BUILD_docs : ON -- CPU_ONLY : OFF -- USE_OPENCV : ON -- USE_LEVELDB : ON -- USE_LMDB : ON -- USE_NCCL : OFF -- USE_WARP_CTC : ON -- ALLOW_LMDB_NOLOCK : OFF

-- Dependencies: -- BLAS : Yes (Atlas) -- Boost : Yes (ver. 1.58) -- glog : Yes -- gflags : Yes -- protobuf : Yes (ver. 3.1.0) -- lmdb : Yes (ver. 0.9.17) -- LevelDB : Yes (ver. 1.18) -- Snappy : Yes (ver. 1.1.3) -- OpenCV : Yes (ver. 3.1.0) -- CUDA : Yes (ver. 8.0)

-- NVIDIA CUDA: -- Target GPU(s) : Auto -- GPU arch(s) : sm_61 -- cuDNN : Yes (ver. 5.1.5)

-- Python: -- Interpreter : /usr/bin/python2.7 (ver. 2.7.12) -- Libraries : /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12) -- NumPy : /usr/local/lib/python2.7/dist-packages/numpy/core/include (ver 1.13.3)

-- Documentaion: -- Doxygen : No -- config_file :

-- Install: -- Install path : /data2/yk/ocr/caffe/build/install

CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: WARP_CTC_INCLUDE_DIR used as include directory in directory /data2/yk/ocr/caffe used as include directory in directory /data2/yk/ocr/caffe used as include directory in directory /data2/yk/ocr/caffe used as include directory in directory /data2/yk/ocr/caffe used as include directory in directory /data2/yk/ocr/caffe used as include directory in directory /data2/yk/ocr/caffe used as include directory in directory /data2/yk/ocr/caffe used as include directory in directory /data2/yk/ocr/caffe used as include directory in directory /data2/yk/ocr/caffe used as include directory in directory /data2/yk/ocr/caffe/src/gtest used as include directory in directory /data2/yk/ocr/caffe/src/gtest used as include directory in directory /data2/yk/ocr/caffe/src/gtest used as include directory in directory /data2/yk/ocr/caffe/src/gtest used as include directory in directory /data2/yk/ocr/caffe/src/gtest used as include directory in directory /data2/yk/ocr/caffe/src/gtest used as include directory in directory /data2/yk/ocr/caffe/src/gtest used as include directory in directory /data2/yk/ocr/caffe/src/caffe used as include directory in directory /data2/yk/ocr/caffe/src/caffe used as include directory in directory /data2/yk/ocr/caffe/src/caffe used as include directory in directory /data2/yk/ocr/caffe/src/caffe used as include directory in directory /data2/yk/ocr/caffe/src/caffe used as include directory in directory /data2/yk/ocr/caffe/src/caffe used as include directory in directory /data2/yk/ocr/caffe/src/caffe used as include directory in directory /data2/yk/ocr/caffe/src/caffe used as include directory in directory /data2/yk/ocr/caffe/src/caffe/test used as include directory in directory /data2/yk/ocr/caffe/src/caffe/test used as include directory in directory /data2/yk/ocr/caffe/src/caffe/test used as include directory in directory /data2/yk/ocr/caffe/src/caffe/test used as include directory in directory /data2/yk/ocr/caffe/src/caffe/test used as include directory in directory /data2/yk/ocr/caffe/src/caffe/test used as include directory in directory /data2/yk/ocr/caffe/src/caffe/test used as include directory in directory /data2/yk/ocr/caffe/src/caffe/test used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/tools used as include directory in directory /data2/yk/ocr/caffe/examples used as include directory in directory /data2/yk/ocr/caffe/examples used as include directory in directory /data2/yk/ocr/caffe/examples used as include directory in directory /data2/yk/ocr/caffe/examples used as include directory in directory /data2/yk/ocr/caffe/examples used as include directory in directory /data2/yk/ocr/caffe/examples used as include directory in directory /data2/yk/ocr/caffe/examples used as include directory in directory /data2/yk/ocr/caffe/examples used as include directory in directory /data2/yk/ocr/caffe/examples used as include directory in directory /data2/yk/ocr/caffe/examples used as include directory in directory /data2/yk/ocr/caffe/python used as include directory in directory /data2/yk/ocr/caffe/python used as include directory in directory /data2/yk/ocr/caffe/python used as include directory in directory /data2/yk/ocr/caffe/python used as include directory in directory /data2/yk/ocr/caffe/python used as include directory in directory /data2/yk/ocr/caffe/python used as include directory in directory /data2/yk/ocr/caffe/python used as include directory in directory /data2/yk/ocr/caffe/matlab used as include directory in directory /data2/yk/ocr/caffe/matlab used as include directory in directory /data2/yk/ocr/caffe/matlab used as include directory in directory /data2/yk/ocr/caffe/matlab used as include directory in directory /data2/yk/ocr/caffe/matlab used as include directory in directory /data2/yk/ocr/caffe/matlab used as include directory in directory /data2/yk/ocr/caffe/docs used as include directory in directory /data2/yk/ocr/caffe/docs used as include directory in directory /data2/yk/ocr/caffe/docs used as include directory in directory /data2/yk/ocr/caffe/docs used as include directory in directory /data2/yk/ocr/caffe/docs used as include directory in directory /data2/yk/ocr/caffe/docs

-- Configuring incomplete, errors occurred! See also "/data2/yk/ocr/caffe/build/CMakeFiles/CMakeOutput.log". See also "/data2/yk/ocr/caffe/build/CMakeFiles/CMakeError.log". 请问这是怎么回事?是没找到wrapctc的目录么

zhousteven commented 6 years ago

我改动了CTC的代码如下: 在cpu_ctc.h及cpu_ctc.cuh中使用 \caffe_win2linux\caffe_ocr-master\include\detail\cpu_ctc.h第8行要添加

define CTC_DISABLE_OMP 之前是为了屏蔽GPU,因为我的机器只支持CPU,所以打开GPU会发生什么问题,不是很清楚;

从日志文件看,您使用了GPU,请先确认您是否链接openmp的库吧,然后将#define CTC_DISABLE_OMP删除再做尝试,

billyzju commented 6 years ago

@zhousteven 貌似你这个Linux版本的改动CPU-ONLY的不止一处啊,我看了看代码,error: no matching function for call to ‘caffe::DenseBlockLayer::reshape_gpu_data(int&, int&, int&, int&, int&, int&)’ reshape_gpu_data(this->H, this->W,this->N, h, w,batch_size); ,是不是你把DenseBlockLayer里面全部改成不用GPU而用CPU了?我这边编译都不过。

billyzju commented 6 years ago

@zhousteven 头文件声明的reshap_gpu_data的和cpp文件里面调用和相应实现的参数个数不一致,不知道怎么编译通过的? candidate expects 4 arguments, 6 provided src/caffe/layers/DenseBlock_layer.cpp: In instantiation of ‘void caffe::DenseBlockLayer::Reshape(const std::vector<caffe::Blob>&, const std::vector<caffe::Blob>&) [with Dtype = double]’: src/caffe/layers/DenseBlock_layer.cpp:1027:2: required from here src/caffe/layers/DenseBlock_layer.cpp:234:19: error: no matching function for call to ‘caffe::DenseBlockLayer::reshape_gpu_data(int&, int&, int&, int&, int&, int&)’ reshape_gpu_data(this->H, this->W,this->N, h, w,batch_size);

billyzju commented 6 years ago

@zhousteven 看了作者提供的源代码,hpp文件定义的reshape_gpu_data的hpp文件里面是6个参数,你这改的有点太离谱了吧

FLHonker commented 6 years ago

@zhousteven ,傻帽?你放的是啥源码?明明是caffe原本的好不好。

berli commented 6 years ago

@FLHonker 这个caffe还编译不过

FLHonker commented 6 years ago

@berli ,绝对是唬人的

JackLongKing commented 5 years ago

我现在编译好了。其实就是添加几个层,另外就是编译warp-ctc时将动态库给链接一下就好了。 @ericshijian

ghost commented 5 years ago

@JackLongKing 怎么解决的,能分享下么

JackLongKing commented 5 years ago

1.如果不加warp-ctc的话,相对比较容易。步骤如下:(1)将对应的.hpp,.cpp,.cu放入对应的位置(src/caffe/layers(.hpp),include/caffe/layers(.cpp,.cu));(2)修改src/caffe/proto/caffe.proto,在message LayerParameter数据结构中添加对应的信息。下面是我添加的层的相关信息(注意数字不能与现有层冲突)。

=======================================

_optional DenseBlockParameter denseblock_param = 147; optional LSTMParameter lstm_param = 148; //lstm of junhyuk optional ReverseParameter reverse_param = 149; optional ReverseTimeParameter reverse_time_param = 150; optional TransposeParameter transpose_param=151; optional CtcDecoderParameter ctc_decoder_param = 152; optional WarpCtcLossParameter warp_ctc_loss_param = 153; // for warpctc loss

======================================

然后在caffe.proto最后面加入相关层对应的结构,即message。如下

======================================

message DenseBlockParameter { //if you don't use BC, BN-ReLU-Conv3 is one transition //if you use BC, then BN-ReLU-Conv1-BN-ReLU-Conv3 is one transition optional int32 numTransition = 1 [default = 40]; optional int32 initChannel = 2 [default = 16]; optional int32 growthRate = 3 [default = 12]; //Convolution related parameters optional int32 pad_h = 4 [default = 1]; optional int32 pad_w = 5 [default = 1]; optional int32 conv_verticalStride = 6 [default = 1]; optional int32 conv_horizentalStride = 7 [default = 1]; optional int32 filter_H = 8 [default = 3]; optional int32 filter_W = 9 [default = 3]; optional FillerParameter Filter_Filler = 10; //BN related parameters optional FillerParameter BN_Scaler_Filler = 11; optional FillerParameter BN_Bias_Filler = 12; //Performance Related parameters optional int32 gpuIdx = 15 [default = 0]; //Dropout related parameter optional bool use_dropout = 16 [default = false]; optional float dropout_amount = 17 [default = 0]; optional bool use_BC = 18 [default = false]; //If it is not ultra space efficient, then it stores output data of conv1 optional bool BC_ultra_space_efficient = 19 [default = false]; optional int32 workspace_MB = 20 [default = 8]; optional float moving_average_fraction = 21 [default = 0.1]; }

message LSTMParameter { optional uint32 num_output = 1; // The number of outputs for the layer optional float clipping_threshold = 2 [default = 0.0]; optional FillerParameter weight_filler = 3; // The filler for weight optional FillerParameter bias_filler = 4; // The filler for the bias optional uint32 batch_size = 5 [default = 1]; }

message ReverseParameter { // axis controls the data axis which shall be inverted. // The layout of the content will not be inverted // // The default axis is 0 that means: // data_previous[n] == data_afterwards[N - n -1] // where N is the shape of axis(n) // // Usually this layer will be used with recurrent layers to invert the // time axis which is axis 0 // This layer will therefore swap the order in time but not the // order of the actual data. optional int32 axis = 1 [default = 0]; }

message ReverseTimeParameter { // if true the rest of the sequence will not be reversed but copied // if false no more operation will be performed for the reset. // this can lead to random numbers in the blob. optional bool copy_remaining = 1 [default = false]; }

message TransposeParameter { // For example, if you want to transpose NxCxHxW into WxNxHxC, // the parameter should be the following: // transpose_param { dim: 3 dim: 0 dim: 2 dim: 1 } // ie, if the i-th dim has value n, then the i-th axis of top is equal to the n-th axis of bottom. repeated int32 dim=1; }

message CtcDecoderParameter { // The index of the blank index in the labels. A negative (default) // value will use the last index optional int32 blank_index = 1 [default = 0];

// Collapse the repeated labels during the ctc calculation // e.g. collapse [0bbb11bb11bb0b2] to [01102] instead of [0111102], // where b means blank label. // The default behaviour is to merge repeated labels. // Note: blank labels will be removed in any case. optional bool ctc_merge_repeated = 2 [default = true]; } message WarpCtcLossParameter { // Adds delayed output to the CTC loss calculation (untested!) optional int32 output_delay = 1 [default = 0];

// The index of the blank index in the labels. A negative (default) // value will use the last index optional int32 blank_index = 2 [default = 0];

// Collapse repeating labels of the target sequence before calculating // the loss and the gradients (e.g. collapse [01102] to [0102]) // The default behaviour is to keep repeated labels. Elsewise the // network will not learn to predict repetitions. optional bool preprocess_collapse_repeated = 3 [default = false];

// Collapse the repeated labels during the ctc calculation // e.g collapse [0bbb11bb11bb0b2] to [01102] instead of [0111102], // where b means blank label. // The default behaviour is to merge repeated labels. // Note: blank labels will be removed in any case. optional bool ctc_merge_repeated = 4 [default = true];

/// This parameter is for test cases only! /// The time for which to calculate the loss (see Graves Eq. (7.27) ) /// Note that the result must be the same for each 0 <= t < T /// Therefore you can chose an arbitrary value, default 0 optional int32 loss_calculation_t = 5 [default = 0]; }

=========================================

@greatgeekgrace

JackLongKing commented 5 years ago

2.如果要加入warp-ctc,首先参考https://github.com/kasyoukin/caffe_ocr_for_linux,编译libwarpctc.so,然后修改Makefile.config加入libwarpctc.so所在位置,修改Makefile,加入库名"warpctc"。然后按上述1所描述方法添加layer,编译应该就可以了。运行的时候,将libwarpctc.so复制到caffe根目录,就可以运行了。