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. HDFS文件系统基本文件命令、编程读写HDFS
  2. autumn 0.5.1 : Python Package Index
  3. [转]CS的顶级会议和期刊
  4. matlab恢复默认界面布局
  5. python的imread、newaxis
  6. c/c++整理--c++面向对象(4)
  7. 大数据技术之 Kafka (第 4 章 Kafka API ) Producer API
  8. Tensorflow实践:用神经网络训练分类器
  9. mac 源码编译yar遇见的坑
  10. window下启动Redis闪退问题解决
  11. 【三维路径规划】基于matlab遗传算法无人机三维路径规划【含Matlab源码 1526期】
  12. Boost和STL学习资料大全
  13. dubbo源码解析-cluster
  14. java drawlines()方法
  15. Qt ListView 刷新数据
  16. 使用Navicat导入“中国5级行政区域mysql库”
  17. 2018年,数万款小程序暴毙在路上
  18. 从Oracle迁移到MySQL的各种坑及自救方案
  19. word转换为图片格式的几种方式
  20. MATLAB完美画图:改变坐标轴刻度的显示数值,常数函数的作图

热门文章

  1. 使用https://mail.google.com/登录GMail
  2. fuel-6.1 iso制作
  3. Python单源最短路径算法汇总
  4. proxmox 宿主机添加硬盘
  5. 你的英语不行!微软亚研自动语法纠错系统达到人类水平
  6. Python中long与int
  7. 学生HTML个人网页作业作品 ~ 科技大学官网 网页设计成品~ 学生网页设计作业源码
  8. 公钥、私钥、证书的生成
  9. VRay 3.6 for SketchUp 混合材质之艺术背景制作教程
  10. 海量时序数据低成本存储架构设计