- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我关注了 Tensorflow Reading Data指南以 TFRecord 的形式获取我的应用程序数据,并在我的输入管道中使用 TFRecordReader 来读取此数据。
我现在正在阅读有关使用 skflow/tf.learn 的指南构建一个简单的回归器,但我看不到如何通过这些工具使用我的输入数据。
在以下代码中,应用程序在调用 regressor.fit(..)
时失败,出现 ValueError: setting an array element with a sequence.
。
错误:
Traceback (most recent call last):
File ".../tf.py", line 138, in <module>
run()
File ".../tf.py", line 86, in run
regressor.fit(x, labels)
File ".../site-packages/tensorflow/contrib/learn/python/learn/estimators/base.py", line 218, in fit
self.batch_size)
File ".../site-packages/tensorflow/contrib/learn/python/learn/io/data_feeder.py", line 99, in setup_train_data_feeder
return data_feeder_cls(X, y, n_classes, batch_size)
File ".../site-packages/tensorflow/contrib/learn/python/learn/io/data_feeder.py", line 191, in __init__
self.X = check_array(X, dtype=x_dtype)
File ".../site-packages/tensorflow/contrib/learn/python/learn/io/data_feeder.py", line 161, in check_array
array = np.array(array, dtype=dtype, order=None, copy=False)
ValueError: setting an array element with a sequence.
代码:
import tensorflow as tf
import tensorflow.contrib.learn as learn
def inputs():
with tf.name_scope('input'):
filename_queue = tf.train.string_input_producer([filename])
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(serialized_example, feature_spec)
labels = features.pop('actual')
some_feature = features['some_feature']
features_batch, labels_batch = tf.train.shuffle_batch(
[some_feature, labels], batch_size=batch_size, capacity=capacity,
min_after_dequeue=min_after_dequeue)
return features_batch, labels_batch
def run():
with tf.Graph().as_default():
x, labels = inputs()
# regressor = learn.TensorFlowDNNRegressor(hidden_units=[10, 20, 10])
regressor = learn.TensorFlowLinearRegressor()
regressor.fit(x, labels)
...
看起来 check_array
调用需要一个真正的数组,而不是张量。我可以做些什么来将我的数据整理成正确的形状吗?
最佳答案
看起来您使用的 API 已贬值。如果您使用更现代的 tf.contrib.learn.LinearRegressor
(我认为 >= 1.0),你应该指定 input_fn
,它基本上产生输入和标签。我认为在您的示例中,这就像将 run
函数更改为一样简单:
def run():
with tf.Graph().as_default():
regressor = tf.contrib.learn.LinearRegressor()
regressor.fit(input_fn=my_input_fn)
然后定义一个名为 my_input_fn
的输入函数。来自 the docs ,此输入函数采用以下形式:
def my_input_fn():
# Preprocess your data here...
# ...then return 1) a mapping of feature columns to Tensors with
# the corresponding feature data, and 2) a Tensor containing labels
return feature_cols, labels
我认为文档可以帮助您完成剩下的工作。从这里开始,我很难说你应该如何在没有看到你的数据的情况下继续。
关于python - 将 Tensorflow 输入管道与 skflow/tf learn 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37516684/
我有一个数据集 X,可以说有 2000 行。我想把每两行放在一起表示。结果应为 1000 行数据集(列数应保持不变)。 我已经在 matlab 中做到了这一点 #matlab function fun
我正处于学习 SkFlow/TensorFlow 的早期阶段,所以我将阐述我对我正在尝试做的事情的理解,尽管它可能不正确。 假设我正在尝试构建一个模型来预测汽车是否会通过排放测试。 我的训练和测试 c
我正在尝试预测一个时间序列:给定 50 个先前的值,我想预测接下来的 5 个值。 为此,我使用了 skflow 包(基于 TensorFlow),这个问题相对接近 Boston example pro
我刚刚安装了 skflow 和 TensorFlow,我对 skflow 附带的示例有疑问。示例代码为: import random import pandas from sklearn.linear
我是 skflow 新手。通过以下示例代码,我能够初始化神经网络估计器。 regressor = skflow.TensorFlowDNNRegressor( hidden_units=[1
我最近从 tensorflow 切换到 skflow。在 tensorflow 中,我们会将 lambda*tf.nn.l2_loss(weights) 添加到我们的损失中。现在我在 skflow 中
我正在与其他人共享的 EC2 实例上使用 Tensorflow 和 skflow 训练卷积神经网络。为了让我们所有人都能同时工作,我想限制分配的可用 GPU 内存的比例。 This question使
我正在尝试在使用 sklearn 实现的同时使用 TensorFlow 制作回归模型,因此它可以与我制作的所有其他模型很好地配合。然而,我似乎无法找到一种使用自定义评分函数(成本函数或目标函数)来训练
我需要在我的 model_fn() 中创建一个随机变量,其形状为 [batch_size, 20]。 我不想将 batch_size 作为参数传递,因为这样我就无法使用不同的批量大小进行预测。 去掉与
我在 4 GPU Amazon 实例上遇到了这个问题,使用了一个简单的示例脚本: import skflow import tensorflow as tf from sklearn import d
是否可以使用没有标记输入(或输出)节点的 Tensorflow C++ API 执行图形?据我所知,在训练我的模型时(在 python 中使用 skflow,后来我将其保存为二进制 protobuf)
我关注了 Tensorflow Reading Data指南以 TFRecord 的形式获取我的应用程序数据,并在我的输入管道中使用 TFRecordReader 来读取此数据。 我现在正在阅读有关使
我尝试从 skflow 运行 iris_save_restore.py 示例,根本不更改代码。 但是,我遇到了一个错误,我不确定如何继续。它似乎是在从保存的文件恢复模型时发生的。 new_classi
我无法让 DNNClassifier 在训练时打印进度,即损失和验证分数。据我所知,可以使用从 BaseEstimator 继承的配置参数打印损失,但是当我传递一个 RunConfig 对象时,分类器
在 Anaconda 2.7 中运行此示例时: import tensorflow.contrib.learn as skflow def DNN_model(X, y): """This i
我是一名优秀的程序员,十分优秀!