python - 属性错误: module 'tensorflow.python.framework.tensor_shape' has no attribute 'scalar'

标签 python tensorflow

我正在尝试训练 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/

相关文章:

从索引到值的 tensorflow

python - Tf.keras model.predict() 返回高于 1 的类别概率?

python - gethostbyaddr() 在 Python 3 中引发 UnicodeDecodeError

python - python中的xml遍历

python - 访问张量的元素

c++ - 握手失败,出现 fatal error SSL_ERROR_SSL : error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER

python - 如何将 Tensorflow 模型转换为 tensorflow.js 模型?

python - 回调函数中的 ctypes POINTER(c_void_p)

Python,sigaction(2) 可用吗?

python - 从 Pandas 数据框中的组内选择特定行