Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numpy input error - list object has no attribute shape when running mnist example #214

Open
tusharkgerg opened this issue Dec 17, 2017 · 5 comments

Comments

@tusharkgerg
Copy link

Python 3.4
tensorflow 1.4

I have copied the code exactly as in example, and getting the following error.

Here is surrounding code where the error occurred:
model = tf.estimator.Estimator(model_fn)

Define the input function for training

input_fn = tf.estimator.inputs.numpy_input_fn(
    x={'features': mnist.train.images}, y=mnist.train.labels,
    batch_size=batch_size, num_epochs=None, shuffle=True)
# Train the Model
model.train(input_fn, steps=num_steps)

The error:

File "/Users/tushar/workspace/python/impact/cnn.py", line 123, in run
model.train(input_fn, steps=num_steps)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/estimator/estimator.py", line 302, in train
loss = self._train_model(input_fn, hooks, saving_listeners)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/estimator/estimator.py", line 708, in _train_model
input_fn, model_fn_lib.ModeKeys.TRAIN)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/estimator/estimator.py", line 577, in _get_features_and_labels_from_input_fn
result = self._call_input_fn(input_fn, mode)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/estimator/estimator.py", line 663, in _call_input_fn
return input_fn(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/estimator/inputs/numpy_io.py", line 109, in input_fn
if len(set(v.shape[0] for v in ordered_dict_x.values())) != 1:
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/estimator/inputs/numpy_io.py", line 109, in
if len(set(v.shape[0] for v in ordered_dict_x.values())) != 1:
AttributeError: 'list' object has no attribute 'shape'

I tried the same with my own input data and made sure to convert them to numpy arrays, and then tried with the same tutorial mnist data as well. In both cases, getting this error. Unable to figure out why this error occurred with the mnist data as the code is the same as in given example.

Please help, what am I missing?

@gnazareths
Copy link

Following

@hidingtutorials
Copy link

I am having the same issue :(

@momja
Copy link

momja commented Feb 24, 2018

I am also facing this problem. Any solutions since initially posting?

@akalani
Copy link

akalani commented Mar 1, 2018

I am pretty sure this is because you are feeding Python array instead of Numpy array. Convert to Numpy array and then pass to tf.estimator.inputs.numpy_input_fn.

@RostamDin
Copy link

I found the answer here ->https://stackoverflow.com/questions/57537474/how-to-fix-attributeerror-list-object-has-no-attribute-shape-error-in-pyt

Try using
nmodel.predict(x_test)
instead of
nmodel.predict([x_test])
(remove the brackets).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants