From e70b4b35dff5f32dfe73b59e39cb5c7c703818ae Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Wed, 14 Mar 2018 03:04:23 -0700 Subject: [PATCH] Add pybind11 wrapper for decoder --- fluid/DeepASR/decoder/decoder.cc | 21 ++++++++++++++++ fluid/DeepASR/decoder/decoder.h | 18 ++++++++++++++ fluid/DeepASR/decoder/pybind.cc | 29 ++++++++++++++++++++++ fluid/DeepASR/decoder/setup.py | 41 ++++++++++++++++++++++++++++++++ fluid/DeepASR/decoder/setup.sh | 7 ++++++ 5 files changed, 116 insertions(+) create mode 100644 fluid/DeepASR/decoder/decoder.cc create mode 100644 fluid/DeepASR/decoder/decoder.h create mode 100644 fluid/DeepASR/decoder/pybind.cc create mode 100644 fluid/DeepASR/decoder/setup.py create mode 100644 fluid/DeepASR/decoder/setup.sh diff --git a/fluid/DeepASR/decoder/decoder.cc b/fluid/DeepASR/decoder/decoder.cc new file mode 100644 index 00000000..a99f972e --- /dev/null +++ b/fluid/DeepASR/decoder/decoder.cc @@ -0,0 +1,21 @@ +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include "decoder.h" + +std::string decode(std::vector> probs_mat) { + // Add decoding logic here + + return "example decoding result"; +} diff --git a/fluid/DeepASR/decoder/decoder.h b/fluid/DeepASR/decoder/decoder.h new file mode 100644 index 00000000..4a67fa36 --- /dev/null +++ b/fluid/DeepASR/decoder/decoder.h @@ -0,0 +1,18 @@ +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include +#include + +std::string decode(std::vector> probs_mat); diff --git a/fluid/DeepASR/decoder/pybind.cc b/fluid/DeepASR/decoder/pybind.cc new file mode 100644 index 00000000..8cd65903 --- /dev/null +++ b/fluid/DeepASR/decoder/pybind.cc @@ -0,0 +1,29 @@ +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include +#include + +#include "decoder.h" + +namespace py = pybind11; + +PYBIND11_MODULE(decoder, m) { + m.doc() = "Decode function for Deep ASR model"; + + m.def("decode", + &decode, + "Decode one input probability matrix " + "and return the transcription"); +} diff --git a/fluid/DeepASR/decoder/setup.py b/fluid/DeepASR/decoder/setup.py new file mode 100644 index 00000000..cedd5d64 --- /dev/null +++ b/fluid/DeepASR/decoder/setup.py @@ -0,0 +1,41 @@ +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from distutils.core import setup, Extension +from distutils.sysconfig import get_config_vars + +args = ['-std=c++11'] + +# remove warning about -Wstrict-prototypes +(opt, ) = get_config_vars('OPT') +os.environ['OPT'] = " ".join(flag for flag in opt.split() + if flag != '-Wstrict-prototypes') + +ext_modules = [ + Extension( + 'decoder', + ['pybind.cc', 'decoder.cc'], + include_dirs=['pybind11/include', '.'], + language='c++', + extra_compile_args=args, ), +] + +setup( + name='decoder', + version='0.0.1', + author='Paddle', + author_email='', + description='Decoder for Deep ASR model', + ext_modules=ext_modules, ) diff --git a/fluid/DeepASR/decoder/setup.sh b/fluid/DeepASR/decoder/setup.sh new file mode 100644 index 00000000..71fd6626 --- /dev/null +++ b/fluid/DeepASR/decoder/setup.sh @@ -0,0 +1,7 @@ + + +if [ ! -d pybind11 ]; then + git clone https://github.com/pybind/pybind11.git +fi + +python setup.py build_ext -i -- GitLab