cpp_preproc_test.cpp 921 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <pybind11/pybind11.h>
  2. #include <pybind11/stl.h>
  3. #include <memory>
  4. #include <functional>
  5. #include <string>
  6. #include <unordered_map>
  7. #include <vector>
  8. #include "pypreproc.h"
  9. namespace py = pybind11;
  10. bool TestPyPreproc(const std::unordered_map<std::string, std::string> &params) {
  11. auto model = std::make_shared<edk::ModelLoader>("data/test_model.cambricon", "subnet0");
  12. std::vector<float*> inputs;
  13. for (uint32_t i = 0; i < model->InputNum(); ++i) {
  14. inputs.push_back(new float[model->InputShape(i).DataCount()]);
  15. }
  16. auto free_inputs = [&inputs] () {
  17. for (auto ptr : inputs) delete[] ptr;
  18. };
  19. cnstream::PyPreproc pypreproc;
  20. if (!pypreproc.Init(params)) {
  21. free_inputs();
  22. return false;
  23. }
  24. bool ret = 0 == pypreproc.Execute(inputs, model, nullptr);
  25. free_inputs();
  26. return ret;
  27. }
  28. void PreprocTestWrapper(py::module &m) { // NOLINT
  29. m.def("cpptest_pypreproc", &TestPyPreproc);
  30. }