【发布时间】:2017-08-21 11:18:35
【问题描述】:
我尝试使用来自 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)
执行此代码示例时,我得到:
File "/home/juta/.local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 659, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Shape must be rank 1 but is rank 0 for 'ParseExample_3/ParseExample' (op: 'ParseExample') with input shapes: [], [0], [], [], [], [], [0], [0], [0], [0].
解析可能失败,因为 reader.read(queue) 似乎返回空对象:
ReaderRead(key=<tf.Tensor 'ReaderRead:0' shape=() dtype=string>, value=<tf.Tensor 'ReaderRead:1' shape=() dtype=string>)
为什么阅读器没有返回任何数据?
【问题讨论】:
标签: python tensorflow google-bigquery