models icon indicating copy to clipboard operation
models copied to clipboard

object_detection train.py ValueError Tensor conversion

Open normandra opened this issue 8 years ago • 15 comments

System information

  • What is the top-level directory of the model you are using(/home/models/research/object_detection):
  • Have I written custom code (only the one to generate TFRecords):
  • OS Platform and Distribution (Linux Ubuntu 18.04):
  • TensorFlow installed from (pip binary):
  • TensorFlow version (1.8.0):
  • Bazel version (N/A):
  • CUDA/cuDNN version(N/A):
  • GPU model and memory(N/A):
  • Exact command to reproduce(python train.py --logtostderr --train_dir=./models/train --pipeline_config_path=ssd_mobilenet_v2_coco.config ):

Describe the problem

I followed the use your own data template from the g3doc using the following code

It seems that the filename is expected as a float32? or its being used as an input?

Source code / logs

`def create_tf_example(example):

#Frame,Label,xmin,xmax,ymin,ymax
#0      1       2   3   4   5

# TODO(user): Populate the following variables from your example.
height = 960  # Image height
width = 540  # Image width
filename = example[0]  # Filename of the image. Empty if image is not from file
filename = filename.encode()



encoded_image_data = None  # Encoded image bytes

with tf.gfile.GFile('GELABELT_BBox/SCHILD/BILDER_149/'+example[0],'rb') as fid:
    encoded_image_data = fid.read()

image_format = b'jpg'  # b'jpeg' or b'png'

# List of normalized left x coordinates in bounding box (1 per box)
xmins = [int(example[2])/width]
xmaxs = [int(example[3])/width]  # List of normalized right x coordinates in bounding box
# (1 per box)
# List of normalized top y coordinates in bounding box (1 per box)
ymins = [int(example[4])/height]
ymaxs = [int(example[5])/height]  # List of normalized bottom y coordinates in bounding box
# (1 per box)
classes_text = [example[1].encode()]  # List of string class name of bounding box (1 per box)
classes = [1]  # List of integer class id of bounding box (1 per box)

tf_example = tf.train.Example(features=tf.train.Features(feature={
    'image/height': dataset_util.int64_feature(height),
    'image/width': dataset_util.int64_feature(width),
    'image/filename': dataset_util.bytes_feature(filename),
    'image/source_id': dataset_util.bytes_feature(filename),
    'image/encoded': dataset_util.bytes_feature(encoded_image_data),
    'image/format': dataset_util.bytes_feature(image_format),
    'image/object/bbox/xmin': dataset_util.float_list_feature(xmins),
    'image/object/bbox/xmax': dataset_util.float_list_feature(xmaxs),
    'image/object/bbox/ymin': dataset_util.float_list_feature(ymins),
    'image/object/bbox/ymax': dataset_util.float_list_feature(ymaxs),
    'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
    'image/object/class/label': dataset_util.int64_list_feature(classes),
}))
return tf_example`

and the trace:

WARNING:tensorflow:From /home/mno/Desktop/tf_detection/models/research/object_detection/trainer.py:260: 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.create_global_step WARNING:tensorflow:num_readers has been reduced to 0 to match input file shards. Traceback (most recent call last): File "train.py", line 184, in <module> tf.app.run() File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run _sys.exit(main(argv)) File "train.py", line 180, in main graph_hook_fn=graph_rewriter_fn) File "/home/mno/Desktop/tf_detection/models/research/object_detection/trainer.py", line 274, in train train_config.prefetch_queue_capacity, data_augmentation_options) File "/home/mno/Desktop/tf_detection/models/research/object_detection/trainer.py", line 59, in create_input_queue tensor_dict = create_tensor_dict_fn() File "train.py", line 121, in get_next dataset_builder.build(config)).get_next() File "/home/mno/Desktop/tf_detection/models/research/object_detection/builders/dataset_builder.py", line 186, in build process_fn, config.input_path[:], input_reader_config) File "/home/mno/Desktop/tf_detection/models/research/object_detection/utils/dataset_util.py", line 141, in read_dataset sloppy=config.shuffle)) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 973, in apply dataset = transformation_func(self) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/contrib/data/python/ops/interleave_ops.py", line 76, in _apply_fn buffer_output_elements, prefetch_input_elements) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/data/ops/readers.py", line 130, in __init__ cycle_length, block_length) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1959, in __init__ super(InterleaveDataset, self).__init__(input_dataset, map_func) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1928, in __init__ self._map_func.add_to_graph(ops.get_default_graph()) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 484, in add_to_graph self._create_definition_if_needed() File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 319, in _create_definition_if_needed self._create_definition_if_needed_impl() File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 336, in _create_definition_if_needed_impl outputs = self._func(*inputs) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1916, in tf_map_func dataset = map_func(nested_args) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/data/ops/readers.py", line 196, in __init__ filenames = ops.convert_to_tensor(filenames, dtype=dtypes.string) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1014, in convert_to_tensor as_ref=False) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1104, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/home/mno/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 947, 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)'

normandra avatar Jun 07 '18 15:06 normandra

it seems that the issue was on my side, I was able to get this running with a different dataset.

normandra avatar Jun 08 '18 09:06 normandra

Hi @normandra, do you know what was the problem with your data?

LuisFernandoBecker avatar Jun 08 '18 16:06 LuisFernandoBecker

@normandra same error too. did you fix the issue?

hellottt20012001 avatar Jun 10 '18 10:06 hellottt20012001

@normandra got the same error while using faster_rcnn_resnet101_kitti model. how to fix this?

lYesterdaYl avatar Jun 10 '18 17:06 lYesterdaYl

I checked again, It's possible that the problem didn't lie within my data set but the fact that I moved the train.py outside of its original folder making it using the wrong utils.

normandra avatar Jun 11 '18 14:06 normandra

same error here..

ontheway16 avatar Jun 12 '18 09:06 ontheway16

The pipeline.config needs to have "pet_faces_train.record*" and "pet_faces_val.record*" for the input paths since the new outputs of the create_pet_tf_record.py script now creates batches of files.

After making that change everything works.

david-csnmedia avatar Jun 13 '18 20:06 david-csnmedia

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

can anyone explain me why i m getting this error? how do i remove it?

moinkhan3012 avatar Sep 25 '18 17:09 moinkhan3012

@moinkhan3012 - I face the same error. Did u resolve it?

zishanahmed08 avatar Oct 16 '18 12:10 zishanahmed08

@moinkhan3012 The same error, Did you fix it?

lan2720 avatar Oct 18 '18 10:10 lan2720

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

my config is based on https://github.com/tensorflow/models/blob/master/research/object_detection/samples/configs/faster_rcnn_nas_coco.config

input_path: "PATH_TO_BE_CONFIGURED/mscoco_train.record-?????-of-00100" should be a path to the train or eval tf records make sure you are removing -?????-of-00100

Azadehkhojandi avatar Oct 31 '18 11:10 Azadehkhojandi

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

my config is based on https://github.com/tensorflow/models/blob/master/research/object_detection/samples/configs/faster_rcnn_nas_coco.config

input_path: "PATH_TO_BE_CONFIGURED/mscoco_train.record-?????-of-00100" should be a path to the train or eval tf records make sure you are removing -?????-of-00100

works for me thx

oblank avatar Mar 13 '19 10:03 oblank

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

my config is based on https://github.com/tensorflow/models/blob/master/research/object_detection/samples/configs/faster_rcnn_nas_coco.config

input_path: "PATH_TO_BE_CONFIGURED/mscoco_train.record-?????-of-00100" should be a path to the train or eval tf records make sure you are removing -?????-of-00100

thank you!!

b-tupiti avatar Mar 30 '19 01:03 b-tupiti

The pipeline.config needs to have "pet_faces_train.record*" and "pet_faces_val.record*" for the input paths since the new outputs of the create_pet_tf_record.py script now creates batches of files.

After making that change everything works.

@david-csnmedia have you seen this happening when num_epochs is set to 1 as well? I am trying to figure out how to effectively modify filename_dataset = filename_dataset.repeat(config.num_epochs or None) the following function in object_detection/builders/dataset_builder.py in evaluation mode.

def read_dataset(file_read_func, input_files, config):
  """Reads a dataset, and handles repetition and shuffling.

  Args:
    file_read_func: Function to use in tf.contrib.data.parallel_interleave, to
      read every individual file into a tf.data.Dataset.
    input_files: A list of file paths to read.
    config: A input_reader_builder.InputReader object.

  Returns:
    A tf.data.Dataset of (undecoded) tf-records based on config.
  """
  # Shard, shuffle, and read files.
  filenames = tf.gfile.Glob(input_files)
  num_readers = config.num_readers
  if num_readers > len(filenames):
    num_readers = len(filenames)
    tf.logging.warning('num_readers has been reduced to %d to match input file '
                       'shards.' % num_readers)
  filename_dataset = tf.data.Dataset.from_tensor_slices(filenames)
  if config.shuffle:
    filename_dataset = filename_dataset.shuffle(
        config.filenames_shuffle_buffer_size)
  elif num_readers > 1:
    tf.logging.warning('`shuffle` is false, but the input data stream is '
                       'still slightly shuffled since `num_readers` > 1.')
  filename_dataset = filename_dataset.repeat(config.num_epochs or None)
  records_dataset = filename_dataset.apply(
      tf.contrib.data.parallel_interleave(
          file_read_func,
          cycle_length=num_readers,
          block_length=config.read_block_length,
          sloppy=config.shuffle))
  if config.shuffle:
    records_dataset = records_dataset.shuffle(config.shuffle_buffer_size)
  return records_dataset

tispratik avatar Apr 18 '20 19:04 tispratik

I added the following piece of code to the read_dataset function as I noticed that num_epochs is not set during evaluation.

  if config.num_epochs == 0:
    filename_dataset = filename_dataset.repeat(1)
  else:
    filename_dataset = filename_dataset.repeat(config.num_epochs or None)

But then I am getting a new error after evaluation.

WARNING:tensorflow:An OutOfRangeError or StopIteration exception is raised by the code in FinalOpsHook. This typically means the Ops running by the FinalOpsHook have a dependency back to some input source, w$
ich should not happen. For example, for metrics in tf.estimator.Estimator, all metrics functions return two Ops: `value_op` and  `update_op`. Estimator.evaluate calls the `update_op` for each batch of the dat
a in input source and, once it is exhausted, it call the `value_op` to get the metric values. The `value_op` here should have dependency back to variables reading only, rather than reading another batch from
input. Otherwise, the `value_op`, executed by `FinalOpsHook`, triggers another data reading, which ends OutOfRangeError/StopIteration. Please fix that.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1278, in _do_call
    return fn(*args)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1263, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1350, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.OutOfRangeError: End of sequence
         [[Node: IteratorGetNext = IteratorGetNext[output_shapes=[[1], [1,300,300,3], [1,?,?,3], [1,3], [1,100], [1,100,4], [1,100,22], [1,100], [1,100], [1,100], [1]], output_types=[DT_INT32, DT_FLOAT, DT_UI
NT8, DT_INT32, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_INT32, DT_BOOL, DT_FLOAT, DT_INT32], _device="/job:localhost/replica:0/task:0/device:CPU:0"](Iterator)]]

During handling of the above exception, another exception occurred:

Anyone has an idea how to handle this?

tispratik avatar Apr 18 '20 22:04 tispratik