Search code examples
pythontensorflowobject-detection

Error when converting xml files to tfrecord files


I am following the TensorFlow 2 Object Detection API Tutorial on a Macbook

Here's what I got when running the given script for converting xmls to TFrecords

Traceback (most recent call last):
  File "generate_tfrecord.py", line 62, in <module>
    label_map_dict = label_map_util.get_label_map_dict(label_map)
  File "/usr/local/lib/python3.8/site-packages/object_detection/utils/label_map_util.py", line 164, in get_label_map_dict
    label_map = load_labelmap(label_map_path)
  File "/usr/local/lib/python3.8/site-packages/object_detection/utils/label_map_util.py", line 133, in load_labelmap
    label_map_string = fid.read()
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/lib/io/file_io.py", line 116, in read
    self._preread_check()
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/lib/io/file_io.py", line 78, in _preread_check
    self._read_buf = _pywrap_file_io.BufferedInputStream(
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. tensorflow.python._pywrap_file_io.BufferedInputStream(arg0: str, arg1: int)

Invoked with: item {
  name: "cat"
  id: 1
}
, 524288

My label map file contains the following

item {
    id: 1
    name: 'cat'
}

Solution

  • It seems the problem can be resolved by replacing

    label_map = label_map_util.load_labelmap(args.labels_path)
    label_map_dict = label_map_util.get_label_map_dict(label_map)
    

    as

    label_map_dict = label_map_util.get_label_map_dict(args.labels_path)