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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.gat import GAT
  21. from src.config import GatConfig
  22. context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
  23. if __name__ == '__main__':
  24. parser = argparse.ArgumentParser(description='GAT_export')
  25. parser.add_argument('--ckpt_file', type=str, default='./ckpts/gat.ckpt', help='GAT ckpt file.')
  26. parser.add_argument('--output_file', type=str, default='gat.air', help='GAT output air name.')
  27. parser.add_argument('--dataset', type=str, default='cora', help='GAT dataset name.')
  28. args_opt = parser.parse_args()
  29. if args_opt.dataset == "citeseer":
  30. feature_size = [1, 3312, 3703]
  31. biases_size = [1, 3312, 3312]
  32. num_classes = 6
  33. else:
  34. feature_size = [1, 2708, 1433]
  35. biases_size = [1, 2708, 2708]
  36. num_classes = 7
  37. hid_units = GatConfig.hid_units
  38. n_heads = GatConfig.n_heads
  39. feature = np.random.uniform(0.0, 1.0, size=feature_size).astype(np.float32)
  40. biases = np.random.uniform(0.0, 1.0, size=biases_size).astype(np.float64)
  41. feature_size = feature.shape[2]
  42. num_nodes = feature.shape[1]
  43. gat_net = GAT(feature_size,
  44. num_classes,
  45. num_nodes,
  46. hid_units,
  47. n_heads,
  48. attn_drop=0.0,
  49. ftr_drop=0.0)
  50. gat_net.set_train(False)
  51. load_checkpoint(args_opt.ckpt_file, net=gat_net)
  52. gat_net.add_flags_recursive(fp16=True)
  53. export(gat_net, Tensor(feature), Tensor(biases), file_name=args_opt.output_file, file_format="AIR")