当前位置:网站首页>Clean the label folder
Clean the label folder
2022-07-26 09:01:00 【The wind blows the fallen leaves and the flowers flutter】
Clean the marked folder
One 、 Preface
It is often used Ai After marking , Many categories are different from what we need .

For example, some boxes have no selected category , So when marking, this box is -1, This needs cleaning before training 
There is also the need to delete empty annotation files
For this reason, I simply wrote about cleaning everything in the folder txt Procedure of documents
Two 、 Cleaning procedure
import os
''' Enter the folder address : Output the relative addresses of all files in this folder '''
def getFilePath(fileDo):
allFilePath=[]
for file in os.listdir(fileDo):
allFilePath.append(os.path.join(fileDo, file))
#print(file)
return allFilePath
''' Enter a list containing file addresses : Function to traverse the file and execute the following instructions 1、 Delete the category as -1 The item 2、 Change other categories to specified values k 3、 Delete empty files '''
def PreData(allFilePath,k):
for FilePath in allFilePath:
if FilePath.endswith('txt'):
tem = [] # Set category not to -1 Save the items of
with open(FilePath, 'r', encoding='utf-8') as f:
while True:
line = f.readline()
if line == '':
break
if line[0] != '-': # Complete the deletion of category -1 The task of
line=str(k)+line[1:]
tem.append(line)
else:
print(line)
# If , The text , What can be inserted normally is empty , Just delete the file
if len(tem)==0:
os.remove(FilePath)
print(' Delete file '+FilePath)
# If the part is empty, write
else:
with open(FilePath, 'w', encoding='utf-8') as w:
for line in tem:
w.write(str(line))# Rewrite the previously cached values
def main():
#fileDo = './ human beings / human beings - Baidu - Tag data '
fileDo=input(' Please enter the relative address of the folder to be cleaned :')
#print(fileDo)
# Output to this folder , The relative address of all files and returned to the variable
allFilePath=getFilePath(fileDo)
print(' All documents in the address are as follows :')
print(allFilePath)
# Normalize folders
PreData(allFilePath,3)
if __name__ =='__main__':
main()
边栏推荐
- ONTAP 9文件系统的限制
- [search topics] flood coverage of search questions after reading the inevitable meeting
- Set of pl/sql -2
- pl/sql之集合
- codeforces dp合集
- [recommended collection] MySQL 30000 word essence summary - query and transaction (III)
- Overview of motion recognition evaluation
- 2022茶艺师(中级)特种作业证考试题库模拟考试平台操作
- 基于序的评价指标 (特别针对推荐系统和多标签学习)
- 论文笔记: 知识图谱 KGAT (未完暂存)
猜你喜欢

Day06 homework - skill question 6
![[eslint] Failed to load parser ‘@typescript-eslint/parser‘ declared in ‘package. json » eslint-confi](/img/39/135d29dae23b55497728233f31aa6a.png)
[eslint] Failed to load parser ‘@typescript-eslint/parser‘ declared in ‘package. json » eslint-confi

Node-v download and application, ES6 module import and export

pl/sql之集合-2

C Entry series (31) -- operator overloading

Pop up window in Win 11 opens with a new tab ---firefox

Flask project learning (I) -- sayhello

Database operation skills 7

Cadence(十)走线技巧与注意事项

Day 6 summary & database operation
随机推荐
数据库操作 题目一
SQL入门——组合表
Web概述和B/S架构
In the first year of L2, the upgrade of arbitrum nitro brought a more compatible and efficient development experience
2022茶艺师(中级)特种作业证考试题库模拟考试平台操作
ES6 modular import and export) (realize page nesting)
CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主?
Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world
NPM add source and switch source
力扣链表题
What are the differences in the performance of different usages such as count (*), count (primary key ID), count (field) and count (1)? That's more efficient
Pytoch realizes logistic regression
Numpy Foundation
ES6模块化导入导出)(实现页面嵌套)
Web overview and b/s architecture
论文笔记: 知识图谱 KGAT (未完暂存)
Dynamic SQL and exceptions of pl/sql
My meeting of OA project (query)
The idea shortcut key ALT realizes the whole column operation
Database operation skills 6