当前位置: 首页 > news >正文

网站做图尺寸大小近期的新闻热点

网站做图尺寸大小,近期的新闻热点,网架加工安装一体的公司,2010网站建设管理数据集批量更新分类OR删除分类行数据 import osdef remove_class_from_file(file_path, class_to_remove):"""从YOLO格式的标注文件中删除指定类别的行记录,并去除空行。: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_remove=None, old_class=None, new_class=None):"""处理指定目录下的所有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_remove=class_to_remove)# 更新指定类别的分类数字
old_class = 1  # 替换为旧类别ID
new_class = 100  # 替换为新类别ID
process_directory(directory_path, old_class=old_class, new_class=new_class)
http://www.mmbaike.com/news/60469.html

相关文章:

  • 怎么搜索网站内容品牌推广计划
  • 六种常见网络营销方法南昌seo排名公司
  • 为什么有点网站打不开深圳百度seo代理
  • wordpress+配置七牛seo搜索引擎优化步骤
  • 苏州画廊网站建设网页制作软件哪个好
  • 初做淘宝客选哪个网站成人电脑基础培训班
  • 社交网站建设计划书baidu com百度一下
  • 不动产认证是哪个公司做的网站推广普通话宣传标语
  • 西安网站建设成功建设搜索风云榜
  • 岳阳网站定制seo关键词优化培训班
  • 老司机网站建设今日热点新闻事件2021
  • 美篇制作app下载安装免费seo企业建站系统
  • 日照网站建设系统介绍广州seo技术外包公司
  • seogseo网站seo
  • 安徽网站建设开发电话开发一个小程序一般需要多少钱呢
  • 做网站获流量网站排名推广工具
  • wordpress设置网站关键字seo短视频网页入口引流
  • 一个空间做2个网站今日国际军事新闻头条
  • websocket做新闻网站2023新闻摘抄十条
  • 搭建本地环境做网站手机如何制作网页
  • wordpress 用户接口深圳网站优化平台
  • wordpress variant百度seo软件曝光行者seo
  • 计算机哪个专业工资最高seo排名的职位
  • 个人网站设计企业软文网站有哪些
  • 四平网站制作安新seo优化排名网站
  • 做网站的公司叫什么软件渠道营销推广方案
  • 开发网站开发工程师招聘要求网站投放广告费用
  • 榆林网络公司建设网站超级外链工具源码
  • c 网站建设做排名优化
  • 国内做网站建设好的宁波网站推广找哪家公司