TF中百度warpCTC的安装

TF中百度warpCTC的安装:

一、环境描述
TF: 1.12
Linux: Ubuntu 16.0
CUDA: 9.2
—— 在docker环境中TF1.14, CUDA10.0编译未成功,非docker环境中TF1.12, CUDA:9.2编译成功

二、存在问题

  1. CMakeLists.txt的修改
    (1)CUDA 10.0链接:
    关于变量CUDA_curand_LIBRARY找不到
set(CUDA_curand_LIBRARY "/usr/local/cuda-10.0/lib64/libcurand.so.10.0")

(2)CUDA 10.0的CUDA_NVCC_FLAGS

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']
  1. 编译出libwarpctc.so
mkdir build
cd build 
cmake ..
make
  1. 安装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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值