python-在Tensorflow中使用BigQueryReader读取数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python-在Tensorflow中使用BigQueryReader读取数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1740字,纯文字阅读大概需要3分钟。
内容图文
![python-在Tensorflow中使用BigQueryReader读取数据](/upload/InfoBanner/zyjiaocheng/685/9a523bca9cba4c179808eececc436c5b.jpg)
我尝试使用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>)
为什么阅读器不返回任何数据?
解决方法:
读取器未返回空对象:它正在返回标量(即,等级为0或“空”形状的张量).有关更多详细信息,请参见TensorFlow programmers guide on tensor shapes.
形状错误“形状必须为等级1但等级为0”表示tf.parse_example() op希望输入的是向量(等级1张量),而不是标量.至少有两种可能的解决方案:
>请改用需要标量输入的tf.parse_single_example()操作.
>将reader.read()返回的值整形为矢量,例如使用tf.expand_dims(examples_serialized, 0).
内容总结
以上是互联网集市为您收集整理的python-在Tensorflow中使用BigQueryReader读取数据全部内容,希望文章能够帮你解决python-在Tensorflow中使用BigQueryReader读取数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。