svpino / tf_object_detection_cm

Confusion Matrix in Object Detection with TensorFlow
78 stars 36 forks source link

Fails with runtime error: Failing to parse input data #1

Closed nekulkarni closed 6 years ago

nekulkarni commented 6 years ago

I followed the following example given in the README file, while using the correct paths to detection.record and label_map.pbtxt files:

python confusion_matrix.py --detections_record=testing_detections.record --label_map=label_map.pbtxt

However I run into an error:

Traceback (most recent call last):
  File "neeraj_confusion_matrix.py", line 133, in <module>
    tf.app.run(main)
  File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "neeraj_confusion_matrix.py", line 128, in main
    confusion_matrix = process_detections(FLAGS.detections_record, categories)
  File "neeraj_confusion_matrix.py", line 45, in process_detections
    decoded_dict = data_parser.parse(example)
  File "/home/ubuntu/tensorflow/models/research/object_detection/metrics/tf_example_parser.py", line 153, in parse
    results_dict[key] = parser.parse(tf_example)
  File "/home/ubuntu/tensorflow/models/research/object_detection/metrics/tf_example_parser.py", line 49, in parse
    self.field_name].HasField("bytes_list") else None
TypeError: sequence item 0: expected str instance, bytes found

I'm using python3.6 and tensorflow r1.10.

Why doesn't it work?

svpino commented 6 years ago

Hi Nkulkarni,

I found this issue as well. The problem is with the TensorFlow library and the solution is explained here: https://github.com/tensorflow/models/issues/3252. Unfortunately, you’ll have to patch your local copy of TensorFlow.

Here is the relevant section of the link that explains what you need to do (quote below):

I had same error with Python3.5 and TF1.5. This causes tf_example.features.feature[self.field_name].bytes_list.value returns byte type instead of string type in metrics/tf_example_parser.StringParser.

So I changed tf_example_parser.StringParser below

class StringParser(data_parser.DataToNumpyParser):
  """Tensorflow Example string parser."""
  def __init__(self, field_name):
    self.field_name = field_name
  def parse(self, tf_example):
    if tf_example.features.feature[self.field_name].HasField("bytes_list"):
        result = tf_example.features.feature[self.field_name].bytes_list.value
        result = "".join([x if type(x)=='str' else x.decode('utf-8') for x in result])
    else:
        result = None
    return result
nekulkarni commented 6 years ago

That worked. Thanks so much @svpino!

frankdeepl commented 5 years ago

The problem has been resolved. Thanks so much @svpino .