当前位置:网站首页>对标注文件夹进行清洗
对标注文件夹进行清洗
2022-07-26 08:52:00 【风吹落叶花飘荡】
对标注文件夹进行清洗
一、前言
很多时候使用了Ai标注后,很多类别和我们需要的不一样。

比如有些框没有选定类别,所以标注的时候这个框就是-1,这在训练前是需要清洗的
还有要删除空的标注文件的需求
为此我简单写了一下清洗文件夹内全部txt文件的程序
二、清洗程序
import os
''' 输入文件夹地址: 输出该文件夹下全部文件的相对地址 '''
def getFilePath(fileDo):
allFilePath=[]
for file in os.listdir(fileDo):
allFilePath.append(os.path.join(fileDo, file))
#print(file)
return allFilePath
''' 输入包含文件地址的列表: 函数对文件进行遍历执行以下指令 1、删掉类别为-1的项 2、将其他类别都修改为指定值k 3、删除空的的文件 '''
def PreData(allFilePath,k):
for FilePath in allFilePath:
if FilePath.endswith('txt'):
tem = [] # 将类别不为-1的项保存起来
with open(FilePath, 'r', encoding='utf-8') as f:
while True:
line = f.readline()
if line == '':
break
if line[0] != '-': #完成删除类别为-1的任务
line=str(k)+line[1:]
tem.append(line)
else:
print(line)
#如果,该文本,可正常插入的为空,就删除该文件
if len(tem)==0:
os.remove(FilePath)
print('删除文件'+FilePath)
#部为空则写入
else:
with open(FilePath, 'w', encoding='utf-8') as w:
for line in tem:
w.write(str(line))#将之前缓存的值重写进去
def main():
#fileDo = './人类/人类-百度-标签数据'
fileDo=input('请输入要清洗文件夹的相对地址:')
#print(fileDo)
# 输出该文件夹下,全部文件的相对地址并返回给变量
allFilePath=getFilePath(fileDo)
print('地址内全部文件如下:')
print(allFilePath)
# 对进行文件夹进行规范化
PreData(allFilePath,3)
if __name__ =='__main__':
main()
边栏推荐
- 03异常处理,状态保持,请求钩子---04大型项目结构与蓝图
- [freeswitch development practice] use SIP client Yate to connect freeswitch for VoIP calls
- pl/sql之动态sql与异常
- The lessons of 2000. Web3 = the third industrial revolution?
- 合工大苍穹战队视觉组培训Day5——机器学习,图像识别项目
- PAT 甲级 A1034 Head of a Gang
- Pytoch realizes logistic regression
- [suggestions collection] summary of MySQL 30000 word essence - locking mechanism and performance tuning (IV) [suggestions collection]
- Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
- Overview of motion recognition evaluation
猜你喜欢

Day 6 summary & database operation

Database operation skills 7

Poor English, Oracle OCP or MySQL OCP exam can also get a high score of 80 points

at、crontab

JDBC数据库连接池(Druid技术)

机器学习中的概率模型

03异常处理,状态保持,请求钩子---04大型项目结构与蓝图

Deploy prometheus+grafana monitoring platform

Pan micro e-cology8 foreground SQL injection POC

Datawhale panda book has been published!
随机推荐
数据库操作 题目一
Espressif plays with the compilation environment
Dynamic SQL and exceptions of pl/sql
Replication of SQL injection vulnerability in the foreground of Pan micro e-cology8
深度学习常用激活函数总结
Oracle 19C OCP 1z0-082 certification examination question bank (51-60)
Oracle 19C OCP 1z0-083 question bank (7-12)
数据库操作 题目二
Recurrence of SQL injection vulnerability in the foreground of a 60 terminal security management system
Oracle 19C OCP 1z0-082 certification examination question bank (30-35)
机器学习中的概率模型
[freeswitch development practice] use SIP client Yate to connect freeswitch for VoIP calls
Ansible important components (playbook)
数据库操作 技能6
The lessons of 2000. Web3 = the third industrial revolution?
Database operation skills 7
OA项目之我的会议(查询)
数据库操作技能7
2000年的教训。web3是否=第三次工业革命?
Set of pl/sql -2