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.1 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. - Dataset size:
  28. Statistics of dataset used are summerized as below:
  29. | | Cora | Citeseer |
  30. | ------------------ | -------------: | -------------: |
  31. | Task | Transductive | Transductive |
  32. | # Nodes | 2708 (1 graph) | 3327 (1 graph) |
  33. | # Edges | 5429 | 4732 |
  34. | # Features/Node | 1433 | 3703 |
  35. | # Classes | 7 | 6 |
  36. | # Training Nodes | 140 | 120 |
  37. | # Validation Nodes | 500 | 500 |
  38. | # Test Nodes | 1000 | 1000 |
  39. - Data Preparation
  40. - Place the dataset to any path you want, the folder should include files as follows(we use Cora dataset as an example):
  41. ```
  42. .
  43. └─data
  44. ├─ind.cora.allx
  45. ├─ind.cora.ally
  46. ├─ind.cora.graph
  47. ├─ind.cora.test.index
  48. ├─ind.cora.tx
  49. ├─ind.cora.ty
  50. ├─ind.cora.x
  51. └─ind.cora.y
  52. ```
  53. - Generate dataset in mindrecord format for cora or citeseer.
  54. ```buildoutcfg
  55. cd ./scripts
  56. # SRC_PATH is the dataset file path you downloaded, DATASET_NAME is cora or citeseer
  57. sh run_process_data_ascend.sh [SRC_PATH] [DATASET_NAME]
  58. ```
  59. - Launch
  60. ```
  61. #Generate dataset in mindrecord format for cora
  62. ./run_process_data_ascend.sh ./data cora
  63. #Generate dataset in mindrecord format for citeseer
  64. ./run_process_data_ascend.sh ./data citeseer
  65. ```
  66. # [Features](#contents)
  67. ## Mixed Precision
  68. 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.
  69. # [Environment Requirements](#contents)
  70. - Hardward (Ascend)
  71. - Framework
  72. - [MindSpore](https://www.mindspore.cn/install/en)
  73. - For more information, please check the resources below:
  74. - [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
  75. - [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)
  76. # [Quick Start](#contents)
  77. After installing MindSpore via the official website and Dataset is correctly generated, you can start training and evaluation as follows.
  78. - running on Ascend
  79. ```
  80. # run training example with cora dataset, DATASET_NAME is cora
  81. sh run_train_ascend.sh [DATASET_NAME]
  82. ```
  83. # [Script Description](#contents)
  84. ## [Script and Sample Code](#contents)
  85. ```shell
  86. .
  87. └─gat
  88. ├─README.md
  89. ├─scripts
  90. | ├─run_process_data_ascend.sh # Generate dataset in mindrecord format
  91. | └─run_train_ascend.sh # Launch training
  92. |
  93. ├─src
  94. | ├─config.py # Training configurations
  95. | ├─dataset.py # Data preprocessing
  96. | ├─gat.py # GAT model
  97. | └─utils.py # Utils for training gat
  98. |
  99. └─train.py # Train net
  100. ```
  101. ## [Script Parameters](#contents)
  102. Parameters for both training and evaluation can be set in config.py.
  103. - config for GAT, CORA dataset
  104. ```python
  105. "learning_rate": 0.005, # Learning rate
  106. "num_epochs": 200, # Epoch sizes for training
  107. "hid_units": [8], # Hidden units for attention head at each layer
  108. "n_heads": [8, 1], # Num heads for each layer
  109. "early_stopping": 100, # Early stop patience
  110. "l2_coeff": 0.0005 # l2 coefficient
  111. "attn_dropout": 0.6 # Attention dropout ratio
  112. "feature_dropout":0.6 # Feature dropout ratio
  113. ```
  114. ## [Training Process](#contents)
  115. ### Training
  116. - running on Ascend
  117. ```python
  118. sh run_train_ascend.sh [DATASET_NAME]
  119. ```
  120. Training result will be stored in the scripts path, whose folder name begins with "train". You can find the result like the
  121. followings in log.
  122. ```python
  123. Epoch:0, train loss=1.98498 train acc=0.17143 | val loss=1.97946 val acc=0.27200
  124. Epoch:1, train loss=1.98345 train acc=0.15000 | val loss=1.97233 val acc=0.32600
  125. Epoch:2, train loss=1.96968 train acc=0.21429 | val loss=1.96747 val acc=0.37400
  126. Epoch:3, train loss=1.97061 train acc=0.20714 | val loss=1.96410 val acc=0.47600
  127. Epoch:4, train loss=1.96864 train acc=0.13571 | val loss=1.96066 val acc=0.59600
  128. ...
  129. Epoch:195, train loss=1.45111 train_acc=0.56429 | val_loss=1.44325 val_acc=0.81200
  130. Epoch:196, train loss=1.52476 train_acc=0.52143 | val_loss=1.43871 val_acc=0.81200
  131. Epoch:197, train loss=1.35807 train_acc=0.62857 | val_loss=1.43364 val_acc=0.81400
  132. Epoch:198, train loss=1.47566 train_acc=0.51429 | val_loss=1.42948 val_acc=0.81000
  133. Epoch:199, train loss=1.56411 train_acc=0.55000 | val_loss=1.42632 val_acc=0.80600
  134. Test loss=1.5366285, test acc=0.84199995
  135. ...
  136. ```
  137. # [Model Description](#contents)
  138. ## [Performance](#contents)
  139. | Parameter | GAT |
  140. | ------------------------------------ | ----------------------------------------- |
  141. | Resource | Ascend 910 |
  142. | uploaded Date | 06/16/2020(month/day/year) |
  143. | MindSpore Version | 0.5.0-beta |
  144. | Dataset | Cora/Citeseer |
  145. | Training Parameter | epoch=200 |
  146. | Optimizer | Adam |
  147. | Loss Function | Softmax Cross Entropy |
  148. | Accuracy | 83.0/72.5 |
  149. | Speed | 0.195s/epoch |
  150. | Total time | 39s |
  151. | Scripts | https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/gnn/gat |
  152. # [Description of random situation](#contents)
  153. 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%.
  154. # [ModelZoo Homepage](#contents)
  155. Please check the official [homepage](http://gitee.com/mindspore/mindspore/tree/master/model_zoo).