python - 使用从文件到另一个文件的变量
问题描述
我有 utils 文件作为
def load_data(dataset_str):
"""
Loads input data from gcn/data directory
ind.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.defaultdict
object;
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):
objects.append(pkl.load(f, encoding='latin1'))
else:
objects.append(pkl.load(f))
并想在这个文件中使用 ally 变量(训练文件)
flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_string('dataset', 'citeseer', 'Dataset string.') # 'cora', 'citeseer', 'pubmed'
flags.DEFINE_string('model', 'gcn', 'Model string.') # 'gcn', 'gcn_cheby', 'dense'
flags.DEFINE_float('learning_rate', 0.01, 'Initial learning rate.')
flags.DEFINE_integer('epochs', 200, 'Number of epochs to train.')
flags.DEFINE_integer('hidden1', 16, 'Number of units in hidden layer 1.')
flags.DEFINE_float('dropout', 0.5, 'Dropout rate (1 - keep probability).')
flags.DEFINE_float('weight_decay', 5e-4, 'Weight for L2 loss on embedding matrix.')
flags.DEFINE_integer('early_stopping', 10, 'Tolerance for early stopping (# of epochs).')
flags.DEFINE_integer('max_degree', 3, 'Maximum Chebyshev polynomial degree.')
# Load data
adj, features, y_train, y_val, y_test, ally, train_mask, val_mask, test_mask =
load_data(FLAGS.dataset)
我试图在火车文件中添加 ally 变量,特别是在最后一行
# Load data
adj, features, y_train, y_val, y_test, ally, train_mask, val_mask, test_mask =
load_data(FLAGS.dataset)
但是这个错误似乎没有足够的值来解包(预期为 9,得到 8)
解决方案
推荐阅读
- amazon-web-services - 我们可以通过 AWS-simple-notification-service 发送 AWS codepipline 的失败日志吗?
- angular - 在 GitLab 上部署 Compodoc 文档而不使用 GitLab Pages
- c# - System.Xml.XmlException 此 XML 文档中禁止 DTD 异常
- linkedin - LinkedIn API 营销开发者平台 AdAnalyticsV2 中的分页失败
- c# - 如何访问对象列表中的对象?
- ios - 将 ArcGIS 的时间滑块工具集成到 ios swift xcode 应用程序
- node.js - 如何更改node.js中soap包生成的xml?
- java - 如何使用 ModelMapper 映射 oneToMany
- json - 对话流向所有平台发送卡片响应
- c# - 如何从 Xamarin Forms 项目中调用 Android 和 iOS 项目中可用的方法?