TensorFlow binding for CTC-CRF. An extension of thu-spmi/CAT for Tensorflow.
This is a modified version of thu-spmi/CAT. I just modify the code to the new CPP Extensions API style of Tensorflow and refact the gpu_den
code.
Because CTC-CRF operator is based on CUDA Toolkit, so you should setting CUDA environment. For details, you can follow this link or TensorFlow official link.
Environment Setup
Append the following lines to ~/.bashrc
or ~/.zshrc
.
export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Install TensorFlow with Anaconda virtual environment
Create a virtual environment is recommended. You can choose Conda or venv. Here I use Conda as an example.
# Install TensorFlow/cuda/nvcc first, reference is here:
conda create --name tf pip python==3.7
conda activate tf
conda install tensorflow-gpu==1.15.0
Install CTC-CRF TensorFlow wrapper
setting your TENSORFLOW_SRC_PATH
and OPENFST
.
NOTE: This is an example, please don't simply copy to your terminal:
# Create a symlink libtensorflow_framework.so.1 which references the original file libtensorflow_framework.so
ln -s /home/huanglk/anaconda3_202002/envs/tf_subcomp/lib/python3.7/site-packages/tensorflow_core/libtensorflow_framework.so.1 /home/huanglk/anaconda3_202002/envs/tf_subcomp/lib/python3.7/site-packages/tensorflow_core/libtensorflow_framework.so
# export TENSORFLOW_SRC_PATH
export TENSORFLOW_SRC_PATH=/home/huanglk/anaconda3_202002/envs/tf_subcomp/lib/python3.7/site-packages/tensorflow_core/
# export OPENFST
export OPENFST=/usr/local/
GPUCTC
, PATHWEIGHT
and GPUDEN
.Makefile
will exetucate python3 ./setup.py install
for CTC-CRF TensorFlow wrapper.Now, you can install CTC-Crf TensorFlow wrapper warp-ctc-crf
.
# Install warp_ctc_crf
cd warp_ctc_crf
make -j 32
Test:
tests/test_ctc_crf_op.py
is a simple test for Tensorflow API for CAT.Tensorflow API:
setup.py
: ctc_crf_loss setup script. It only test in g++ 5.0+ and Tensorflow 1.14.0ctc_crf_op_kernel.cc
: Tensorflow C++ binding.ctc_crf_tensorflow/__init__.py
: Tensorflow API for ctc_crf_loss.Others:
gpu_ctc/
: Just follow thu-spmi/CATgpu_den/
: Code refactoring from thu-spmi/CAT.