No such file or directory: ‘data/ind.cora.x’

把graphsgcn的cora改成data不行,把data里改成cora也不行

实际上,最后把data文件夹拷到root目录里才成功。

open文件夹data的方法,不用要.和/。

names = ['x', 'y', 'tx', 'ty', 'allx', 'ally', 'graph']objects = []for i in range(len(names)):with open("data/ind.{}.{}".format(dataset_str, names[i]), 'rb') as f:if sys.version_info > (3, 0):data = pkl.load(f, encoding='latin1')if(names[i].find('graph')==-1):print(f)print(data.shape)for j in range(data.shape[0]): print('********',names[i],j,data[j].shape,'**********')print(data[j])else:print(f)print(data)objects.append(data)else:objects.append(pkl.load(f))x, y, tx, ty, allx, ally, graph = tuple(objects)

data_loader.py所有的代码

import numpy as np
import pickle as pkl
import networkx as nx
import scipy.sparse as sp
from scipy.sparse.linalg.eigen.arpack import eigsh
import sysdef parse_index_file(filename):"""Parse index file."""index = []for line in open(filename):index.append(int(line.strip()))return indexdef sample_mask(idx, l):"""Create mask."""mask = np.zeros(l)mask[idx] = 1return np.array(mask, dtype=np.bool)def load_data(dataset_str):"""Loads input data from gcn/data directoryind.dataset_str.x => the feature vectors of the training instances as scipy.sparse.csr.csr_matrix object;ind.dataset_str.tx => the feature vectors of the test instances as scipy.sparse.csr.csr_matrix object;ind.dataset_str.allx => the feature vectors of both labeled and unlabeled training instances(a superset of ind.dataset_str.x) as scipy.sparse.csr.csr_matrix object;ind.dataset_str.y => the one-hot labels of the labeled training instances as numpy.ndarray object;ind.dataset_str.ty => the one-hot labels of the test instances as numpy.ndarray object;ind.dataset_str.ally => the labels for instances in ind.dataset_str.allx as numpy.ndarray object;ind.dataset_str.graph => a dict in the format {index: [index_of_neighbor_nodes]} as collections.defaultdictobject;ind.dataset_str.test.index => the indices of test instances in graph, for the inductive setting as list object.All objects above must be saved using python pickle module.:param dataset_str: Dataset name:return: All data input files loaded (as well the training/test data)."""names = ['x', 'y', 'tx', 'ty', 'allx', 'ally', 'graph']objects = []for i in range(len(names)):with open("data/ind.{}.{}".format(dataset_str, names[i]), 'rb') as f:if sys.version_info > (3, 0):data = pkl.load(f, encoding='latin1')if(names[i].find('graph')==-1):print(f)print(data.shape)for j in range(data.shape[0]): print('********',names[i],j,data[j].shape,'**********')print(data[j])else:print(f)print(data)objects.append(data)else:objects.append(pkl.load(f))x, y, tx, ty, allx, ally, graph = tuple(objects)#测试数据集# print(x[0][0],x.shape,type(x))  ##x是一个稀疏矩阵,记住1的位置,140个实例,每个实例的特征向量维度是1433  (140,1433)# print(y[0],y.shape)   ##y是标签向量,7分类,140个实例 (140,7)##训练数据集# print(tx[0][0],tx.shape,type(tx))  ##tx是一个稀疏矩阵,1000个实例,每个实例的特征向量维度是1433  (1000,1433)# print(ty[0],ty.shape)   ##y是标签向量,7分类,1000个实例 (1000,7)##allx,ally和上面的形式一致# print(allx[0][0],allx.shape,type(allx))  ##tx是一个稀疏矩阵,1708个实例,每个实例的特征向量维度是1433  (1708,1433)# print(ally[0],ally.shape)   ##y是标签向量,7分类,1708个实例 (1708,7)##graph是一个字典,大图总共2708个节点for i in graph:print(i,graph[i])test_idx_reorder = parse_index_file("data/ind.{}.test.index".format(dataset_str))test_idx_range = np.sort(test_idx_reorder)print(test_idx_range)if dataset_str == 'citeseer':# Fix citeseer dataset (there are some isolated nodes in the graph)# Find isolated nodes, add them as zero-vecs into the right positiontest_idx_range_full = range(min(test_idx_reorder), max(test_idx_reorder)+1)tx_extended = sp.lil_matrix((len(test_idx_range_full), x.shape[1]))tx_extended[test_idx_range-min(test_idx_range), :] = txtx = tx_extendedty_extended = np.zeros((len(test_idx_range_full), y.shape[1]))ty_extended[test_idx_range-min(test_idx_range), :] = tyty = ty_extendedfeatures = sp.vstack((allx, tx)).tolil()features[test_idx_reorder, :] = features[test_idx_range, :]adj = nx.adjacency_matrix(nx.from_dict_of_lists(graph))# print(adj,adj.shape)labels = np.vstack((ally, ty))labels[test_idx_reorder, :] = labels[test_idx_range, :]idx_test = test_idx_range.tolist()idx_train = range(len(y))idx_val = range(len(y), len(y)+500)train_mask = sample_mask(idx_train, labels.shape[0])val_mask = sample_mask(idx_val, labels.shape[0])test_mask = sample_mask(idx_test, labels.shape[0])y_train = np.zeros(labels.shape)y_val = np.zeros(labels.shape)y_test = np.zeros(labels.shape)y_train[train_mask, :] = labels[train_mask, :]y_val[val_mask, :] = labels[val_mask, :]y_test[test_mask, :] = labels[test_mask, :]return adj, features, y_train, y_val, y_test, train_mask, val_mask, test_maskdef sparse_to_tuple(sparse_mx):"""Convert sparse matrix to tuple representation."""def to_tuple(mx):if not sp.isspmatrix_coo(mx):mx = mx.tocoo()coords = np.vstack((mx.row, mx.col)).transpose()values = mx.datashape = mx.shapereturn coords, values, shapeif isinstance(sparse_mx, list):for i in range(len(sparse_mx)):sparse_mx[i] = to_tuple(sparse_mx[i])else:sparse_mx = to_tuple(sparse_mx)return sparse_mxdef preprocess_features(features):"""Row-normalize feature matrix and convert to tuple representation"""rowsum = np.array(features.sum(1))r_inv = np.power(rowsum, -1).flatten()r_inv[np.isinf(r_inv)] = 0.r_mat_inv = sp.diags(r_inv)features = r_mat_inv.dot(features)return sparse_to_tuple(features)def normalize_adj(adj):"""Symmetrically normalize adjacency matrix."""adj = sp.coo_matrix(adj)rowsum = np.array(adj.sum(1))d_inv_sqrt = np.power(rowsum, -0.5).flatten()d_inv_sqrt[np.isinf(d_inv_sqrt)] = 0.d_mat_inv_sqrt = sp.diags(d_inv_sqrt)return adj.dot(d_mat_inv_sqrt).transpose().dot(d_mat_inv_sqrt).tocoo()def preprocess_adj(adj):"""Preprocessing of adjacency matrix for simple GCN model and conversion to tuple representation."""adj_normalized = normalize_adj(adj + sp.eye(adj.shape[0]))return sparse_to_tuple(adj_normalized)def construct_feed_dict(features, support, labels, labels_mask, placeholders):"""Construct feed dictionary."""feed_dict = dict()feed_dict.update({placeholders['labels']: labels})feed_dict.update({placeholders['labels_mask']: labels_mask})feed_dict.update({placeholders['features']: features})feed_dict.update({placeholders['support'][i]: support[i] for i in range(len(support))})feed_dict.update({placeholders['num_features_nonzero']: features[1].shape})return feed_dictdef chebyshev_polynomials(adj, k):"""Calculate Chebyshev polynomials up to order k. Return a list of sparse matrices (tuple representation)."""print("Calculating Chebyshev polynomials up to order {}...".format(k))adj_normalized = normalize_adj(adj)laplacian = sp.eye(adj.shape[0]) - adj_normalizedlargest_eigval, _ = eigsh(laplacian, 1, which='LM')scaled_laplacian = (2. / largest_eigval[0]) * laplacian - sp.eye(adj.shape[0])t_k = list()t_k.append(sp.eye(adj.shape[0]))t_k.append(scaled_laplacian)def chebyshev_recurrence(t_k_minus_one, t_k_minus_two, scaled_lap):s_lap = sp.csr_matrix(scaled_lap, copy=True)return 2 * s_lap.dot(t_k_minus_one) - t_k_minus_twofor i in range(2, k+1):t_k.append(chebyshev_recurrence(t_k[-1], t_k[-2], scaled_laplacian))return sparse_to_tuple(t_k)load_data('cora')

终于会读写cora数据集文件了。

bug: No such file or directory: ‘data/ind.cora.x‘相关推荐

  1. 成功解FileNotFoundError: [Errno 2] No such file or directory: './data\\mnist\\train-images-idx3-ubyte'

    成功解FileNotFoundError: [Errno 2] No such file or directory:  './data\\mnist\\train-images-idx3-ubyte' ...

  2. Pycharm踩坑(一) FileNotFoundError: [Errno 2] No such file or directory: ‘../data/users.txt‘ 目录结构

    Python 使用Pycharm运行程序提示:FileNotFoundError: [Errno 2] No such file or directory: '../data/users.txt' 目 ...

  3. 读取文件报错:FileNotFoundError: [Errno 2] No such file or directory

    文章目录 问题描述 问题分析 解决办法 问题描述 使用 img = Image.open('data/DSC_8923.jpg') 读取一张图片时,报 FileNotFoundError: [Errn ...

  4. 成功解决FileNotFoundError: [Errno 2] No such file or directory: '/home/bai/Myprojects/Tfexamples/data/kn

    成功解决FileNotFoundError: [Errno 2] No such file or directory: '/home/bai/Myprojects/Tfexamples/data/kn ...

  5. The file or directory to be published does not exist: /data/vendor/bower/jquery/dist

    Exception 'yii\base\InvalidParamException' with message 'The file or directory to be published does ...

  6. VScode运行fs.readFile时报错no such file or directory或无法输出data或undefined

    这个问题我在网上查找解决办法的时候大多都是说异步的问题,然而用了那些所谓的解决办法后还是输出不了data的值,显然不是异步的问题,今天记录下踩坑. 如果Code Runner插件配置完毕,可以跳过第一 ...

  7. Apollo 星火计划踩坑记录 dreamview启动报错“No such file or directory: ‘ping‘: ‘ping‘”

    第一次以计算机科学与技术本科生身份写blog也是值得纪念的 百度Apollo开源社区近期开始了"星火计划第二期",使用了新版本的工程框架,但是毕竟还在测试中,小bug不可避免,这篇 ...

  8. 【 Linux学习】解决Ubuntu系统发送邮件失败,报错:send-mail: fatal: open /etc/postfix/main.cf: No such file or directory

    一.问题描述 今天在Ubuntu系统上,使用mail命令发送邮件的时候,失败了,报错send-mail: fatal: open /etc/postfix/main.cf: No such file ...

  9. FileNotFoundError: [Errno 2] No such file or directory:XXXX

    情况一: 今天在运行readme的时候出现了一个错误"": File "/mnt/d/Pycharm_workspace/pretrain/SMILES-BERT/fai ...

最新文章

  1. live555学习笔记2-基础类
  2. Apache与IIS的优劣对比点点评
  3. php 数据分别是怎么传的_四种php页面间传递数据方法
  4. C 函数传递指针参数注意事项
  5. python3 音乐播放器_python3 音乐播放器
  6. 解密QQ非会员漫游聊天记录
  7. 自动化软件部署的shell脚本
  8. app上线发布流程_APP上线发布流程
  9. 捷达vs7测试_捷达VS5话题:防撞钢梁,溃缩梁。第200311期
  10. rpt水晶报表制作过程
  11. java生成点阵图_【图片】一个零基础的小白是如何脱变成Java后端工程师的?【java吧】_百度贴吧...
  12. python 安装包时出现:SyntaxError: invalid syntax
  13. Jupyter Notebook 自动生成目录(超级实用)
  14. baddy:核心函数入口
  15. 计算机英语 单词1-100
  16. C++实现改变网速*SpeedDuplex和网速监控
  17. mysql的month_MySQL month()函数
  18. 黄金比例在设计上的应用
  19. na5tr1 测距芯片调试小结
  20. matplotlib函数库使用imshow绘制像素图片

热门文章

  1. 假期余额查询 2021-04-30
  2. Zigbee学习笔记
  3. 早睡早起使人健康、富裕又聪明
  4. 苹果APP安装包ipa如何安装在手机上
  5. 如何在Linux中检查硬盘上的坏道或坏块
  6. 分享1个月速成软件设计师资格证的经验(●----●)
  7. jQuery制作火柴人游戏源码
  8. 复盘国内互联网公司电商之路
  9. 【STM32F4教程】第六节:通用定时器之PWM实现呼吸灯
  10. keras中model.evaluate()函数使用从flow_from_directory中生成的测试集一直循环问题