• python递归列出文件夹下所有文件的full_path


    语义分割数据集idd和cityscapes是很类似的,他们可以产生相同的id意义的ground truth, 代码在https://github.com/AutoNUE/public-code
    可以设置和cs的类别意义一样的setting,idd根据json自动生成cs格式的gt

    因为advent的代码是传入cityscapes的路径list,所以需要获取诸如一个文件夹下所有子文件中的路径,

    即递归获取文件夹中子文件夹的所有文件的full path,用如下的code即可

    import os
    def listdir(path, list_name):
        for file in os.listdir(path):
            file_path = os.path.join(path, file)
            if os.path.isdir(file_path):
                listdir(file_path, list_name)
            else:
                temp = file_path.split('/')
                temp0 = temp[-2]+'/'+temp[-1]
                list_name.append(temp0)
                
    list_name = []
    path=filePath
    listdir(path,list_name)
    print(list_name)
    

    如果要写到txt文件之中的话,需要以下代码

    with open('./idd.txt','w') as f:     #要存入的txt
        write=''
        for i in list_name:
            write=write+str(i)+'
    '
        f.write(write)
    

    然后就可以得到诸如下面的txt文件了

    正是和cityscapes一样格式的txt文件,也是我们想要的结果

  • 相关阅读:
    SQL SERVER 随笔知识点
    c# 异步之async/await ,Task
    c# 委托探究
    JS项整理
    C#功能块代码
    Core HostBuilder构建管道,报错提示"Value cannot be null”
    解析Swagge.Json生成Word文档
    C# Http
    C# 责任链模式
    C# 单例模式
  • 原文地址:https://www.cnblogs.com/yongjieShi/p/15195100.html
Copyright © 2020-2023  润新知