我正在尝试训练 DNNClassifier,但是当我尝试训练模型时,我不断遇到这个问题 问题称为
属性错误:模块“tensorflow.python.framework.tensor_shape”没有属性“标量”
import tensorflow as tf
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784')
feature_columns = [tf.feature_column.numeric_column("x", shape=[784])]
feature_columns
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(mnist['data'] , mnist['target'])
classifier = tf.estimator.DNNClassifier(hidden_units=[300, 100], n_classes=10,
feature_columns=feature_columns)
def input_train_fn(X,y):
features = {'x':tf.convert_to_tensor(X)}
return features, y.reshape((-1,1)).astype(int)
classifier.train(input_fn=lambda : input_train_fn(X_train, y_train), steps=100000)
最后一行抛出以下错误:-
属性错误:模块“tensorflow.python.framework.tensor_shape”没有属性“标量”
最佳答案
升级您的 tensorflow 和 tensorflow 估计器可能会有所帮助。
我在 Github tf-estimator 存储库 ( https://github.com/tensorflow/estimator/commit/561b3f95d4f9041cb7a2fbbfdc94efee16413725#diff-a815f16c6f90bfe736d98b8c99a7c2fcL337 ) 中找到了此提交。
关于python - 属性错误: module 'tensorflow.python.framework.tensor_shape' has no attribute 'scalar' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61431380/