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.

t_model.rst 3.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. .. _model:
  2. AutoGL Model
  3. ============
  4. AutoGL project uses ``model`` to define the common graph nerual networks and ``automodel`` to denote the relative class that includes some auto functions. Currently, we support the following models and automodels:
  5. * ``GCN`` and ``AutoGCN`` : graph convolutional network from https://arxiv.org/abs/1609.02907
  6. * ``GAT`` and ``AutoGAT`` : graph attentional network from https://arxiv.org/abs/1710.10903
  7. * ``GraphSAGE`` and ``AutoGraphSAGE`` : from the "Inductive Representation Learning on Large Graphs" https://arxiv.org/abs/1706.02216
  8. And we also support the following models and automodels for graph classification tasks:
  9. * ``GIN`` and ``AutoGIN`` : graph isomorphism network from https://arxiv.org/abs/1810.00826
  10. * ``Topkpool`` and ``AutoTopkpool`` : graph U-Net from https://arxiv.org/abs/1905.05178, https://arxiv.org/abs/1905.02850
  11. Define your own model and automodel
  12. -----------------------------------
  13. If you want to add your own model and automodel for some task, the only thing you should do is add a new model where the forward function should be fulfilled and a new automodel inherited from the basemodel.
  14. Firstly, you should define your model if it does not belong to the models above.
  15. Secondly, you should define your corresponding automodel.
  16. .. code-block:: python
  17. # 1. define your search space to self.space of your automodel instance
  18. [
  19. {'parameterName': 'num_layers', 'type': 'DISCRETE', 'feasiblePoints': '2,3,4'},
  20. {"parameterName": 'hidden', "type": "NUMERICAL_LIST", "numericalType": "INTEGER", "length": 3, "minValue": [8, 8, 8], "maxValue": [64, 64, 64], "scalingType": "LOG"},
  21. {'parameterName': 'dropout', 'type': 'DOUBLE', 'maxValue': 0.9, 'minValue': 0.1, 'scalingType': 'LINEAR'},
  22. {'parameterName': 'act', 'type': 'CATEGORICAL_LIST', "feasiblePoints": ['leaky_relu', 'relu', 'elu', 'tanh']},
  23. ]
  24. # 2. define the default point to self.hyperparams of your automodel instance
  25. {
  26. 'num_layers': 2,
  27. 'hidden': [16],
  28. 'dropout': 0.2,
  29. 'act': 'leaky_relu'
  30. }
  31. Where ``self.space`` is a list of dictionary indicating the name, type, feasible point, min/max value and some properties of the parameter. ``self.hyperparams`` is a dictionary indicating the hyper-parameters used in this model.
  32. Finally, you can use the defined model and automodel for the specific need.
  33. .. code-block :: python
  34. # for example
  35. import torch
  36. from .base import BaseModel
  37. class YourGNN(torch.nn.Module):
  38. def forward(self, data):
  39. pass # Your forward function
  40. class YourAutoGNN(BaseModel):
  41. def __init__(self, num_features=None, num_classes=None, device=None, init=True, **args):
  42. """
  43. num_features: the number of features
  44. num_classes: the number of classes
  45. device: your device to run code
  46. init: if True, the model will be initialize
  47. """
  48. self.space = XXX # Define your search space
  49. self.hyperparams = XXX # Define your hyper-parameters
  50. self.initialized = False
  51. if init is True:
  52. self.initialize()