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.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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
  19. from mindspore.train.serialization import load_checkpoint, export
  20. from src.gcn import GCN
  21. from src.config import ConfigGCN
  22. context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
  23. if __name__ == '__main__':
  24. parser = argparse.ArgumentParser(description='GCN_export')
  25. parser.add_argument('--ckpt_file', type=str, default='', help='GCN ckpt file.')
  26. parser.add_argument('--output_file', type=str, default='gcn.air', help='GCN output air name.')
  27. parser.add_argument('--dataset', type=str, default='cora', help='GCN dataset name.')
  28. args_opt = parser.parse_args()
  29. config = ConfigGCN()
  30. if args_opt.dataset == "cora":
  31. input_dim = 1433
  32. class_num = 7
  33. adj = Tensor(np.zeros((2708, 2708), np.float64))
  34. feature = Tensor(np.zeros((2708, 1433), np.float32))
  35. else:
  36. input_dim = 3703
  37. class_num = 6
  38. adj = Tensor(np.zeros((3312, 3312), np.float64))
  39. feature = Tensor(np.zeros((3312, 3703), np.float32))
  40. gcn_net = GCN(config, input_dim, class_num)
  41. gcn_net.set_train(False)
  42. load_checkpoint(args_opt.ckpt_file, net=gcn_net)
  43. gcn_net.add_flags_recursive(fp16=True)
  44. export(gcn_net, adj, feature, file_name=args_opt.output_file, file_format="AIR")