You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import torch.nn as nn
  2. import torch.nn.functional as F
  3. class Fully(nn.Module):
  4. def __init__(self, nfeat, nhid, nclass, dropout,multi_label=False):
  5. super(Fully, self).__init__()
  6. self.multi_label = multi_label
  7. layers = []
  8. if len(nhid) == 0:
  9. layers.append(nn.Linear(nfeat, nclass))
  10. else:
  11. layers.append(nn.Linear(nfeat, nhid[0]))
  12. for i in range(len(nhid) - 1):
  13. layers.append(nn.Linear(nhid[i], nhid[i + 1]))
  14. if nclass > 1:
  15. layers.append(nn.Linear(nhid[-1], nclass))
  16. self.fc = nn.ModuleList(layers)
  17. self.dropout = dropout
  18. self.nclass = nclass
  19. def forward(self, x, adj=None):
  20. end_layer = len(self.fc) - 1 if self.nclass > 1 else len(self.fc)
  21. for i in range(end_layer):
  22. x = F.dropout(x, self.dropout, training=self.training)
  23. x = self.fc[i](x)
  24. x = F.relu(x)
  25. classifier = self.fc[-1](x)
  26. if self.multi_label:
  27. classifier = classifier
  28. else:
  29. classifier = F.log_softmax(classifier, dim=1)
  30. return classifier