我试图使用Tensorflow中的BigQueryReader,但实际读取数据时没有成功。这是我的代码:
import tensorflow as tf
from tensorflow.contrib.cloud.python.ops.bigquery_reader_ops import BigQueryReader
import time
features = dict(
weight_pounds=tf.FixedLenFeature([1], tf.float32),
mother_age=tf.FixedLenFeature([1], tf.float32),
father_age=tf.FixedLenFeature([1], tf.float32),
gestation_weeks=tf.FixedLenFeature([1], tf.float32))
millis = int(round(time.time() * 1000))
reader = BigQueryReader(project_id="bigquery-public-data",
dataset_id="samples",
table_id="natality",
timestamp_millis=millis,
num_partitions=10,
features=features)
queue = tf.train.string_input_producer(reader.partitions())
row_id, examples_serialized = reader.read(queue)
examples = tf.parse_example(examples_serialized, features=features)
执行此代码示例时,我得到:
^{pr2}$解析可能失败,因为读卡器.read(queue)似乎返回空对象:
ReaderRead(key=<tf.Tensor 'ReaderRead:0' shape=() dtype=string>, value=<tf.Tensor 'ReaderRead:1' shape=() dtype=string>)
为什么读卡器没有返回任何数据?在
我也遇到过同样的问题,尝试了三种方法。应运行以下解决方案:
但是,即使此代码运行,以下代码仍将挂起而不生成任何输出:
^{pr2}$推测一下,这个问题可能源于
^{3}$tf.train.string_input_producer
现在被弃用,取而代之的是tf.data
,因此可能不再支持这种用法。另一方面,我找不到任何关于如何在BigQuery中使用tf.data
的文档。我试过这样的方法:但这将返回
IndexError: list index out of range
错误读取器不返回空对象:它返回标量(即秩为0的张量或“空”形状)。有关详细信息,请参见TensorFlowprogrammers guide on tensor shapes。在
{or-rank>表示输入的形状必须小于1^而不是标量。至少有两种可能的解决方案:
reader.read()
返回的值重塑为向量,例如使用^{相关问题 更多 >
编程相关推荐