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)
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?
Following
I am having the same issue :(
I am also facing this problem. Any solutions since initially posting?
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.
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).
Most helpful comment
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.