mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 09:07:10 +08:00

* Add notes for tensors * Optimize some apis * move some warnings * Support build with Paddle2ONNX * Add protobuf support * Fix compile on mac * add clearn package script * Add paddle2onnx code * remove submodule * Add onnx ocde * remove softlink * add onnx code * fix error * Add cmake file * fix patchelf * update paddle2onnx * Delete .gitmodules --------- Co-authored-by: PaddleCI <paddle_ci@example.com> Co-authored-by: pangyoki <pangyoki@126.com> Co-authored-by: jiangjiajun <jiangjiajun@baidu.lcom>
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
/*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <pybind11/pybind11.h>
|
|
#include <pybind11/stl.h>
|
|
#include "onnx/py_utils.h"
|
|
|
|
#include "onnxoptimizer/optimize.h"
|
|
|
|
namespace ONNX_NAMESPACE {
|
|
namespace py = pybind11;
|
|
using namespace pybind11::literals;
|
|
PYBIND11_MODULE(onnx_opt_cpp2py_export, onnx_opt_cpp2py_export) {
|
|
onnx_opt_cpp2py_export.doc() = "ONNX Optimizer";
|
|
|
|
onnx_opt_cpp2py_export.def(
|
|
"optimize",
|
|
[](const py::bytes& bytes, const std::vector<std::string>& names) {
|
|
ModelProto proto{};
|
|
ParseProtoFromPyBytes(&proto, bytes);
|
|
auto const result = optimization::Optimize(proto, names);
|
|
std::string out;
|
|
result.SerializeToString(&out);
|
|
return py::bytes(out);
|
|
});
|
|
|
|
onnx_opt_cpp2py_export.def(
|
|
"optimize_fixedpoint",
|
|
[](const py::bytes& bytes, const std::vector<std::string>& names) {
|
|
ModelProto proto{};
|
|
ParseProtoFromPyBytes(&proto, bytes);
|
|
auto const result =
|
|
optimization::OptimizeFixed(proto, names);
|
|
std::string out;
|
|
result.SerializeToString(&out);
|
|
return py::bytes(out);
|
|
});
|
|
onnx_opt_cpp2py_export.def("get_available_passes", &optimization::GetAvailablePasses);
|
|
onnx_opt_cpp2py_export.def("get_fuse_and_elimination_passes", &optimization::GetFuseAndEliminationPass);
|
|
}
|
|
}
|