简体   繁体   English

AttributeError:模块'tensorflow.contrib.learn'没有属性'TensorFlowDNNClassifier'

[英]AttributeError: module 'tensorflow.contrib.learn' has no attribute 'TensorFlowDNNClassifier'

This is the ml tensorflow code I am trying to execute - 这是我试图执行的ml tensorflow代码 -

import tensorflow.contrib.learn as skflow
from sklearn import datasets, metrics
iris = datasets.load_iris()
classifier = skflow.TensorFlowDNNClassifier(hidden_units=[10, 20, 10], n_classes=3)
classifier.fit(iris.data, iris.target)
score = metrics.accuracy_score(iris.target, classifier.predict(iris.data))

print("Accuracy: %f" % score)

It gives the following error - 它给出以下错误 -

Traceback (most recent call last): Traceback(最近一次调用最后一次):

File "C:\\Users\\admin\\test3.py", line 5, in 文件“C:\\ Users \\ admin \\ test3.py”,第5行,in

classifier = skflow.TensorFlowDNNClassifier(hidden_units=[10, 20, 10], n_classes=3) AttributeError: module 'tensorflow.contrib.learn' has no attribute 'TensorFlowDNNClassifier' classifier = skflow.TensorFlowDNNClassifier(hidden_​​units = [10,20,10],n_classes = 3)AttributeError:模块'tensorflow.contrib.learn'没有属性'TensorFlowDNNClassifier'

[Finished in 69.3s with exit code 1] [完成69.3s,退出代码1]

[shell_cmd: python -u "C:\\Users\\admin\\test3.py"] [shell_cmd:python -u“C:\\ Users \\ admin \\ test3.py”]

There seems to have been a major refactor in the TensorFlow project, and all the skflow code has been moved under the main tensorflow repository. TensorFlow项目中似乎有一个主要的重构,并且所有skflow代码都已在主tensorflow存储库下移动。

Try to replace TensorFlowDNNClassifier with just DNNClassifier . 尝试用DNNClassifier替换TensorFlowDNNClassifier The new class can be found out here . 新课程可以在这里找到。 Your corrected code will look like, 您的更正后的代码看起来像,

import tensorflow.contrib.learn as skflow
from sklearn import datasets, metrics
iris = datasets.load_iris()
# made a change in the next line
classifier = skflow.DNNClassifier(hidden_units=[10, 20, 10], n_classes=3)
classifier.fit(iris.data, iris.target)
score = metrics.accuracy_score(iris.target, classifier.predict(iris.data))

print("Accuracy: %f" % score)
import tensorflow.contrib.learn.python from tensorflow.contrib.learn.python import learn as learn

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模块'tensorflow.contrib.learn'没有属性'python' - module 'tensorflow.contrib.learn' has no attribute 'python' 没有名为 tensorflow.contrib.learn 的模块 - No module named tensorflow.contrib.learn AttributeError:模块“ tensorflow.contrib.learn.python.learn.ops”没有属性“ split_squeeze” - AttributeError: module 'tensorflow.contrib.learn.python.learn.ops' has no attribute 'split_squeeze' AttributeError:模块“tensorflow”在 tensorflow 2.0 中没有属性“contrib” - AttributeError: module 'tensorflow' has no attribute 'contrib' in tensorflow 2.0 AttributeError:模块“ tensorflow.contrib”没有属性“ estimator” - AttributeError: module 'tensorflow.contrib' has no attribute 'estimator' AttributeError:模块“ tensorflow.contrib.rnn”没有属性“ BasicLSTMCell” - AttributeError: module 'tensorflow.contrib.rnn' has no attribute 'BasicLSTMCell' AttributeError:模块“ tensorflow.contrib.rnn”没有属性“ GRUCell” - AttributeError: Module 'tensorflow.contrib.rnn' has no attribute 'GRUCell' 出现错误“AttributeError:模块'tensorflow'没有属性'contrib'” - Getting error “AttributeError: module 'tensorflow' has no attribute 'contrib'” AttributeError: 模块“tensorflow_core.compat.v1”没有属性“contrib” - AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib' AttributeError:模块“ tensorflow.contrib.slim”没有属性“ nets” - AttributeError: module 'tensorflow.contrib.slim' has no attribute 'nets'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM