-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88fc58e
commit 713ee69
Showing
4 changed files
with
141 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,66 @@ | ||
import torch | ||
import os | ||
from torch_geometric.transforms import NormalizeFeatures | ||
import load_dataset | ||
import engine | ||
import model | ||
import torch_geometric.transforms as T | ||
|
||
datasets = {} | ||
device = 'cuda' if torch.cuda.is_available() else 'cpu' | ||
|
||
datasets['cora'] = load_dataset.load_ds('Cora', NormalizeFeatures()) | ||
datasets['citeseer'] = load_dataset.load_ds('CiteSeer', NormalizeFeatures()) | ||
datasets['pubmed'] = load_dataset.load_ds('PubMed', NormalizeFeatures()) | ||
classification = False | ||
|
||
for ds in datasets.values(): | ||
load_dataset.print_ds_info(ds) | ||
print('\n#################################\n') | ||
if classification: | ||
|
||
dataset = datasets['cora'] | ||
transform_classification = T.Compose([ | ||
T.NormalizeFeatures(), | ||
T.ToDevice(device) | ||
]) | ||
|
||
model = model.GAT(dataset.num_features, dataset.num_classes) | ||
datasets = {} | ||
|
||
criterion = torch.nn.CrossEntropyLoss() # Define loss criterion => CrossEntropyLoss in the case of classification | ||
optimizer = torch.optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4) | ||
datasets['cora'] = load_dataset.load_ds('Cora', transform_classification) | ||
datasets['citeseer'] = load_dataset.load_ds('CiteSeer', transform_classification) | ||
datasets['pubmed'] = load_dataset.load_ds('PubMed', transform_classification) | ||
|
||
results = engine.train(model, dataset.data, dataset.data, criterion, optimizer, 10, False) | ||
for ds in datasets.values(): | ||
load_dataset.print_ds_info(ds) | ||
print('\n#################################\n') | ||
|
||
for k, r in results.items(): | ||
print(k, r) | ||
dataset = datasets['cora'] | ||
|
||
model = model.GAT(dataset.num_features, dataset.num_classes) | ||
|
||
criterion = torch.nn.CrossEntropyLoss() # Define loss criterion => CrossEntropyLoss in the case of classification | ||
optimizer = torch.optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4) | ||
|
||
results = engine.train(model, dataset.data, dataset.data, criterion, optimizer, 10, False) | ||
|
||
for k, r in results.items(): | ||
print(k, r) | ||
|
||
else: | ||
transform_prediction = T.Compose([ | ||
T.NormalizeFeatures(), | ||
T.ToDevice(device), | ||
T.RandomLinkSplit(num_val=0.05, num_test=0.1, is_undirected=True, | ||
add_negative_train_samples=False) | ||
]) | ||
|
||
datasets = {} | ||
|
||
datasets['cora'] = load_dataset.load_ds('Cora', transform_prediction) | ||
datasets['citeseer'] = load_dataset.load_ds('CiteSeer', transform_prediction) | ||
datasets['pubmed'] = load_dataset.load_ds('PubMed', transform_prediction) | ||
|
||
dataset = datasets['cora'] | ||
train_ds, val_ds, test_ds = dataset[0] | ||
|
||
model = model.GCN_Predictor(dataset.num_features, dataset.num_classes) | ||
|
||
criterion = torch.nn.BCEWithLogitsLoss() # Define loss criterion => Binary Cross Entropy for link prediction | ||
optimizer = torch.optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4) | ||
|
||
engine.train_link_prediction(model, train_ds, criterion, optimizer, 101) | ||
|
||
acc = engine.test(model, val_ds) | ||
print(acc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters