SSD-Tensorflow icon indicating copy to clipboard operation
SSD-Tensorflow copied to clipboard

TypeError: Can not convert a tuple into a Tensor or Operation.

Open kimna4 opened this issue 7 years ago • 15 comments

Hello, I am new to tensorflow.

I 've trained voc 2007 dataset (without 2012) by following guide. The problem is when I try to run 'eval_ssd_network.py' Below error message is printed INFO:tensorflow:Evaluating ./logs/model.ckpt-621 Traceback (most recent call last): File "/home/kimna/TensorflowWorkspace/SSD-Tensorflow-master/eval_ssd_network.py", line 346, in tf.app.run() File "/home/kimna/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "/home/kimna/TensorflowWorkspace/SSD-Tensorflow-master/eval_ssd_network.py", line 320, in main session_config=config) File "/home/kimna/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/slim/python/slim/evaluation.py", line 207, in evaluate_once config=session_config) File "/home/kimna/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/evaluation.py", line 182, in _evaluate_once eval_step_value = _get_latest_eval_step_value(eval_ops) File "/home/kimna/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/evaluation.py", line 75, in _get_latest_eval_step_value with ops.control_dependencies(update_ops): File "/home/kimna/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 4284, in control_dependencies return get_default_graph().control_dependencies(control_inputs) File "/home/kimna/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3997, in control_dependencies c = self.as_graph_element(c) File "/home/kimna/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3015, in as_graph_element return self._as_graph_element_locked(obj, allow_tensor, allow_operation) File "/home/kimna/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3104, in _as_graph_element_locked types_str)) TypeError: Can not convert a tuple into a Tensor or Operation.

=========================================================================== I hope to tell you all of parameters for generating tfrecords and train.

tf_convert_data.py --dataset_name=pascalvoc --dataset_dir=.Datasets/VOC2007/ --output_name=voc_2007_train --output_dir=./tfrecords

train_ssd_network.py --train_dir=./logs/ --dataset_dir=./tfrecords --dataset_name=pascalvoc_2007 --dataset_split_name=train --model_name=ssd_300_vgg --checkpoint_path=./checkpoints/ssd_300_vgg.ckpt --save_summaries_secs=60 --save_interval_secs=600 --weight_decay=0.0005 --optimizer=adam --learning_rate=0.001 --batch_size=16

eval_ssd_network.py --eval_dir=./logs/eval --dataset_dir=./tfrecords --dataset_name=pascalvoc_2007 --dataset_split_name=train --model_name=ssd_300_vgg --checkpoint_path=./logs/ --batch_size=1

=========================================================================== I don't use voc test images and voc 2012 datasets. Since, I just want to know how to run the SSD-Tensorflow and I will use my own dataset.

What is the my problem? thankyou in advance

kimna4 avatar Oct 24 '17 11:10 kimna4

I met the same problem today, and my python version is 3.5, my tensorflow version is tensorflow-gpu (1.4.0rc0), who can help me about this problem?

w5688414 avatar Nov 06 '17 09:11 w5688414

I use my own voc 2007 test datasets, and I only use two classes, person and car. the error is below whsyxt@whsyxt:~/Downloads/SSD-Tensorflow$ python3 eval_ssd_network.py \

--eval_dir=${EVAL_DIR} \
--dataset_dir=${DATASET_DIR} \
--dataset_name=pascalvoc_2007 \
--dataset_split_name=test \
--model_name=ssd_300_vgg \
--checkpoint_path=${CHECKPOINT_PATH} \
--batch_size=1

WARNING:tensorflow:From eval_ssd_network.py:113: get_or_create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version. Instructions for updating: Please switch to tf.train.get_or_create_global_step

===========================================================================

Training | Evaluation flags:

===========================================================================

{'batch_size': 1, 'checkpoint_path': './checkpoints/VGG_VOC0712_SSD_300x300_ft_iter_120000.ckpt', 'dataset_dir': 'tfrecords_test_v3', 'dataset_name': 'pascalvoc_2007', 'dataset_split_name': 'test', 'eval_dir': 'logs/', 'eval_image_size': None, 'eval_resize': 4, 'gpu_memory_fraction': 0.1, 'keep_top_k': 200, 'master': '', 'matching_threshold': 0.5, 'max_num_batches': None, 'model_name': 'ssd_300_vgg', 'moving_average_decay': None, 'nms_threshold': 0.45, 'num_classes': 21, 'num_preprocessing_threads': 4, 'preprocessing_name': None, 'remove_difficult': True, 'select_threshold': 0.01, 'select_top_k': 400, 'wait_for_checkpoints': False}

===========================================================================

SSD net parameters:

===========================================================================

{'anchor_offset': 0.5, 'anchor_ratios': [[2, 0.5], [2, 0.5, 3, 0.3333333333333333], [2, 0.5, 3, 0.3333333333333333], [2, 0.5, 3, 0.3333333333333333], [2, 0.5], [2, 0.5]], 'anchor_size_bounds': [0.15, 0.9], 'anchor_sizes': [(21.0, 45.0), (45.0, 99.0), (99.0, 153.0), (153.0, 207.0), (207.0, 261.0), (261.0, 315.0)], 'anchor_steps': [8, 16, 32, 64, 100, 300], 'feat_layers': ['block4', 'block7', 'block8', 'block9', 'block10', 'block11'], 'feat_shapes': [(38, 38), (19, 19), (10, 10), (5, 5), (3, 3), (1, 1)], 'img_shape': (300, 300), 'no_annotation_label': 21, 'normalizations': [20, -1, -1, -1, -1, -1], 'num_classes': 21, 'prior_scaling': [0.1, 0.1, 0.2, 0.2]}

===========================================================================

Training | Evaluation dataset files:

===========================================================================

['tfrecords_test_v3/voc_2007_test_000.tfrecord', 'tfrecords_test_v3/voc_2007_test_001.tfrecord', 'tfrecords_test_v3/voc_2007_test_002.tfrecord', 'tfrecords_test_v3/voc_2007_test_003.tfrecord', 'tfrecords_test_v3/voc_2007_test_004.tfrecord', 'tfrecords_test_v3/voc_2007_test_005.tfrecord']

INFO:tensorflow:Evaluating ./checkpoints/VGG_VOC0712_SSD_300x300_ft_iter_120000.ckpt Traceback (most recent call last): File "eval_ssd_network.py", line 346, in tf.app.run() File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "eval_ssd_network.py", line 320, in main session_config=config) File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/slim/python/slim/evaluation.py", line 207, in evaluate_once config=session_config) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/evaluation.py", line 182, in _evaluate_once eval_step_value = _get_latest_eval_step_value(eval_ops) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/evaluation.py", line 75, in _get_latest_eval_step_value with ops.control_dependencies(update_ops): File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 4304, in control_dependencies return get_default_graph().control_dependencies(control_inputs) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 4017, in control_dependencies c = self.as_graph_element(c) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 3035, 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 3124, in _as_graph_element_locked types_str)) TypeError: Can not convert a tuple into a Tensor or Operation

w5688414 avatar Nov 06 '17 09:11 w5688414

I got the same above error mentioned by @w5688414. Here are my work env: virtualenv 15.1.0 python 2.7.10 tensorflow 1.4.0

zhihongzeng2002 avatar Nov 07 '17 22:11 zhihongzeng2002

in eval_ssd_network.py, calling slim.evaluation.evaluation_loop with

eval_op=flatten(list(names_to_updates.values())),

don't forget to import flatten with from compiler.ast import flatten

CharlesShang avatar Nov 08 '17 16:11 CharlesShang

@CharlesShang thanks for your response. I tried your idea. I got the same as before.

zhihongzeng2002 avatar Nov 08 '17 16:11 zhihongzeng2002

I got the same error. use the function

def flatten(x): 
         result = [] 
         for el in x: 
              if isinstance(el, tuple): 
                    result.extend(flatten(el))
              else: 
                    result.append(el) 
          return result

in eval_op=flatten(list(names_to_updates.values())),, it works for me.

zhaowanqing avatar Nov 13 '17 13:11 zhaowanqing

Here is my solution: In eval_ssd_network.py Line 319: eval_op = flatten(list(name_to_updates.values())), LIne 338: eval_op =flatten(list(names_to_updates.values())),

@zhaowanqing: the function in your comment is almost same as the one in "from compiler.ast import flatten". Here are the code in ast.py def flatten(seq): l = [] for elt in seq: t = type(elt) if t is tuple or t is list: for elt2 in flatten(elt): l.append(elt2) else: l.append(elt) return l

zhihongzeng2002 avatar Nov 13 '17 20:11 zhihongzeng2002

@zhaowanqing thank you for your sharing, I have solved my problem, my commandline is below: DATASET_DIR=tfrecords_test_v3 EVAL_DIR=logs/ CHECKPOINT_PATH=./checkpoints/VGG_VOC0712_SSD_300x300_ft_iter_120000.ckpt python3 eval_ssd_network.py \ --eval_dir=${EVAL_DIR} \ --dataset_dir=${DATASET_DIR} \ --dataset_name=pascalvoc_2007 \ --dataset_split_name=test \ --model_name=ssd_300_vgg \ --checkpoint_path=${CHECKPOINT_PATH} \ --batch_size=1 it works fine

w5688414 avatar Nov 14 '17 05:11 w5688414

@zhaowanqing thank you.it works for me. I got the same error. use the function

def flatten(x): result = [] for el in x: if isinstance(el, tuple): result.extend(flatten(el)) else: result.append(el) return result in eval_op=flatten(list(names_to_updates.values())),, it works for me.

baolinhu avatar Jan 11 '18 09:01 baolinhu

Here is my solution: In eval_ssd_network.py Line 319: eval_op = flatten(list(name_to_updates.values())), LIne 338: eval_op =flatten(list(names_to_updates.values())),

@zhaowanqing: the function in your comment is almost same as the one in "from compiler.ast import flatten". Here are the code in ast.py def flatten(seq): l = [] for elt in seq: t = type(elt) if t is tuple or t is list: for elt2 in flatten(elt): l.append(elt2) else: l.append(elt) return l

Here is my solution: In eval_ssd_network.py Line 319: eval_op = flatten(list(name_to_updates.values())), LIne 338: eval_op =flatten(list(names_to_updates.values())),

@zhaowanqing: the function in your comment is almost same as the one in "from compiler.ast import flatten". Here are the code in ast.py def flatten(seq): l = [] for elt in seq: t = type(elt) if t is tuple or t is list: for elt2 in flatten(elt): l.append(elt2) else: l.append(elt) return l

Line 319: eval_op = flatten(list(name_to_updates.values())), modify this to Line 319: eval_op = flatten(list(names_to_updates.values())),

Falmi avatar Nov 02 '18 09:11 Falmi

I have add the function flatten and modified the code in line 319 and line 338, But now, I got another error like this: ** TypeError: Tensor objects are only iterable when eager execution is enabled. To iterate over this tensor use tf.map_fn. ** how can i solve it

wangxianrui avatar Dec 06 '18 09:12 wangxianrui

@wangxianrui what's your environ?

Hizhaoyuan avatar Dec 20 '18 11:12 Hizhaoyuan

I have add the function flatten and modified the code in line 319 and line 338, But now, I got another error like this:

ERROR:tensorflow:================================== Object was never used (type <class 'tensorflow.python.framework.ops.Tensor'>): <tf.Tensor 'report_uninitialized_variables_1/boolean_mask/GatherV2:0' shape=(?,) dtype=string> If you want to mark it as used call its "mark_used()" method.

How to solve this problem???? my tf version is 1.12.0(Gpu) @w5688414 @zhaowanqing @zhihongzeng2002

Sulince avatar Mar 06 '19 13:03 Sulince

good

4869conan avatar Oct 08 '19 10:10 4869conan

I have add the function flatten and modified the code in line 319 and line 338, But now, I got another error like this:

ERROR:tensorflow:================================== Object was never used (type <class 'tensorflow.python.framework.ops.Tensor'>): <tf.Tensor 'report_uninitialized_variables_1/boolean_mask/GatherV2:0' shape=(?,) dtype=string> If you want to mark it as used call its "mark_used()" method.

How to solve this problem???? my tf version is 1.12.0(Gpu) @w5688414 @zhaowanqing @zhihongzeng2002

there are two lines, you only change one ,then it threw the bug like yours

weixinxu666 avatar Jan 22 '20 14:01 weixinxu666