get_model_io.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*************************************************************************
  2. * Copyright (C) [2019] by Cambricon, Inc. All rights reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. *************************************************************************/
  20. #include <gflags/gflags.h>
  21. #include <fstream>
  22. #include <iostream>
  23. #include <string>
  24. #include "easyinfer/model_loader.h"
  25. DEFINE_string(offline_model, "", "path of offline-model");
  26. DEFINE_string(function_name, "subnet0", "model defined function name");
  27. int main(int argc, char *argv[]) {
  28. ::gflags::ParseCommandLineFlags(&argc, &argv, true);
  29. if (FLAGS_offline_model.size() == 0) {
  30. std::cout << "usage: get_model_io -offline_model model_name" << std::endl;
  31. return 0;
  32. } else {
  33. std::fstream fs;
  34. fs.open(FLAGS_offline_model, std::ios::in);
  35. if (!fs) {
  36. std::cout << FLAGS_offline_model << " doesn't exist " << std::endl;
  37. fs.close();
  38. return 0;
  39. }
  40. fs.close();
  41. }
  42. edk::ModelLoader model(FLAGS_offline_model, FLAGS_function_name);
  43. std::cout << "----------------------input num: " << model.InputNum() << '\n';
  44. for (uint32_t i = 0; i < model.InputNum(); ++i) {
  45. std::cout << "model input shape " << i << ": " << model.InputShape(i) << std::endl;
  46. }
  47. std::cout << "---------------------output num: " << model.OutputNum() << '\n';
  48. for (uint32_t i = 0; i < model.OutputNum(); ++i) {
  49. std::cout << "model output shape " << i << ": " << model.OutputShape(i) << std::endl;
  50. }
  51. std::cout << "model's parallelism: " << model.ModelParallelism() << std::endl;
  52. std::cout << "[INFO] succeed in getting input & output format\n";
  53. return 0;
  54. }