【问题标题】:No such file or directory for xml filesxml 文件没有这样的文件或目录
【发布时间】:2021-07-05 03:07:09
【问题描述】:

我已注释图像并保存在注释文件夹中。我需要转成yolov5格式。

annotations = [os.path.join('annotations', x) for x in os.listdir('/content/gdrive/My 
Drive/annotations') if x[-3:] == "xml"]

现在注释有:

annotations/100_1_0_20170110183726390.xml
annotations/100_1_2_20170105174847679.xml
annotations/100_1_2_20170110182836729.xml

当我尝试:

for ann in tqdm(annotations):
    info_dict = extract_info_from_xml(ann)
    convert_to_yolov5(info_dict)
annotations = [os.path.join('annotations', x) for x in os.listdir('annotations') if x[-3:] == "txt"]

我得到:

FileNotFoundError: [Errno 2] No such file or directory: 
'annotations/100_1_0_20170110183726390.xml'

【问题讨论】:

    标签: python xml for-loop yolo annotate


    【解决方案1】:

    您似乎正在尝试访问一个不存在的文件夹annotations/100_1_0_20170110183726390.xml(尽管我想我知道您要做什么)。

    程序需要知道文件的完整路径,如/content/gdrive/My Drive/annotations/,而不是 annotations.

    我认为os.path.join('/content/gdrive/My Drive/annotations', x) for x in os.listdir('/content/gdrive/My Drive/annotations') if x[-3:] == "txt" 可能有用,虽然有点罗嗦。

    如果您在与annotations 相同的目录中编写程序,您可能可以使用os.getcwd(),它将返回当前工作目录。然后你可以使用:

    myPath = os.getcwd()
    myPath = myPath + "annotations/"
    os.path.join(myPath, x) for x in os.listdir(myPath) if x[-3:] == "txt"

    我认为。

    【讨论】:

    • 在第一行我有包含所有 xml 文件的注释。我还列出了注释中的 3 个文件。那为什么找不到xml文件
    • @Nithya 它将寻找annotations/100_1_0_20170110183726390.xml 而不是/content/gdrive/My Drive/annotations/100_1_0_20170110183726390.xml,这是真正的位置。第一个不存在。
    猜你喜欢
    • 2021-06-24
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 2021-09-10
    • 2013-02-17
    相关资源
    最近更新 更多