python -tf.contrib.learn load_csv_with_header在TensorFlow 1.1中不起作用

python -tf.contrib.learn load_csv_with_header在TensorFlow 1.1中不起作用,第1张

概述我安装了最新的TensorFlow(v1.1.0)并尝试运行 tf.contrib.learn Quickstart教程,您可以在其中为IRIS数据集构建分类器.但是,当我尝试时: training_set = tf.contrib.learn.datasets.base.load_csv_with_header( filename=IRIS_TRAINING, target_dt 我安装了最新的TensorFlow(v1.1.0)并尝试运行 tf.contrib.learn Quickstart教程,您可以在其中为IRIS数据集构建分类器.但是,当我尝试时:

training_set = tf.contrib.learn.datasets.base.load_csv_with_header(    filename=IRIS_TRAINING,target_dtype=np.int,features_dtype=np.float32)

我遇到了stopiteration错误.

当我检查API时,我没有找到任何关于load_csv_with_header()的信息.他们是否在最新版本中更改了它而没有更新教程?我怎样才能解决这个问题?

编辑:
我使用python3.6,如果这有任何区别.

解决方法 这是因为Python 2和Python 3之间存在差异.下面我的代码适用于Python 3.5:

if not os.path.exists(IRIS_TRAINING):    raw = urllib.request.urlopen(IRIS_TRAINING_URL).read().decode()    with open(IRIS_TRAINING,'w') as f:        f.write(raw)if not os.path.exists(IRIS_TEST):    raw = urllib.request.urlopen(IRIS_TEST_URL).read().decode()    with open(IRIS_TEST,'w') as f:        f.write(raw)

可能发生的是您的代码在IRIS_TRAINING之后创建了一个文件名.但文件是空的.因此提出了stopiteration.如果你看一下load_csv_with_header的实现:

with gfile.Open(filename) as csv_file:    data_file = csv.reader(csv_file)    header = next(data_file)

当next没有检测到任何其他要读取的项目时,会引发stopiteration,如文档https://docs.python.org/3.5/library/exceptions.html#StopIteration所示

请注意我的代码与Tensorflow教程中显示的Python 2版本相比的变化:

> urllib.request.urlopen而不是urllib.urlopen> read()在read()之后执行

总结

以上是内存溢出为你收集整理的python -tf.contrib.learn load_csv_with_header在TensorFlow 1.1中不起作用全部内容,希望文章能够帮你解决python -tf.contrib.learn load_csv_with_header在TensorFlow 1.1中不起作用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1193922.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-03
下一篇2022-06-03

发表评论

登录后才能评论

评论列表(0条)

    保存