TF中百度warpCTC的安装:
一、环境描述
TF: 1.12
Linux: Ubuntu 16.0
CUDA: 9.2
—— 在docker环境中TF1.14, CUDA10.0编译未成功,非docker环境中TF1.12, CUDA:9.2编译成功
二、存在问题
- CMakeLists.txt的修改
(1)CUDA 10.0链接:
关于变量CUDA_curand_LIBRARY找不到
set(CUDA_curand_LIBRARY "/usr/local/cuda-10.0/lib64/libcurand.so.10.0")
IF (CUDA_VERSION GREATER 8.9)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode arch=compute_70,code=sm_70")
ENDIF()
IF (CUDA_VERSION GREATER 9.9)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode arch=compute_75,code=sm_75")
ENDIF()
(3)新的GCC 编译旧的C++ ABILine 8:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
同时tensorflow_binding下的setup.py文件修改Line 62:
extra_compile_args += [ '-D_GLIBCXX_USE_CXX11_ABI=0']
- 编译出libwarpctc.so
mkdir build
cd build
cmake ..
make
- 安装TF版本:
export TENSORFLOW_SRC_PATH="/usr/local/lib/python3.6/dist-packages/tensorflow"
export CUDA_HOME="/usr/local/cuda-10.0$CUDA_HOME"
export WARP_CTC_PATH="/root/Project/warp-ctc/build$WARP_CTC_PATH"
cd tensorflow_binding
python setup.py install
存在问题:
(1)“cannot find -ltensorflow_framework”
ln -s /usr/local/lib/python3.6/dist-packages/tensorflow/libtensorflow_framework.so.1 /usr/lib/libtensorflow_framework.so
——参考:https://yq.aliyun.com/articles/377598
(2)“ValueError: list.remove(x): x not in list ”
Line 122:
try:
self.compiler.compiler_so.remove('-Wstrict-prototypes')
except ValueError:
pass
(3)tenosrflow不同版本导致一些头文件的变更
src/ctc_op_kernel.cc:
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/bounds_check.h"
#include "tensorflow/core/util/sparse/sparse_tensor.h"
src/warpctc_op.cc:
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/bounds_check.h"
(3)运行
cd tests
python test_warpctc_op.py
出现问题:“tensorflow test error as_list() is not defined on an unknow tensorshape”
解决:修改./src/warpctc_op.cc
#include "tensorflow/core/framework/shape_inference.h"
using ::tensorflow::shape_inference::DimensionHandle;
using ::tensorflow::shape_inference::InferenceContext;
using ::tensorflow::shape_inference::ShapeHandle;
using ::tensorflow::Status;
REGISTER_OP("WarpCTC")
.Input("activations: float32")
.Input("flat_labels: int32")
.Input("label_lengths: int32")
.Input("input_lengths: int32")
.Attr("blank_label: int = 0")
.Output("costs: float32")
.Output("gradients: float32")
.SetShapeFn([](InferenceContext* c) {
ShapeHandle activations;
ShapeHandle flat_labels;
ShapeHandle label_lengths;
ShapeHandle input_lengths;
TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 3, &activations));
TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &flat_labels));
TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 1, &label_lengths));
TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 1, &input_lengths));
// Get batch size from inputs and sequence_length, and update inputs
// with the merged batch_size since it is returned.
DimensionHandle batch_size;
TF_RETURN_IF_ERROR(
c->Merge(c->Dim(activations, 1), c->Dim(input_lengths, 0), &batch_size));
TF_RETURN_IF_ERROR(c->ReplaceDim(activations, 1, batch_size, &activations));
c->set_output(0, c->Vector(batch_size));
c->set_output(1, activations);
return Status::OK();
});
重新运行:
cd tensorflow_binding
python setup.py install