export_lite.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. #Licensed under the Apache License, Version 2.0 (the "License");
  4. #you may not use this file except in compliance with the License.
  5. #You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. #Unless required by applicable law or agreed to in writing, software
  10. #distributed under the License is distributed on an "AS IS" BASIS,
  11. #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. #See the License for the specific language governing permissions and
  13. #limitations under the License.
  14. import paddlelite.lite as lite
  15. import os
  16. import argparse
  17. def export_lite():
  18. opt = lite.Opt()
  19. model_file = os.path.join(FLAGS.model_dir, '__model__')
  20. params_file = os.path.join(FLAGS.model_dir, '__params__')
  21. opt.run_optimize("", model_file, params_file, 'naive_buffer', FLAGS.place,
  22. FLAGS.save_file)
  23. if __name__ == '__main__':
  24. parser = argparse.ArgumentParser(description=__doc__)
  25. parser.add_argument(
  26. "--model_dir",
  27. type=str,
  28. default="",
  29. help="path of '__model__' and '__params__'.",
  30. required=True)
  31. parser.add_argument(
  32. "--place",
  33. type=str,
  34. default="arm",
  35. help="run place: 'arm|opencl|x86|npu|xpu|rknpu|apu'.",
  36. required=True)
  37. parser.add_argument(
  38. "--save_file",
  39. type=str,
  40. default="paddlex.nb",
  41. help="file name for storing the output files.",
  42. required=True)
  43. FLAGS = parser.parse_args()
  44. export_lite()