GraphGallery 0.3.0
read the dataset
from graphgallery.data import Planetoid, NPZDataset;
data = Planetoid('cora', root="~/GraphData/datasets/", verbose=False);
graph = data.graph
idx_train, idx_val, idx_test = data.split()
>>> graph
Graph(adj_matrix(2708, 2708), attr_matrix(2708, 2708), labels(2708,))
Add TensorFlow and PyTorch support
Using TensorFlow
graphgallery.set_backend("tensorflow")
from graphgallery.nn.models import GCN
model = GCN(graph, attr_transformer="normalize_attr", device="GPU", seed=123);
model.build()
his = model.train(idx_train, idx_val, verbose=1, epochs=100)
loss, accuracy = model.test(idx_test)
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
Using PyTorch
graphgallery.set_backend("pytorch")
# the following codes are the same!
from graphgallery.nn.models import GCN
model = GCN(graph, attr_transformer="normalize_attr", device="GPU", seed=123);
model.build()
his = model.train(idx_train, idx_val, verbose=1, epochs=100)
loss, accuracy = model.test(idx_test)
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')