|
| 1 | +// pybind/nnet3/nnet_nnet_pybind.cc |
| 2 | + |
| 3 | +// Copyright 2020 JD AI, Beijing, China (author: Lu Fan) |
| 4 | + |
| 5 | +// See ../../../COPYING for clarification regarding multiple authors |
| 6 | +// |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +// you may not use this file except in compliance with the License. |
| 9 | +// You may obtain a copy of the License at |
| 10 | +// |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +// |
| 13 | +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED |
| 15 | +// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, |
| 16 | +// MERCHANTABLITY OR NON-INFRINGEMENT. |
| 17 | +// See the Apache 2 License for the specific language governing permissions and |
| 18 | +// limitations under the License. |
| 19 | + |
| 20 | +#include "nnet3/nnet_nnet_pybind.h" |
| 21 | + |
| 22 | +#include "nnet3/nnet-nnet.h" |
| 23 | + |
| 24 | +using namespace kaldi; |
| 25 | +using namespace kaldi::nnet3; |
| 26 | + |
| 27 | +void pybind_nnet_nnet(py::module& m) { |
| 28 | + using PyClass = kaldi::nnet3::Nnet; |
| 29 | + auto nnet = py::class_<PyClass>( |
| 30 | + m, "Nnet", |
| 31 | + "This function can be used either to initialize a new Nnet from a " |
| 32 | + "config file, or to add to an existing Nnet, possibly replacing " |
| 33 | + "certain parts of it. It will die with error if something went wrong. " |
| 34 | + "Also see the function ReadEditConfig() in nnet-utils.h (it's made a " |
| 35 | + "non-member because it doesn't need special access)."); |
| 36 | + nnet.def(py::init<>()) |
| 37 | + .def("Read", &PyClass::Read, py::arg("is"), py::arg("binary")) |
| 38 | + .def("GetComponentNames", &PyClass::GetComponentNames, |
| 39 | + "returns vector of component names (needed by some parsing code, " |
| 40 | + "for instance).", |
| 41 | + py::return_value_policy::reference) |
| 42 | + .def("GetComponentName", &PyClass::GetComponentName, |
| 43 | + py::arg("component_index")) |
| 44 | + .def("Info", &PyClass::Info, |
| 45 | + "returns some human-readable information about the network, " |
| 46 | + "mostly for debugging purposes. Also see function NnetInfo() in " |
| 47 | + "nnet-utils.h, which prints out more extensive infoformation.") |
| 48 | + .def("NumComponents", &PyClass::NumComponents) |
| 49 | + .def("NumNodes", &PyClass::NumNodes) |
| 50 | + .def("GetComponent", (Component * (PyClass::*)(int32)) & PyClass::GetComponent, |
| 51 | + py::arg("c"), py::return_value_policy::reference); |
| 52 | +} |
0 commit comments