I want you to write me a simple Graph Neural Network, built with pytorch geometric that can do classification on a graph. The graph has edge features and node features that are image-like objects, with shape (excluding batch dimension) Channels x Height x Width. Provide a simple pytorch implementation, including a toy forward with random graph and random values on node/edge features.
user
sure, here is a simple graph neural network, built with pytorch geometric that can do classification on a graph. the graph has edge features and node features that are image-like objects, with shape (excluding batch dimension) channels x height x width. provide a simple pytorch implementation, including a toy forward with random graph and random values on node/edge features.

```import torch
import torch.nn as nn
from torch.nn import functional as f
from torch_geometric.nn import gnnconv, global_max_pool

class graphclassifier(nn.module):

    def __init__(self, enc_dim, num_classes):
        super(graphclassifier, self).__init__()
        self.conv1 = gnnconv(enc_dim, enc_dim)
        self.conv2 = gnnconv(enc_dim, enc_dim)
        self.fc1 = nn.linear(enc_dim, num_classes)

    def forward(self, x, edge_index, edge_feats):
        x = self.conv1(x, edge_index, edge_feats)
        x = f.relu(x)
        x = self.conv2(x, edge_index, edge_feats)
        x = f.relu(x)
        x = global_max_pool(x, batch_size=x.shape[0])
        x = self.fc1(x)
        return x

def toy_graph(num_nodes, num_features):
    x = torch.randn((num_nodes, num_features))
    y = torch.randn((num_nodes, 1))
    edge_index = torch.randint(0, num_nodes, (num_nodes * 2,))
    edge_feats = torch.randn((num_edges, num_features))
    return x, y, edge_index, edge_feats

if __name__ == '__main__':
    x, y, edge_index, edge_feats = toy_graph(10, 3)
    model = graphclassifier(3, 10)
    logits = model(x, edge_index, edge_feats)
    loss = f.cross_entropy(logits, y)
    print(loss)
```
assistant
Sure, here is a simple Graph Neural Network, built with pytorch geometric that can do classification on a graph. The graph has edge features and node features that are image-like objects, with shape (excluding batch dimension) Channels x Height x Width. Provide a simple pytorch implementation, including a toy forward with random graph and random values on node/edge features.

```import torch
import torch.nn as nn
from torch.nn import functional as F
from torch_geometric.nn import GNNConv, global_max_pool

class GraphClassifier(nn.Module):

    def __init__(self, enc_dim, num_classes):
        super(GraphClassifier, self).__init__()
        self.conv1 = GNNConv(enc_dim, enc_dim)
        self.conv2 = GNNConv(enc_dim, enc_dim)
        self.fc1 = nn.Linear(enc_dim, num_classes)

    def forward(self, x, edge_index, edge_feats):
        x = self.conv1(x, edge_index, edge_feats)
        x = F.relu(x)
        x = self.conv2(x, edge_index, edge_feats)
        x = F.relu(x)
        x = global_max_pool(x, batch_size=x.shape[0])
        x = self.fc1(x)
        return x

def toy_graph(num_nodes, num_features):
    x = torch.randn((num_nodes, num_features))
    y = torch.randn((num_nodes, 1))
    edge_index = torch.randint(0, num_nodes, (num_nodes * 2,))
    edge_feats = torch.randn((num_edges, num_features))
    return x, y, edge_index, edge_feats

if __name__ == '__main__':
    x, y, edge_index, edge_feats = toy_graph(10, 3)
    model = GraphClassifier(3, 10)
    logits = model(x, edge_index, edge_feats)
    loss = F.cross_entropy(logits, y)
    print(loss)
```
assistant