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.
- Install CUDA Toolkit
- Follow this link to download and install CUDA Toolkit for your Linux distribution.
- Installation instructions can be found here
-
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
andOPENFST
.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/
- It will compile three modules with gcc/g++, include
GPUCTC
,PATHWEIGHT
andGPUDEN
. - It is worth mentioning that if the version of gcc/g++ >= 5.0.0 and less than 6.0.0 will be helpful for following pipeline.
- Finally,
Makefile
will exetucatepython3 ./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
- It will compile three modules with gcc/g++, include
-
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.