2

I am trying to train DNNClassifier but when i try to train the model i keep running into this issue called

AttributeError: module 'tensorflow.python.framework.tensor_shape' has no attribute 'scalar'

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)

last line throws following error:-

AttributeError: module 'tensorflow.python.framework.tensor_shape' has no attribute 'scalar'

2 Answers 2

2

Upgrading your tensorflow and tensorflow-estimator might help.

I found this commit in Github tf-estimator repository (https://github.com/tensorflow/estimator/commit/561b3f95d4f9041cb7a2fbbfdc94efee16413725#diff-a815f16c6f90bfe736d98b8c99a7c2fcL337).

Sign up to request clarification or add additional context in comments.

Comments

1

The code you use is depreciated

You need to adjust the tensor_shape you use.

# depreciated
# tensor_shape.scalar()

# running
tensor_shape.TensorShape([])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.