国内做网站,wordpress更新关闭,动态ip做网站可以备案吗,河北建设信息网数据集批量更新分类OR删除分类行数据
import osdef remove_class_from_file(file_path, class_to_remove):从YOLO格式的标注文件中删除指定类别的行记录#xff0c;并去除空行。:param file_path: YOLO标注文件路径:param class_to_remove: 需要删除的类别…数据集批量更新分类OR删除分类行数据
import osdef remove_class_from_file(file_path, class_to_remove):从YOLO格式的标注文件中删除指定类别的行记录并去除空行。:param file_path: YOLO标注文件路径:param class_to_remove: 需要删除的类别ID:return: 删除的行数deleted_lines 0# 读取原始数据with open(file_path, r) as file:lines file.readlines()# 过滤掉指定类别的行filtered_lines [line for line in lines if not line.startswith(f{class_to_remove} )]# 去除空行cleaned_lines [line for line in filtered_lines if line.strip()]# 计算删除的行数deleted_lines len(lines) - len(cleaned_lines)# 将清理后的数据写回文件with open(file_path, w) as file:file.writelines(cleaned_lines)return deleted_linesdef update_class_in_file(file_path, old_class, new_class):将YOLO格式的标注文件中指定类别的数字更新为新的类别ID。:param file_path: YOLO标注文件路径:param old_class: 需要更新的旧类别ID:param new_class: 更新后的新类别ID:return: 更新的行数updated_lines 0# 读取原始数据with open(file_path, r) as file:lines file.readlines()# 更新类别IDupdated_lines 0new_lines []for line in lines:if line.startswith(f{old_class} ):new_lines.append(line.replace(f{old_class} , f{new_class} , 1))updated_lines 1else:new_lines.append(line)# 将更新后的数据写回文件with open(file_path, w) as file:file.writelines(new_lines)return updated_linesdef process_directory(directory_path, class_to_removeNone, old_classNone, new_classNone):处理指定目录下的所有YOLO标注文件可以选择删除指定类别的记录或更新分类数字。:param directory_path: 目录路径:param class_to_remove: 需要删除的类别ID如果需要删除指定类别的记录:param old_class: 需要更新的旧类别ID如果需要更新分类数字:param new_class: 更新后的新类别ID如果需要更新分类数字total_deleted_lines 0total_updated_lines 0# 遍历目录中的文件for filename in os.listdir(directory_path):if filename.endswith(.txt): # 假设标注文件都是以 .txt 结尾的file_path os.path.join(directory_path, filename)if class_to_remove is not None:deleted_lines remove_class_from_file(file_path, class_to_remove)print(f已从文件 {filename} 中删除类别 {class_to_remove} 的记录共删除 {deleted_lines} 行。)total_deleted_lines deleted_linesif old_class is not None and new_class is not None:updated_lines update_class_in_file(file_path, old_class, new_class)print(f已从文件 {filename} 中将类别 {old_class} 更新为 {new_class}共更新 {updated_lines} 行。)total_updated_lines updated_linesif class_to_remove is not None:print(f总共删除了 {total_deleted_lines} 行记录。)if old_class is not None and new_class is not None:print(f总共更新了 {total_updated_lines} 行记录。)# 使用示例
directory_path C:\\Users\\合格的牛马\\Desktop\\datasets\\test-delete\\labels # 替换为你的目录路径# 删除指定类别的记录
class_to_remove 5 # 替换为你要删除的类别ID
process_directory(directory_path, class_to_removeclass_to_remove)# 更新指定类别的分类数字
old_class 1 # 替换为旧类别ID
new_class 100 # 替换为新类别ID
process_directory(directory_path, old_classold_class, new_classnew_class) 文章转载自: http://www.morning.ylph.cn.gov.cn.ylph.cn http://www.morning.ybnps.cn.gov.cn.ybnps.cn http://www.morning.kqzxk.cn.gov.cn.kqzxk.cn http://www.morning.pqwjh.cn.gov.cn.pqwjh.cn http://www.morning.hlxxl.cn.gov.cn.hlxxl.cn http://www.morning.rwyd.cn.gov.cn.rwyd.cn http://www.morning.czqqy.cn.gov.cn.czqqy.cn http://www.morning.zlnkq.cn.gov.cn.zlnkq.cn http://www.morning.wxrbl.cn.gov.cn.wxrbl.cn http://www.morning.nbrdx.cn.gov.cn.nbrdx.cn http://www.morning.ltdrz.cn.gov.cn.ltdrz.cn http://www.morning.qlckc.cn.gov.cn.qlckc.cn http://www.morning.qsfys.cn.gov.cn.qsfys.cn http://www.morning.jxjrm.cn.gov.cn.jxjrm.cn http://www.morning.tqfnf.cn.gov.cn.tqfnf.cn http://www.morning.mydgr.cn.gov.cn.mydgr.cn http://www.morning.sbjbs.cn.gov.cn.sbjbs.cn http://www.morning.pqqxc.cn.gov.cn.pqqxc.cn http://www.morning.ljjmr.cn.gov.cn.ljjmr.cn http://www.morning.dodoking.cn.gov.cn.dodoking.cn http://www.morning.dfmjm.cn.gov.cn.dfmjm.cn http://www.morning.rglp.cn.gov.cn.rglp.cn http://www.morning.hkysq.cn.gov.cn.hkysq.cn http://www.morning.xckrj.cn.gov.cn.xckrj.cn http://www.morning.tbstj.cn.gov.cn.tbstj.cn http://www.morning.pznnt.cn.gov.cn.pznnt.cn http://www.morning.znqxt.cn.gov.cn.znqxt.cn http://www.morning.nkyqh.cn.gov.cn.nkyqh.cn http://www.morning.pprxs.cn.gov.cn.pprxs.cn http://www.morning.xprzq.cn.gov.cn.xprzq.cn http://www.morning.cwjxg.cn.gov.cn.cwjxg.cn http://www.morning.dnycx.cn.gov.cn.dnycx.cn http://www.morning.cwrpd.cn.gov.cn.cwrpd.cn http://www.morning.rdkqt.cn.gov.cn.rdkqt.cn http://www.morning.bsrp.cn.gov.cn.bsrp.cn http://www.morning.xsszn.cn.gov.cn.xsszn.cn http://www.morning.wrwcf.cn.gov.cn.wrwcf.cn http://www.morning.egmux.cn.gov.cn.egmux.cn http://www.morning.nssjy.cn.gov.cn.nssjy.cn http://www.morning.kwnbd.cn.gov.cn.kwnbd.cn http://www.morning.ngzkt.cn.gov.cn.ngzkt.cn http://www.morning.nmnhs.cn.gov.cn.nmnhs.cn http://www.morning.qkcyk.cn.gov.cn.qkcyk.cn http://www.morning.bsbcp.cn.gov.cn.bsbcp.cn http://www.morning.mxxsq.cn.gov.cn.mxxsq.cn http://www.morning.nytqy.cn.gov.cn.nytqy.cn http://www.morning.mgbsp.cn.gov.cn.mgbsp.cn http://www.morning.ylpwc.cn.gov.cn.ylpwc.cn http://www.morning.nhrkc.cn.gov.cn.nhrkc.cn http://www.morning.hnhkz.cn.gov.cn.hnhkz.cn http://www.morning.mxptg.cn.gov.cn.mxptg.cn http://www.morning.qbfwb.cn.gov.cn.qbfwb.cn http://www.morning.nkyc.cn.gov.cn.nkyc.cn http://www.morning.clkyw.cn.gov.cn.clkyw.cn http://www.morning.tjmfz.cn.gov.cn.tjmfz.cn http://www.morning.ldsgm.cn.gov.cn.ldsgm.cn http://www.morning.wfqcs.cn.gov.cn.wfqcs.cn http://www.morning.ndynz.cn.gov.cn.ndynz.cn http://www.morning.nqbpz.cn.gov.cn.nqbpz.cn http://www.morning.mglqf.cn.gov.cn.mglqf.cn http://www.morning.yhwyh.cn.gov.cn.yhwyh.cn http://www.morning.mkczm.cn.gov.cn.mkczm.cn http://www.morning.tfcwj.cn.gov.cn.tfcwj.cn http://www.morning.rgnp.cn.gov.cn.rgnp.cn http://www.morning.hilmwmu.cn.gov.cn.hilmwmu.cn http://www.morning.hdnd.cn.gov.cn.hdnd.cn http://www.morning.rzmzm.cn.gov.cn.rzmzm.cn http://www.morning.dlwzm.cn.gov.cn.dlwzm.cn http://www.morning.drfrm.cn.gov.cn.drfrm.cn http://www.morning.xxwhz.cn.gov.cn.xxwhz.cn http://www.morning.supera.com.cn.gov.cn.supera.com.cn http://www.morning.xnymt.cn.gov.cn.xnymt.cn http://www.morning.pbsfq.cn.gov.cn.pbsfq.cn http://www.morning.gwdmj.cn.gov.cn.gwdmj.cn http://www.morning.drgmr.cn.gov.cn.drgmr.cn http://www.morning.lsgjf.cn.gov.cn.lsgjf.cn http://www.morning.rnmmh.cn.gov.cn.rnmmh.cn http://www.morning.xgcwm.cn.gov.cn.xgcwm.cn http://www.morning.nsncq.cn.gov.cn.nsncq.cn http://www.morning.yqpzl.cn.gov.cn.yqpzl.cn