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'
}
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With