Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
}
like image 303
Yuexin Xu Avatar asked Dec 07 '22 10:12

Yuexin Xu


2 Answers

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)
like image 180
beryllite Avatar answered Dec 10 '22 18:12

beryllite


I've came across the same error and found a workaround.

Remove the lines:

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

And change the def class_text_to_int according to your label map like this:

def class_text_to_int(row_label):
    if row_label == 'cat':
        return 1

Now everything should be working fine.

like image 28
Ian Avatar answered Dec 10 '22 19:12

Ian