当前位置: 首页 > news >正文

电影网站怎么做不犯法南宁seo收费

电影网站怎么做不犯法,南宁seo收费,wordpress上传限制8mb,建设网站的网站空间实验复现来源 https://zhuanlan.zhihu.com/p/603486955 该文章主要解决问题: 1.加深对图神经网络数据集的理解 2.加深对图神经网络模型中喂数据中维度变化的理解 原理问题在另一篇文章分析: 介绍数据集:cora数据集 其中的主要内容表示为…

实验复现来源

https://zhuanlan.zhihu.com/p/603486955

该文章主要解决问题:

1.加深对图神经网络数据集的理解

2.加深对图神经网络模型中喂数据中维度变化的理解

原理问题在另一篇文章分析:
介绍数据集:cora数据集

其中的主要内容表示为一堆文章,有自己的特征内容,有自己的编号,有自己的类别(标签),相互引用的关系构成了图。

cora.content:包含特征编号,特征内容,特征类别(标签)

31336	0	0	0	0	0	0 ....0 Neural_Networks
1061127	0	0	0	0	0	0 ....0 Rule_Learning
1106406	0	0	0	0	0	0 ....0 Reinforcement_Learning
13195	0	0	0	0	0	0 ....0 Reinforcement_Learning
37879	0	0	0	0	0	0 ....0 Probabilistic_Methods

1.其中左面第一列表示特征编号

2.中间的内容表示特征内容(1433维)

3.右面的最后一列表示标签

cora.cite:引用关系,也称作边

35	1033
35	103482
35	103515
35	1050679
35	1103960
35	1103985
35	1109199
35	1112911

左面第一列表示起始点(序号),右面表示终止点(序号),其中一行表示一个边,表示两个点的连接

以点作为主要特征进行分类

首先先看一下GCN网络的参数部分

self.conv1 = GCNConv(in_channels=16, out_channels=32, add_self_loops=True, normalize=True)

主要参数就是输入的维度,输出的维度

# 前向传播时调用
output = self.conv1(x, edge_index, edge_weight)

主要的参数为结点的特征矩阵与图的连接关系

也就是说数据需要预处理成结点的特征矩阵,然后单独的标签,再预处理出图的连接关系

分为三个部分。

1.数据预处理

from plistlib import Data
from torch_geometric.data import Data
import torch
#print(torch.__version__)
import torch.nn.functional as F
# import sys
# print(sys.executable)
# import torch_geometric
# print(torch_geometric.__version__)
datasetPath = 'E:/pytorch/pytorch exercise/Graph neural network/Cora dataset/cora'
node_feature_file = 'E:/pytorch/pytorch exercise/Graph neural network/Cora dataset/cora/Cora.content'
edge_file = 'E:/pytorch/pytorch exercise/Graph neural network/Cora dataset/cora/Cora.cites'
label_mapping = {}
node_features = []
node_labels = []
node_ids = {}  #特征数
# 定义一个计数器,遍历所有可能的标签
current_label = 0with open(node_feature_file,'r') as f:for line in f:parts = line.strip().split('\t')node_id = int(parts[0])features = list(map(float, parts[1:-1]))  # 特征label_str = parts[-1]if label_str not in label_mapping:label_mapping[label_str] = current_labelcurrent_label +=1# 将标签转换为整数label = label_mapping[label_str]node_ids[node_id] = len(node_features) #补充结点索引node_features.append(features)     #将节点特征依次按照数量拼接在一起node_labels.append(label)
#print(node_ids)
# 将节点特征和标签转换为 tensor
node_features = torch.tensor(node_features, dtype=torch.float)
# 输出张量的形状
print(node_features.shape)
# 或者使用 .size() 也能得到相同的结果
print(node_features.size())node_labels = torch.tensor(node_labels, dtype=torch.long)
print("node_labels size = ",node_labels.size())
edge_index = []
with open(edge_file, 'r') as f:for line in f:parts = line.strip().split('\t')source = int(parts[0])  # 源节点target = int(parts[1])  # 目标节点source_idx = node_ids[source]  # 获取节点ID的索引target_idx = node_ids[target]edge_index.append([source_idx, target_idx])#引用边的信息,生成边的索引集合
# print(source_idx)
# print(target_idx)
edge_index = torch.tensor(edge_index, dtype=torch.long).t().contiguous()
print("edge_index size = ",edge_index.size())
#print(edge_index.shape())
data = Data(x=node_features, edge_index=edge_index, y=node_labels)
# 输出数据的一些信息
print(f'节点特征矩阵 shape: {data.x.shape}')
print(f'边的连接关系 (edge_index) shape: {data.edge_index.shape}')
print(f'节点标签 shape: {data.y.shape}')# 输出第一个节点的特征和标签
print(f'节点 0 的特征: {data.x[0]}')
print(f'节点 0 的标签: {data.y[0]}')

其中

node_features表示所有点的特征结合在一起
node_labels表示所有标签集中在一起
node_ids表示特征点的个数

首先是从数据集中抽取特征矩阵的过程

with open(node_feature_file,'r') as f:  #打开文件for line in f:                      #按照行为单位,开始进行遍历parts = line.strip().split('\t')#删除其他空格与回车node_id = int(parts[0])        #将第一个元素放入node_idfeatures = list(map(float, parts[1:-1]))  # 将第二个到倒数第二个元素一并放入featureslabel_str = parts[-1]                #最后一个元素放入标签if label_str not in label_mapping:    #处理标签为null的情况label_mapping[label_str] = current_labelcurrent_label +=1# 将标签转换为整数label = label_mapping[label_str]    node_ids[node_id] = len(node_features) #补充结点索引
#为新的node_id分配一个新的整数索引,比如第一个元素node-id=35422,那么就是node_ids[35422] = 1
#也就是为第一个名字为35422的节点编辑了一个序号1,表示第一个元素node_features.append(features)     #将节点特征依次按照数量拼接在一起node_labels.append(label)           #拼接标签到一个集合中 

从数据集中提取边的集合

edge_index = []
with open(edge_file, 'r') as f:for line in f:parts = line.strip().split('\t')source = int(parts[0])  # 源节点target = int(parts[1])  # 目标节点source_idx = node_ids[source]  # 获取节点ID的索引target_idx = node_ids[target]edge_index.append([source_idx, target_idx])#引用边的信息,生成边的索引集合

转换成data对象

edge_index = torch.tensor(edge_index, dtype=torch.long).t().contiguous()
data = Data(x=node_features, edge_index=edge_index, y=node_labels)

简易的模型

class Net(torch.nn.Module):def __init__(self):super(Net, self).__init__()self.conv1 = GCNConv(data.x.size(1), 16)  # 输入特征维度是 data.x.size(1),输出 16 个特征# 计算类别数,假设 data.y 是节点标签num_classes = data.y.max().item() + 1  # 获取类别数# 第二层卷积层,输出类别数个特征self.conv2 = GCNConv(16, num_classes)def forward(self,x,edge_index):x = self.conv1(x, edge_index)        #输入特征矩阵与边的索引集合x = F.relu(x)                        #卷积后激活x = self.conv2(x, edge_index)return F.log_softmax(x, dim=1)

http://www.hkea.cn/news/995354/

相关文章:

  • 网站建设书优化大师是干什么的
  • 优秀的网站建设公司百度指数人群画像
  • wordpress企业中文模板太原seo哪家好
  • 广东网广东网站建设网站推广方案模板
  • 网站运营知识快手seo
  • 咖啡公司网站建设策划书微信营销方式
  • 柳江区城乡住房建设局网站上海seo优化服务公司
  • 西城企业网站建设企业网站怎么优化
  • 初学者做动态网站项目例子游戏特效培训机构排名
  • 汽车类网站搭建直链平台
  • 做网站遇到的困难总结网络营销软件代理
  • 做网站登录论坛外链代发
  • 东营专业网站建设公司排行青岛谷歌优化公司
  • 公众号和网站先做哪个口碑营销的形式
  • 长沙企业建网站费用关键词搜索推广排行榜
  • 怎么做网站端口代理沧州网络推广外包公司
  • php wordpress 目录seo课程培训机构
  • 常州网站建设方案优化引流app推广软件
  • 网络营销网站建设实训网络营销步骤
  • 网站都有后台吗百度竞价开户公司
  • 秭归网站建设网站seo优化心得
  • wordpress电影网站模板seo运营
  • 公司注册网上核名业务如何终止网站排名优化怎么做
  • 网站建设伍金手指下拉2网上推广平台
  • 沧州网站建设公司翼马爱情链接
  • 计算机学了出来干嘛免费优化推广网站的软件
  • 宁波网站建设优化湖南seo优化按天付费
  • 门户网站手机版google官网入口
  • 深圳市工程建设交易服务中心网站软文什么意思
  • 大型网架加工厂成都网站建设方案优化