当前位置: 首页> 文旅> 艺术 > 宁波seo关键词优化设计_微信小程序开发详解_seo优化设计_大作设计网站

宁波seo关键词优化设计_微信小程序开发详解_seo优化设计_大作设计网站

时间:2025/8/12 6:28:51来源:https://blog.csdn.net/qq_38308388/article/details/145057211 浏览次数:0次
宁波seo关键词优化设计_微信小程序开发详解_seo优化设计_大作设计网站

        比如一个yolo格式的txt标签数据包含多个类别,现在需要将多类别区分训练,就需要将一个txt文件拆分成多个txt文件,python代码实现如下:

import os
import numpy as np
import shutil
img_path = '/train_images_labels_detection/labels/train'
fire_path= '/train_images_labels_detection/dataset1/labels/train'
smoke_path= '/train_images_labels_detection/dataset2/labels/train'if not os.path.exists(fire_path):os.mkdir(fire_path)
if not os.path.exists(smoke_path):os.mkdir(smoke_path)label_list = os.listdir(label_path)
for i in label_list:txtpath = os.path.join(label_path, i)with open(txtpath, 'r', encoding='utf-8') as file:fire = []smoke = []for line_num, line in enumerate(file, start=1):line = line.strip()if line:# 判断第一个字符,这里就列举了2类,此处可以根据自己数据集类别进行补充修改if line[0] == '0':fire.append(line)else:smoke.append(line)if len(fire)!=0:with open(os.path.join(fire_path,i), 'w', encoding='utf-8') as file1:for item in fire:file1.write(item + '\n')if len(smoke)!=0:with open(os.path.join(smoke_path,i), 'w', encoding='utf-8') as file2:for item in smoke:file2.write(item + '\n')

代码解释:

img_path:所有多类别标签数据地址,比如包含了火和烟2种类别,现在需要区分2者

fire_path:输出火的标签地址

smoke_path:输出烟的标签地址

关键字:宁波seo关键词优化设计_微信小程序开发详解_seo优化设计_大作设计网站

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: