You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

export.py 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  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. # ============================================================================
  15. """export checkpoint file into air models"""
  16. import argparse
  17. import numpy as np
  18. from mindspore import Tensor, context, load_checkpoint, export
  19. from src.gcn import GCN
  20. from src.config import ConfigGCN
  21. parser = argparse.ArgumentParser(description="GCN export")
  22. parser.add_argument("--device_id", type=int, default=0, help="Device id")
  23. parser.add_argument("--ckpt_file", type=str, required=True, help="Checkpoint file path.")
  24. parser.add_argument("--dataset", type=str, default="cora", choices=["cora", "citeseer"], help="Dataset.")
  25. parser.add_argument("--file_name", type=str, default="gcn", help="output file name.")
  26. parser.add_argument("--file_format", type=str, choices=["AIR", "ONNX", "MINDIR"], default="AIR", help="file format")
  27. parser.add_argument("--device_target", type=str, default="Ascend",
  28. choices=["Ascend", "GPU", "CPU"], help="device target (default: Ascend)")
  29. args = parser.parse_args()
  30. context.set_context(mode=context.GRAPH_MODE, device_target=args.device_target)
  31. if args.device_target == "Ascend":
  32. context.set_context(device_id=args.device_id)
  33. if __name__ == "__main__":
  34. config = ConfigGCN()
  35. if args.dataset == "cora":
  36. input_dim = 1433
  37. class_num = 7
  38. adj = Tensor(np.zeros((2708, 2708), np.float64))
  39. feature = Tensor(np.zeros((2708, 1433), np.float32))
  40. else:
  41. input_dim = 3703
  42. class_num = 6
  43. adj = Tensor(np.zeros((3312, 3312), np.float64))
  44. feature = Tensor(np.zeros((3312, 3703), np.float32))
  45. gcn_net = GCN(config, input_dim, class_num)
  46. gcn_net.set_train(False)
  47. load_checkpoint(args.ckpt_file, net=gcn_net)
  48. gcn_net.add_flags_recursive(fp16=True)
  49. export(gcn_net, adj, feature, file_name=args.file_name, file_format=args.file_format)