zoukankan      html  css  js  c++  java
  • 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文件,也是我们想要的结果

  • 相关阅读:
    lnmp搭建禅道项目
    Vue 常用指令
    vue-tools
    阿里巴巴iconfont使用
    vue创建项目
    yarn 安装vue
    php 名字中间加星号
    图片转base64
    php阿里云短信功能
    php实名认证,身份证号,姓名加照片比对
  • 原文地址:https://www.cnblogs.com/yongjieShi/p/15195100.html
Copyright © 2011-2022 走看看