Save-Load-Infer with DGL

Dear all,

Let say I have trained the model and save and load it with this commands
torch.save(model.state_dict(), PATH) and load it again torch.save(model.state_dict(), PATH). If I have a new graph and want to its nodes by using the loaded trained model, how should I proceed it?

I tried to find a similar demo or example, but couldn’t find it at this point.

Thanks

1 Like

If you are confident that the model should generalize to the new graph, then just create a separate dataset class for this new graph and apply the model as for the training dataset.

If your model is transductive – the model architecture is tied to the graph it is trained on, then it cannot generalize to graph with unseen nodes. Otherwise, we say the model is inductive and can be tested on a different graph than what it is trained on. One such example is train_ppi.py, where it trains a GAT on some graphs but tests it on others.

Thanks both,

Once I load the model with
trained_model = th.load("./model/gcn-2trg.pt")
And perform inference with
inference = trained_model(G_Infer_dgl, G_Infer_dgl.ndata["feature"].cuda())

Is there a way to know the precision or recall of my inference? or the precision or recall of my model?

thanks


Here is an example of how to run save/model for infer with DGL, though the code is not merged into DGL repo.

Specifically, you can look at https://github.com/classicsong/dgl-neptune-examples/blob/72e899803ac114bd99d34d17b65c4d2202e84f1e/examples/mutag/entity_classification.py#L323 and https://github.com/classicsong/dgl-neptune-examples/blob/72e899803ac114bd99d34d17b65c4d2202e84f1e/examples/mutag/eval_classification.py#L44 for model save and restore.

Thanks @classicsong,

But I’m looking for a command now to calculate precision and recall when we do node classification. An example of how im looking for is in How to get a better model