Reputation: 11
I‘m studying the tensoflow, and want to test the example of slim. When I command ./scripts/train_lenet_on_mnist.sh, The program run to eval_image_classifier give a Type Error, The Error information as follows:
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so.8.0 locally
INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:Evaluating /tmp/lenet-model/model.ckpt-20002
INFO:tensorflow:Starting evaluation at 2016-11-09-02:55:57
I tensorflow/core/common_runtime/gpu/gpu_device.cc:951] Found device 0 with properties:
name: Quadro K5000
major: 3 minor: 0 memoryClockRate (GHz) 0.7055
pciBusID 0000:03:00.0
Total memory: 3.94GiB
Free memory: 3.61GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:972] DMA: 0
I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] 0: Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Quadro K5000, pci bus id: 0000:03:00.0)
INFO:tensorflow:Executing eval ops
INFO:tensorflow:Executing eval_op 1/100
INFO:tensorflow:Error reported to Coordinator: <class 'TypeError'>, Fetch argument dict_values([<tf.Tensor 'accuracy/update_op:0' shape=() dtype=float32>, <tf.Tensor 'recall_at_5/update_op:0' shape=() dtype=float32>]) has invalid type <class 'dict_values'>, must be a string or Tensor. (Can not convert a dict_values into a Tensor or Operation.)
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 218, in init
fetch, allow_tensor=True, allow_operation=True))
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2455, in as_graph_element
return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2547, in _as_graph_element_locked
% (type(obj).name, types_str))
TypeError: Can not convert a dict_values into a Tensor or Operation.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "eval_image_classifier.py", line 191, in <module>
tf.app.run()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 30, in run
sys.exit(main(sys.argv[:1] + flags_passthrough))
File "eval_image_classifier.py", line 187, in main
variables_to_restore=variables_to_restore)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/slim/python/slim/evaluation.py", line 359, in evaluate_once
global_step=global_step)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/slim/python/slim/evaluation.py", line 260, in evaluation
sess.run(eval_op, eval_op_feed_dict)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 717, in run
run_metadata_ptr)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 902, in _run
fetch_handler = _FetchHandler(self._graph, fetches, feed_dict_string)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 358, in init
self._fetch_mapper = _FetchMapper.for_fetch(fetches)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 189, in for_fetch
return _ElementFetchMapper(fetches, contraction_fn)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 222, in init
% (fetch, type(fetch), str(e)))
TypeError: Fetch argument dict_values([<tf.Tensor 'accuracy/update_op:0' shape=() dtype=float32>, <tf.Tensor 'recall_at_5/update_op:0' shape=() dtype=float32>]) has invalid type <class 'dict_values'>, must be a string or Tensor. (Can not convert a dict_values into a Tensor or Operation.)
I don't know what happened to the program, I didnot revised any code, just download the code package from github, and for datadownload and train, which give correct result.Is there any help me? I am waiting online. Thanks
Upvotes: 0
Views: 1551
Reputation: 11
The problem is the compatible of python2
and python3
. As I used python3
for interpretation, but the the Keys From a Dictionary is different from python2
and python3
.
In Python2
, simply calling keys()
on a dictionary object will return what you expect, however, in Python3
, keys()
no longer returns a list
, but a view object, so the TypeError can be avoided and compatibility can be maintained by simply converting the dict_keys
object into a list which can then be indexed as normal in both Python2
and Python3
.
I edited the eval_image_classifier
using eval_op=list(names_to_updates.values())
, then it can work perfectly.
Upvotes: 1
Reputation: 725
The other python3 change for eval_image_classifier.py is
for name, value in names_to_values.iteritems():
to
for name, value in names_to_values.items():
Upvotes: 0