У меня есть некоторые xml-файлы с данными аннотации изображений.Я хочу преобразовать эти xml-файлы в .txt-файлы.
Я создал скрипт для преобразования xml в txt-файл в python, но столкнулся с ошибкой
from xml.etree.ElementTree import ElementTree
import sys
import os
import glob
from glob import glob
def read_xml(f,op):
if not os.path.exists(op):
os.makedirs(op,exist_ok=True)
file_n = glob(f)
for i in range(len(file_n)):
xcontent = ElementTree()
xcontent.parse(file_n[i])
doc = [xcontent.find("folder").text,xcontent.find("filename").text,xcontent.find("path").text,xcontent.find("width").text,
xcontent.find("height").text,xcontent.find("depth").text,xcontent.find("name").text,xcontent.find("xmin").text,
xcontent.find("ymin").text,xcontent.find("xmax").text,xcontent.find("ymax").text]
out = open(file_n[i]+".txt","w")
out.write(op)
if __name__ == '__main__':
files=("C:\\multi_cat_3\\models\\research\\object_detection\\images\\train_xmls\\*")
op_path=("C:\\multi_cat_3\\models\\research\\object_detection\\images\\train_xmls_op")
read_xml(files,op_path)
Ошибка:
Traceback (most recent call last):
File "C:/Users/128938/PycharmProjects/augmentation_code/test_file.py", line 32, in <module>
read_xml(files,op_path)
File "C:/Users/128938/PycharmProjects/augmentation_code/test_file.py", line 17, in read_xml
doc = [xcontent.find("folder").text,xcontent.find("filename").text,xcontent.find("path").text,xcontent.find("width").text,
AttributeError: 'NoneType' object has no attribute 'text'