当前位置:网站首页>import torch_ Geometric first graph network example
import torch_ Geometric first graph network example
2022-06-12 13:06:00 【Dongxuan】
Learning Methods on Graphs
Cora citation Get one on the dataset GCN layer
For a high-level explanation on GCN, have a look at its blog post.
① Load data set
from torch_geometric.datasets import Planetoid
dataset = Planetoid(root='/tmp/Cora', name='Cora')
>>> Cora()Build a two-tier GCN The Internet
import torch
import torch.nn.functional as F
from torch_geometric.nn import GCNConv
class GCN(torch.nn.Module):
def __init__(self):
super().__init__()
self.conv1 = GCNConv(dataset.num_node_features, 16)
self.conv2 = GCNConv(16, dataset.num_classes)
def forward(self, data):
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)It is so simple , It's all in one batch Convolution of graphs on large graphs !!!!!!!!!\
Start this network ,train 200 round
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = GCN().to(device)
data = dataset[0].to(device)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4)
model.train()
for epoch in range(200):
optimizer.zero_grad()
out = model(data)
loss = F.nll_loss(out[data.train_mask], data.y[data.train_mask])
loss.backward()
optimizer.step()After training , Test in the test set :
model.eval()
pred = model(data).argmax(dim=1)
correct = (pred[data.test_mask] == data.y[data.test_mask]).sum()
acc = int(correct) / int(data.test_mask.sum())
print(f'Accuracy: {acc:.4f}')
>>> Accuracy: 0.8150The easiest way to learn more about Graph Neural Networks is to study the examples in the examples/ directory and to browse torch_geometric.nn. Happy hacking!
边栏推荐
- 软件构造 03 正则表达式
- Theoretical knowledge of improved DH parameters and standard DH parameters of manipulator
- Hardware composition of embedded system - introduction of embedded development board based on ARM
- STM32F1与STM32CubeIDE编程实例-设备驱动-DHT11温度温度传感器驱动
- 微信web开发者工具使用教程,web开发问题
- R language Visual facet chart, hypothesis test, multivariable grouping t-test, visual multivariable grouping faceting bar plot, adding significance level and jitter points
- Five ways to quickly download large files from Google cloud disk
- 在 Debian 10 上独立安装MySQL数据库
- It is enough to read this article. Web Chinese development
- 创新实训(十一)开发过程中的一些bug汇总
猜你喜欢

"New continent" of mobile application going to sea

从基础到源码统统帮你搞定,技术详细介绍

Improve pipeline efficiency: you need to know how to identify the main obstacles in ci/cd pipeline

About paiwen

Eight misunderstandings are broken one by one (2): poor performance? Fewer applications? You worry a lot about the cloud!

ITK multiresolution image itk:: recursivemultiresolutionpyramidimagefilter

嵌入式系统概述1-嵌入式系统定义、特点和发展历程

Vant tab bar + pull-up loading + pull-down refresh demo van tabs + van pull refresh + van list demo

Array -- seven array topics with double pointer technique

Pytoch official fast r-cnn source code analysis (I) -- feature extraction
随机推荐
手把手教你IDEA创建SSM项目结构
智能垃圾桶语音芯片应用设计方案介绍,WT588F02B-8S
LeetCode滑动窗口刷题总结
Index changes of seed points in ITK original image after ROI and downsampling
Safety KNN
R语言可视化分面图、假设检验、多变量分组t检验、可视化多变量分组分面条形图(faceting bar plot)并添加显著性水平、添加抖动数据点(jitter points)
Theoretical knowledge of improved DH parameters and standard DH parameters of manipulator
Binary tree (program)
import torch_geometric 第一个图网络例子
leetcode 47. Permutations II full permutations II (medium)
成功跳槽阿里,进阶学习
R language Visual facet chart, hypothesis test, multivariable grouping t-test, visual multivariable grouping faceting bar plot, adding significance level and jitter points
Improve pipeline efficiency: you need to know how to identify the main obstacles in ci/cd pipeline
Embedded system hardware composition - embedded system hardware architecture
路由信息的来源
unittest框架
Stm32f1 and stm32cubeide programming examples - device driver -eeprom-at24c256 driver
用PyTorch进行语义分割
分享PDF高清版,系列篇
Redis消息队列重复消费问题