umautobots / vod-converter

Convert between visual object detection datasets
MIT License
307 stars 93 forks source link

TypeError: %d format: a number is required, not str #5

Closed stanlee321 closed 7 years ago

stanlee321 commented 7 years ago

Hi, I have some troubles trying to run the code for transform from Kitti Dataset format to VOC format with the next log:

$ python vod_converter/main.py --from kitti --from-path /g/data_object_image_2/ --to voc --to-path ./out INFO:root:Namespace(filter_images_without_labels=False, from_key='kitti', from_path='G:/data_object_image_2/', select_only_known_labels=False, to_key='voc', to_path='./out') Traceback (most recent call last): File "vod_converter/main.py", line 92, in <module> filter_images_without_labels=args.filter_images_without_labels)) File "vod_converter/main.py", line 40, in main filter_images_without_labels=filter_images_without_labels) File "C:\Users\ASDF\Desktop\GPUexp\vod-converter\vod_converter\converter.py", line 140, in convert egestor.egest(image_detections=image_detections, root=to_path) File "C:\Users\ASDF\Desktop\GPUexp\vod-converter\vod_converter\voc.py", line 122, in egest shutil.copyfile(image['path'], "%s/%d.%s" % (images_path, image_id, src_extension)) TypeError: %d format: a number is required, not str (py36)

Later if I modify this "%s/%d.%s" % (images_path, image_id, src_extension)) to ------>{}/{}.{}" .format(images_path, image_id,src_extension)` format, the next error message is show:

` $ python vod_converter/main.py --from kitti --from-path /g/data_object_image_2/ --to voc --to-path ./out INFO:root:Namespace(filter_images_without_labels=False, from_key='kitti', from_path='G:/data_object_image_2/', select_only_known_labels=False, to_key='voc', to_path='./out') Traceback (most recent call last): File "C:\Users\ASDF.conda\envs\py36\lib\xml\etree\ElementTree.py", line 1066, in _escape_cdata if "&" in text: TypeError: argument of type 'int' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "vod_converter/main.py", line 92, in filter_images_without_labels=args.filter_images_without_labels)) File "vod_converter/main.py", line 40, in main filter_images_without_labels=filter_images_without_labels) File "C:\Users\ASDF\Desktop\GPUexp\vod-converter\vod_converter\converter.py", line 140, in convert egestor.egest(image_detections=image_detections, root=to_path) File "C:\Users\ASDF\Desktop\GPUexp\vod-converter\vod_converter\voc.py", line 164, in egest ET.ElementTree(xml_root).write("{}/{}.xml".format(str(annotations_path), str(image_id))) File "C:\Users\ASDF.conda\envs\py36\lib\xml\etree\ElementTree.py", line 776, in write short_empty_elements=short_empty_elements) File "C:\Users\ASDF.conda\envs\py36\lib\xml\etree\ElementTree.py", line 941, in _serialize_xml short_empty_elements=short_empty_elements) File "C:\Users\ASDF.conda\envs\py36\lib\xml\etree\ElementTree.py", line 941, in _serialize_xml short_empty_elements=short_empty_elements) File "C:\Users\ASDF.conda\envs\py36\lib\xml\etree\ElementTree.py", line 938, in _serialize_xml write(_escape_cdata(text)) File "C:\Users\ASDF.conda\envs\py36\lib\xml\etree\ElementTree.py", line 1074, in _escape_cdata _raise_serialization_error(text) File "C:\Users\ASDF.conda\envs\py36\lib\xml\etree\ElementTree.py", line 1057, in _raise_serialization_error "cannot serialize %r (type %s)" % (text, type(text).name) TypeError: cannot serialize 3 (type int) `

Maybe is the python version? although the same happens in py27 fork version of the code, thanks for the feedback

zhenni commented 7 years ago

@stanlee321 Try this

voc.py line 178

change subnode.text = text to subnode.text = str(text)

krosaen commented 7 years ago

looks like this issue is resolved