gpt4 book ai didi

python - Tensorflow 分类示例期间的 tf.train.get.global_step 错误

转载 作者:行者123 更新时间:2023-11-28 19:05:46 24 4
gpt4 key购买 nike

我正在关注 Siraj Raval 的 YouTube 视频,为鸢尾花数据集构建一个简单的分类器。该视频的日期是 2016 年 5 月,所以我确信 Tensorflow 的某些区域已经更新。我收到一条错误消息,上面写着“请切换到 tf.train.get.global_step。我正在处理旧的过时的 Tensorflow 库,我已经尝试通过研究 feature_columns 找出新的库。我认为这会解决它,但是错误仍然存​​在。非常感谢任何帮助,并公开欢迎任何关于成为受过教育的 Tensorflow 用户的建议。

这是我的代码

import tensorflow.contrib.learn as skflow
from sklearn import datasets, metrics

iris = datasets.load_iris()

feature_columns = skflow.infer_real_valued_columns_from_input(iris.data)

classifier = skflow.LinearClassifier(feature_columns=feature_columns, n_classes=3)

classifier.fit(iris.data, iris.target)


score = metrics.accuracy_score(iris.target, classifier.predict(iris.data))

print("Accuracy: %f" % score)

这里是错误:

WARNING:tensorflow:float64 is not supported by many models, consider casting to float32.
WARNING:tensorflow:Using temporary folder as model directory: C:\Users\isaia\AppData\Local\Temp\tmp8be6vyhq
WARNING:tensorflow:From C:/Users/isaia/PycharmProjects/untitled5/ml.py:10: calling BaseEstimator.fit (from tensorflow.contrib.learn.python.learn.estimators.estimator) with x is deprecated and will be removed after 2016-12-01.
Instructions for updating:
Estimator is decoupled from Scikit Learn interface by moving into
separate class SKCompat. Arguments x, y and batch_size are only
available in the SKCompat class, Estimator will only accept input_fn.
Example conversion:
est = Estimator(...) -> est = SKCompat(Estimator(...))
WARNING:tensorflow:From C:/Users/isaia/PycharmProjects/untitled5/ml.py:10: calling BaseEstimator.fit (from tensorflow.contrib.learn.python.learn.estimators.estimator) with y is deprecated and will be removed after 2016-12-01.
Instructions for updating:
Estimator is decoupled from Scikit Learn interface by moving into
separate class SKCompat. Arguments x, y and batch_size are only
available in the SKCompat class, Estimator will only accept input_fn.
Example conversion:
est = Estimator(...) -> est = SKCompat(Estimator(...))
WARNING:tensorflow:float64 is not supported by many models, consider casting to float32.
WARNING:tensorflow:From C:\Users\isaia\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\linear.py:173: get_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.get_global_step

预先感谢您的帮助

最佳答案

这个估算器is basically deprecated并且可以在下一个版本中从 tensorflow 中删除(并且你会收到一些关于它的警告),你应该使用 tf.estimator.LinearClassifier .它的 API 略有不同,但思想仍然相同。完整代码如下:

import numpy as np
import tensorflow as tf
from sklearn import datasets, metrics

iris = datasets.load_iris()

# The classifier
feature_columns = [tf.feature_column.numeric_column("x", shape=[4])]
classifier = tf.estimator.LinearClassifier(feature_columns=feature_columns,
n_classes=3)

# Training
train_input_fn = tf.estimator.inputs.numpy_input_fn(x={"x": iris.data},
y=iris.target,
num_epochs=50,
shuffle=True)
classifier.train(train_input_fn)

# Testing
test_input_fn = tf.estimator.inputs.numpy_input_fn(x={"x": iris.data},
num_epochs=1,
shuffle=False)
predictions = classifier.predict(test_input_fn)
predicted_classes = [p["classes"].astype(np.float)[0] for p in predictions]

score = metrics.accuracy_score(iris.target, predicted_classes)
print("Accuracy: %f" % score)

关于python - Tensorflow 分类示例期间的 tf.train.get.global_step 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47115957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com