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.

README.md 8.4 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <!--TOC -->
  2. - [Graph Attention Networks Description](#graph-attention-networks-description)
  3. - [Model architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Features](#features)
  6. - [Mixed Precision](#mixed-precision)
  7. - [Environment Requirements](#environment-requirements)
  8. - [Quick Start](#quick-start)
  9. - [Script Description](#script-description)
  10. - [Script and Sample Code](#script-and-sample-code)
  11. - [Script Parameters](#script-parameters)
  12. - [Training Process](#training-process)
  13. - [Training](#training)
  14. - [Model Description](#model-description)
  15. - [Performance](#performance)
  16. - [Evaluation Performance](#evaluation-performance)
  17. - [Inference Performance](#evaluation-performance)
  18. - [Description of random situation](#description-of-random-situation)
  19. - [ModelZoo Homepage](#modelzoo-homepage)
  20. <!--TOC -->
  21. # [Graph Attention Networks Description](#contents)
  22. Graph Attention Networks(GAT) was proposed in 2017 by Petar Veličković et al. By leveraging masked self-attentional layers to address shortcomings of prior graph based method, GAT achieved or matched state of the art performance on both transductive datasets like Cora and inductive dataset like PPI. This is an example of training GAT with Cora dataset in MindSpore.
  23. [Paper](https://arxiv.org/abs/1710.10903): Veličković, P., Cucurull, G., Casanova, A., Romero, A., Lio, P., & Bengio, Y. (2017). Graph attention networks. arXiv preprint arXiv:1710.10903.
  24. # [Model architecture](#contents)
  25. Note that according to whether this attention layer is the output layer of the network or not, the node update function can be concatenate or average.
  26. # [Dataset](#contents)
  27. Note that you can run the scripts based on the dataset mentioned in original paper or widely used in relevant domain/network architecture. In the following sections, we will introduce how to run the scripts using the related dataset below.
  28. - Dataset size:
  29. Statistics of dataset used are summerized as below:
  30. | | Cora | Citeseer |
  31. | ------------------ | -------------: | -------------: |
  32. | Task | Transductive | Transductive |
  33. | # Nodes | 2708 (1 graph) | 3327 (1 graph) |
  34. | # Edges | 5429 | 4732 |
  35. | # Features/Node | 1433 | 3703 |
  36. | # Classes | 7 | 6 |
  37. | # Training Nodes | 140 | 120 |
  38. | # Validation Nodes | 500 | 500 |
  39. | # Test Nodes | 1000 | 1000 |
  40. - Data Preparation
  41. - Place the dataset to any path you want, the folder should include files as follows(we use Cora dataset as an example):
  42. ```
  43. .
  44. └─data
  45. ├─ind.cora.allx
  46. ├─ind.cora.ally
  47. ├─ind.cora.graph
  48. ├─ind.cora.test.index
  49. ├─ind.cora.tx
  50. ├─ind.cora.ty
  51. ├─ind.cora.x
  52. └─ind.cora.y
  53. ```
  54. - Generate dataset in mindrecord format for cora or citeseer.
  55. ```buildoutcfg
  56. cd ./scripts
  57. # SRC_PATH is the dataset file path you downloaded, DATASET_NAME is cora or citeseer
  58. sh run_process_data_ascend.sh [SRC_PATH] [DATASET_NAME]
  59. ```
  60. - Launch
  61. ```
  62. #Generate dataset in mindrecord format for cora
  63. ./run_process_data_ascend.sh ./data cora
  64. #Generate dataset in mindrecord format for citeseer
  65. ./run_process_data_ascend.sh ./data citeseer
  66. ```
  67. # [Features](#contents)
  68. ## Mixed Precision
  69. To ultilize the strong computation power of Ascend chip, and accelerate the training process, the mixed training method is used. MindSpore is able to cope with FP32 inputs and FP16 operators. In GAT example, the model is set to FP16 mode except for the loss calculation part.
  70. # [Environment Requirements](#contents)
  71. - Hardward (Ascend)
  72. - Framework
  73. - [MindSpore](https://www.mindspore.cn/install/en)
  74. - For more information, please check the resources below:
  75. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  76. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  77. # [Quick Start](#contents)
  78. After installing MindSpore via the official website and Dataset is correctly generated, you can start training and evaluation as follows.
  79. - running on Ascend
  80. ```
  81. # run training example with cora dataset, DATASET_NAME is cora
  82. sh run_train_ascend.sh [DATASET_NAME]
  83. ```
  84. # [Script Description](#contents)
  85. ## [Script and Sample Code](#contents)
  86. ```shell
  87. .
  88. └─gat
  89. ├─README.md
  90. ├─scripts
  91. | ├─run_process_data_ascend.sh # Generate dataset in mindrecord format
  92. | └─run_train_ascend.sh # Launch training
  93. |
  94. ├─src
  95. | ├─config.py # Training configurations
  96. | ├─dataset.py # Data preprocessing
  97. | ├─gat.py # GAT model
  98. | └─utils.py # Utils for training gat
  99. |
  100. └─train.py # Train net
  101. ```
  102. ## [Script Parameters](#contents)
  103. Parameters for both training and evaluation can be set in config.py.
  104. - config for GAT, CORA dataset
  105. ```python
  106. "learning_rate": 0.005, # Learning rate
  107. "num_epochs": 200, # Epoch sizes for training
  108. "hid_units": [8], # Hidden units for attention head at each layer
  109. "n_heads": [8, 1], # Num heads for each layer
  110. "early_stopping": 100, # Early stop patience
  111. "l2_coeff": 0.0005 # l2 coefficient
  112. "attn_dropout": 0.6 # Attention dropout ratio
  113. "feature_dropout":0.6 # Feature dropout ratio
  114. ```
  115. ## [Training Process](#contents)
  116. ### Training
  117. - running on Ascend
  118. ```python
  119. sh run_train_ascend.sh [DATASET_NAME]
  120. ```
  121. Training result will be stored in the scripts path, whose folder name begins with "train". You can find the result like the
  122. followings in log.
  123. ```python
  124. Epoch:0, train loss=1.98498 train acc=0.17143 | val loss=1.97946 val acc=0.27200
  125. Epoch:1, train loss=1.98345 train acc=0.15000 | val loss=1.97233 val acc=0.32600
  126. Epoch:2, train loss=1.96968 train acc=0.21429 | val loss=1.96747 val acc=0.37400
  127. Epoch:3, train loss=1.97061 train acc=0.20714 | val loss=1.96410 val acc=0.47600
  128. Epoch:4, train loss=1.96864 train acc=0.13571 | val loss=1.96066 val acc=0.59600
  129. ...
  130. Epoch:195, train loss=1.45111 train_acc=0.56429 | val_loss=1.44325 val_acc=0.81200
  131. Epoch:196, train loss=1.52476 train_acc=0.52143 | val_loss=1.43871 val_acc=0.81200
  132. Epoch:197, train loss=1.35807 train_acc=0.62857 | val_loss=1.43364 val_acc=0.81400
  133. Epoch:198, train loss=1.47566 train_acc=0.51429 | val_loss=1.42948 val_acc=0.81000
  134. Epoch:199, train loss=1.56411 train_acc=0.55000 | val_loss=1.42632 val_acc=0.80600
  135. Test loss=1.5366285, test acc=0.84199995
  136. ...
  137. ```
  138. # [Model Description](#contents)
  139. ## [Performance](#contents)
  140. | Parameter | GAT |
  141. | ------------------------------------ | ----------------------------------------- |
  142. | Resource | Ascend 910 |
  143. | uploaded Date | 06/16/2020(month/day/year) |
  144. | MindSpore Version | 1.0.0 |
  145. | Dataset | Cora/Citeseer |
  146. | Training Parameter | epoch=200 |
  147. | Optimizer | Adam |
  148. | Loss Function | Softmax Cross Entropy |
  149. | Accuracy | 83.0/72.5 |
  150. | Speed | 0.195s/epoch |
  151. | Total time | 39s |
  152. | Scripts | https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/gnn/gat |
  153. # [Description of random situation](#contents)
  154. GAT model contains lots of dropout operations, if you want to disable dropout, set the attn_dropout and feature_dropout to 0 in src/config.py. Note that this operation will cause the accuracy drop to approximately 80%.
  155. # [ModelZoo Homepage](#contents)
  156. Please check the official [homepage](http://gitee.com/mindspore/mindspore/tree/master/model_zoo).