PyTorch Geometric
3 minute read
PyTorch Geometric or PyG is one of the most popular libraries for geometric deep learning and W&B works extremely well with it for visualizing graphs and tracking experiments.
After you have installed Pytorch Geometric, follow these steps to get started.
Sign up and create an API key
An API key authenticates your machine to W&B. You can generate an API key from your user profile.
- Click your user profile icon in the upper right corner.
- Select User Settings, then scroll to the API Keys section.
- Click Reveal. Copy the displayed API key. To hide the API key, reload the page.
Install the wandb
library and log in
To install the wandb
library locally and log in:
Visualize the graphs
You can save details about the input graphs including number of edges, number of nodes and more. W&B supports logging plotly charts and HTML panels so any visualizations you create for your graph can then also be logged to W&B.
Use PyVis
The following snippet shows how you could do that with PyVis and HTML.

Use Plotly
To use plotly to create a graph visualization, first you need to convert the PyG graph to a networkx object. Following this you will need to create Plotly scatter plots for both nodes and edges. The snippet below can be used for this task.

Log metrics
You can use W&B to track your experiments and related metrics, such as loss functions, accuracy, and more. Add the following line to your training loop:

More resources
- Recommending Amazon Products using Graph Neural Networks in PyTorch Geometric
- Point Cloud Classification using PyTorch Geometric
- Point Cloud Segmentation using PyTorch Geometric
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.