小黑代码调试与维度分析:RGCNConv,GraphConv输入输出与公式对应

RGCNConv

小黑代码调试与维度分析:RGCNConv,GraphConv输入输出与公式对应_第1张图片

小黑代码调试与维度分析:RGCNConv,GraphConv输入输出与公式对应_第2张图片

from torch_geometric.nn import RGCNConv,GraphConv
import torch.nn as nn
import torch
num_features = 64
hidden_size = 16
conv1 = RGCNConv(in_channels = num_features,out_channels = hidden_size,num_relations = 3,num_bases = 10)
print('RGCNConv模型里的参数:')
for name,parameter in list(conv1.named_parameters()):
    print(name,':',parameter.shape)
num_nodes = 53
x = torch.randn(num_nodes,num_features)
num_edges = 111
edge_index = torch.randint(0,num_nodes,(2,num_edges))
edge_type = torch.randint(0,10,(num_edges,))
output1 = conv1(x,edge_index,edge_type)
print('output的shape:',output1.shape)

输出:

RGCNConv模型里的参数:
weight : torch.Size([10, 64, 16])
comp : torch.Size([3, 10])
root : torch.Size([64, 16])
bias : torch.Size([16])
output的shape: torch.Size([53, 16])

GraphConv

小黑代码调试与维度分析:RGCNConv,GraphConv输入输出与公式对应_第3张图片

from torch_geometric.nn import GraphConv
import torch.nn as nn
import torch
input_size = 16
output_size = 5
conv2 = GraphConv(input_size, output_size)
print('GraphConv模型里的参数:')
for name,parameter in list(conv2.named_parameters()):
    print(name,':',parameter.shape)

num_nodes = 53
num_edges = 111
input_ = torch.randn([num_nodes,input_size])
edge_index = torch.randint(0,num_nodes,(2,num_edges))
output2 = conv2(input_,edge_index)
print('output的shape:',output2.shape)

输出:

GraphConv模型里的参数:
lin_rel.weight : torch.Size([5, 16])
lin_rel.bias : torch.Size([5])
lin_root.weight : torch.Size([5, 16])
output的shape: torch.Size([53, 5])

你可能感兴趣的:(深度学习,batch,机器学习)