small-code: txt检测结果转化为csv

Kaggle竞赛,将txt检测结果转化为csv用于结果提交:

import os
import glob
import pandas as pd


def txt_to_csv(path):  ### path存放xml文件路径
    txt_list = []
    for txt_file in glob.glob(path + '/*.txt'):
        print(txt_file)
        id = os.path.basename(txt_file).split('.')[0]
        with open(txt_file) as f:
            value = f.readline()
        value = (id,value)
        txt_list.append(value)
    column_name = ['filename_id', 'gt']
    xml_df = pd.DataFrame(txt_list, columns=column_name)
    return xml_df


def main():
    train_path = "C:\\Users\\Subinyi\\Desktop\\label\\submission"
    xml_df = txt_to_csv(train_path)
    xml_df.to_csv(('C:\\Users\\Subinyi\\Desktop\\label\\' + 'solution_txt.csv'), index=None)  ## csv文件存放地址
main()

光伏电池异常检测数据集PVELAD竞赛:

你可能感兴趣的:(人工智能,目标检测,数据集,python,机器学习,目标检测)