models icon indicating copy to clipboard operation
models copied to clipboard

ValueError: Tensor conversion requested dtype string for Tensor with dtype float32: 'Tensor("arg0:0", shape=(), dtype=float32, device=/device:CPU:0)'

Open manu1a opened this issue 8 years ago • 38 comments

Please go to Stack Overflow for help and support:

http://stackoverflow.com/questions/tagged/tensorflow

Also, please understand that many of the models included in this repository are experimental and research-style code. If you open a GitHub issue, here is our policy:

  1. It must be a bug, a feature request, or a significant problem with documentation (for small docs fixes please send a PR instead).
  2. The form below must be filled out.

Here's why we have that policy: TensorFlow developers respond to issues. We want to focus on work that benefits the whole community, e.g., fixing bugs and adding features. Support only helps individuals. GitHub also notifies thousands of people when issues are filed. We want them to see you communicating an interesting problem, rather than being redirected to Stack Overflow.


System information

  • What is the top-level directory of the model you are using: /models/research/object_detection
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04 LTS
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): Tensorflow 1.9.0
  • Bazel version (if compiling from source):
  • CUDA/cuDNN version: none, CPU version
  • GPU model and memory: none
  • Exact command to reproduce: python model_main.py --logtostderr --model_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_pets.config

You can collect some of this information using our environment capture script:

https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh

You can obtain the TensorFlow version with

python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"

Describe the problem

It is a bug. I am trying to train my model using model_main.py in the object detection folder. I have tf_record, images and other data setup. I get this error when I run both model_main.py and train.py. Please help me train the model.

Source code / logs

/models/research/object_detection$ python model_main.py --logtostderr --model_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_pets.config WARNING:tensorflow:Estimator's model_fn (<function model_fn at 0x7f1bc431f6e0>) includes params argument, but params are not passed to Estimator. WARNING:tensorflow:num_readers has been reduced to 0 to match input file shards. Traceback (most recent call last): File "model_main.py", line 101, in tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 125, in run _sys.exit(main(argv)) File "model_main.py", line 97, in main tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0]) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/training.py", line 447, in train_and_evaluate return executor.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/training.py", line 531, in run return self.run_local() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/training.py", line 669, in run_local hooks=train_hooks) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 366, in train loss = self._train_model(input_fn, hooks, saving_listeners) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 1119, in _train_model return self._train_model_default(input_fn, hooks, saving_listeners) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 1129, in _train_model_default input_fn, model_fn_lib.ModeKeys.TRAIN)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 985, in _get_features_and_labels_from_input_fn result = self._call_input_fn(input_fn, mode) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 1074, in _call_input_fn return input_fn(**kwargs) File "/home/kumar/Data/rec/Tesnorflow_Beginners/models/research/object_detection/inputs.py", line 412, in _train_input_fn batch_size=params['batch_size'] if params else train_config.batch_size) File "/home/kumar/Data/rec/Tesnorflow_Beginners/models/research/object_detection/builders/dataset_builder.py", line 134, in build config.input_path[:], input_reader_config) File "/home/kumar/Data/rec/Tesnorflow_Beginners/models/research/object_detection/builders/dataset_builder.py", line 80, in read_dataset sloppy=config.shuffle)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 1002, in apply dataset = transformation_func(self) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/data/python/ops/interleave_ops.py", line 88, in _apply_fn buffer_output_elements, prefetch_input_elements) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/data/ops/readers.py", line 130, in init cycle_length, block_length) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 1988, in init super(InterleaveDataset, self).init(input_dataset, map_func) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 1957, in init self._map_func.add_to_graph(ops.get_default_graph()) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/function.py", line 475, in add_to_graph self._create_definition_if_needed() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/function.py", line 331, in _create_definition_if_needed self._create_definition_if_needed_impl() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/function.py", line 340, in _create_definition_if_needed_impl self._capture_by_value, self._caller_device) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/function.py", line 804, in func_graph_from_py_func outputs = func(*func_graph.inputs) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 1945, in tf_map_func dataset = map_func(nested_args) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/data/ops/readers.py", line 196, in init filenames = ops.convert_to_tensor(filenames, dtype=dtypes.string) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1011, in convert_to_tensor as_ref=False) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1107, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 944, in _TensorTensorConversionFunction (dtype.name, t.dtype.name, str(t))) ValueError: Tensor conversion requested dtype string for Tensor with dtype float32: 'Tensor("arg0:0", shape=(), dtype=float32, device=/device:CPU:0)'

manu1a avatar Jul 26 '18 12:07 manu1a

did you fixed this proplem,i got the same error

baiboat avatar Jul 27 '18 06:07 baiboat

Not yet

manu1a avatar Jul 27 '18 07:07 manu1a

i fixed my error,because i forgot to put my .record files under object_detection/data/.

baiboat avatar Jul 27 '18 09:07 baiboat

any solution? same here. For me it only occurs in their pet detector tutorial.

muchensthughs avatar Jul 27 '18 19:07 muchensthughs

Hi @manu1a -- it is hard to help you debug this without further information. Can you clarify all of the steps you took before running model_main? Where is the data in question, and how was that data created? Thanks.

karmel avatar Jul 27 '18 20:07 karmel

Hi @karmel , sorry for my late response. I created the tf record using the script provided by the dataset tools folder in the tensorflow object detection API. This problem is solved now by tweaking the folder structure for training data, something similar suggested by @baiboat . Thank you.

manu1a avatar Jul 31 '18 07:07 manu1a

Please let me know if the issue can be closed.

manu1a avatar Jul 31 '18 07:07 manu1a

I placed my .records file in object_detection/data/ but this did not solve the problem

jayshah19949596 avatar Aug 02 '18 04:08 jayshah19949596

Matching the number of evaluation samples in config file with the actual number of evaluation samples fixed my problem. The data is participated into 10 shards while I was only using one shard for training and evaluation.

muchensthughs avatar Aug 02 '18 05:08 muchensthughs

Yes, I figured out that I the number in the config file was not matching with my records file. Thanks :)

jayshah19949596 avatar Aug 02 '18 05:08 jayshah19949596

I have the same error! my config file as fllow: train_input_reader: { tf_record_input_reader { input_path: "/data/antispam/bmb-python/pynotebook/tf-model/research/object_detection/data/pet_faces_train.record-?????-of-00100" } label_map_path: "/data/antispam/bmb-python/pynotebook/tf-model/research/object_detection/data/pet_label_map.pbtxt" }

eval_config: { num_examples: 8000

Note: The below line limits the evaluation process to 10 evaluations.

Remove the below line to evaluate indefinitely.

max_evals: 10 }

eval_input_reader: { tf_record_input_reader { input_path: "/data/antispam/bmb-python/pynotebook/tf-model/research/object_detection/data/pet_faces_val.record-?????-of-00010" } label_map_path: "/data/antispam/bmb-python/pynotebook/tf-model/research/object_detection/data/pet_faces_label_map.pbtxt" shuffle: false num_readers: 1 }

Is the config wrong?

mingkin avatar Aug 13 '18 09:08 mingkin

Is .record file that you have mentioned same as .tfrecord or different? Because after running generate_tfrecords.py I am getting two files. First "train.tfrecord" and second "eval.tfrecord".

codinesh1795 avatar Aug 15 '18 08:08 codinesh1795

one of the reasons for this error is that the path to the train or test tfrecord is not correct. It is not necessary to maintain the exact directory structure as long as the file paths are correct in the pipeline.config file

Manish-rai21bit avatar Aug 15 '18 17:08 Manish-rai21bit

I solved it by changing the default 'mscoco_train.record-????-of-00100' to 'coco_train.record-????-of-00100' because the names are different for me when I generated tf records

junweima avatar Aug 27 '18 19:08 junweima

i m confused ,what do u mean by 10 shard please reply asap @muchensthughs

moinkhan3012 avatar Sep 25 '18 13:09 moinkhan3012

i m confused ,what do u mean by 10 shard please reply asap @muchensthughs

you can try changing the num_examples of eval_config in configuration file to the actual number of evaluation samples you have. The sample code is supposed to be used on 10 shards (pet_faces_val.record-00001-of-00010, pet_faces_val.record-00002-of-00010, etc.) but I was only using one shard so the number of evaluation examples did not match.

muchensthughs avatar Sep 25 '18 17:09 muchensthughs

i had already change the num_example to number of images i have in my test images directory(for custom object) .thank you, but didnt work for me .

moinkhan3012 avatar Sep 25 '18 19:09 moinkhan3012

Any other sloution .how do you @jayshah19949596 .solve the problem can u elaborate it plz

moinkhan3012 avatar Sep 29 '18 19:09 moinkhan3012

@baiboat's comment pointed me in the right direction. Specifically, the path to your train.record file needs to be correct in your .config file.

This could be improved by a more helpful error message. In my case, the instructions I was following in this repository have the .config file being written before they recommend a specific directory structure; following the recommendation then requires to go back and change the .config file, so perhaps the instructions should be reordered avoid needing to go back and fix a completed step.

bradknox avatar Oct 03 '18 17:10 bradknox

Had this issue using but solved it by changing the paths in my config file from exact paths to relative paths. WARNING:tensorflow:num_readers has been reduced to 0 to match input file shards. means your paths aren't passing a path pattern matching function.

burrbank avatar Oct 06 '18 22:10 burrbank