Comments (1)
Hi I'm using GCN to classify the node on datasets "KarateClub", then I using GNNExplainer to explain node 12. However, when I explain the node twice, GNNExplainer gives me two different subgraph, and them have different node_feat_mask&edge_mask. Iām so confused about the different explanations generated from the same trained model.
run code on jupyter notebook cell one: ` import torch from torch_geometric.datasets import KarateClub import torch.nn.functional as F from torch_geometric.nn import GCNConv, GNNExplainer from torch_geometric.datasets import KarateClub import networkx as nx import matplotlib.pyplot as plt
dataset = KarateClub()#torch_geometric.datasets
class Net(torch.nn.Module): def init(self): super().init() self.conv1 = GCNConv(dataset.num_node_features, 16) self.conv2 = GCNConv(16, dataset.num_classes) pass
def forward(self, x, edge_index): #x, edge_index = data.x, data.edge_index
x = self.conv1(x, edge_index) x = F.relu(x) x = F.dropout(x, training=self.training) x = self.conv2(x, edge_index) return F.log_softmax(x, dim=1)
pass pass
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model = Net().to(device) data = dataset[0].to(device) optimizer = torch.optim.Adam(model.parameters(), lr=0.01) x, edge_index = data.x, data.edge_index
for epoch in range(61): model.train() optimizer.zero_grad() out = model(x, edge_index) loss = F.nll_loss(out, data.y) loss.backward() optimizer.step()
#print('Epoch {} | Loss: {:.4f}'.format(epoch,loss.item())) model.eval() _, pred=out.max(dim=1) #print(pred) correct = int(pred.eq(data.y).sum().item()) acc = correct / int(data.x.sum()) #print('Accuracy:{:.4f}'.format(acc)) print('Epoch {} | Loss: {:.4f}'.format(epoch,loss.item())+' | Accuracy:{:.4f}'.format(acc))
pass pass `
cell two: explainer = GNNExplainer(model, epochs=60) node_idx = 12 node_feat_mask, edge_mask = explainer.explain_node(node_idx, x, edge_index) ax, G = explainer.visualize_subgraph(node_idx, edge_index, edge_mask, y=data.y) plt.show()
cell three: explainer = GNNExplainer(model, epochs=61) node_idx = 12 node_feat_mask, edge_mask = explainer.explain_node(node_idx, x, edge_index) ax, G = explainer.visualize_subgraph(node_idx, edge_index, edge_mask, y=data.y,threshold=0.6) plt.show()
Hello BILLYLIAOWEI,
Could you able to run the code and get the result? I want to use PyG and GNNExplainer as well.
from gnn-model-explainer.
Related Issues (20)
- Broken link to Observable in README.md
- The requirements.txt should be changed to make Installation work. HOT 1
- Where is the dataset and what kind of dataset am I supposed to use inorder to train? HOT 1
- While training on Tox21 data: "NameError: name 'io_utils' is not defined" HOT 1
- node_idx_new = sum(neighbors_adj_row[:node_idx])--is it possible the way that node_idx_new is generated may lead to duplicate index?
- Question on Explainer Visualization
- Question about link prediction HOT 3
- Question about run bmname=MUTA
- Generating Explanations for REDDIT-BINARY and Mutag dataset HOT 7
- Explain Graph Nets models
- Pytorch Geometric training for synthetic data HOT 1
- Frozen Synthetic Dataset
- Accuracy HOT 1
- Reproduction of multi-instance explanations and prototypes
- Doubt: GNNExplainer on Deep GCNN on Graph Classification Tasks HOT 2
- Use this model explain the graph-level GNN model? HOT 1
- Apply to hetero GNN?
- Observable notebook does not exist
- Question about the loss
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gnn-model-explainer.