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

河北建设厅网站修改密码在哪营销宝

河北建设厅网站修改密码在哪,营销宝,域名和网址的区别,wordpress 淘宝模板怎么用背景:训练一个Yolo8模型,在训练之前,数据集的处理是影响效果的关键因素。 Step1 定义规则 什么是人/车,比如人的话可能是站着的人,如果是骑电动车/自行车就不算是人。 Step2 收集数据集 1. 自己标注。如果是自己标…

背景:训练一个Yolo8模型,在训练之前,数据集的处理是影响效果的关键因素。

Step1 定义规则

什么是人/车,比如人的话可能是站着的人,如果是骑电动车/自行车就不算是人。

Step2 收集数据集

1. 自己标注。如果是自己标注,那么根据上述的规则进行清洗。

2. 采集他人的数据集,标注好的。那么最好是能可视化一下标签。下面是可视化代码。

import os
import cv2def visualize_yolo_boxes(image_folder, label_folder, output_folder):# 确保输出文件夹存在if not os.path.exists(output_folder):os.makedirs(output_folder)# 遍历图片文件夹for image_name in os.listdir(image_folder):# 获取图片路径image_path = os.path.join(image_folder, image_name)# 获取对应的标签路径label_path = os.path.join(label_folder, os.path.splitext(image_name)[0] + '.txt')# 如果标签文件不存在,跳过if not os.path.exists(label_path):print(f"标签文件不存在: {label_path}")continue# 读取图片image = cv2.imread(image_path)if image is None:print(f"无法读取图片: {image_path}")continue# 获取图片的宽度和高度img_height, img_width = image.shape[:2]# 读取标签文件with open(label_path, 'r') as f:lines = f.readlines()# 遍历每个标签for line in lines:parts = line.strip().split()if len(parts) != 5:continue# 解析YOLO格式的标签class_id = int(parts[0])x_center = float(parts[1]) * img_widthy_center = float(parts[2]) * img_heightwidth = float(parts[3]) * img_widthheight = float(parts[4]) * img_height# 计算边界框的左上角和右下角坐标x1 = int(x_center - width / 2)y1 = int(y_center - height / 2)x2 = int(x_center + width / 2)y2 = int(y_center + height / 2)# 在图片上绘制边界框cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)cv2.putText(image, f'Class {class_id}', (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)# 保存可视化结果output_path = os.path.join(output_folder, image_name)cv2.imwrite(output_path, image)print(f"已保存可视化结果: {output_path}")# 示例用法
image_folder = r'.\train\images'
label_folder = r'.\train\labels'
output_folder = r'.\train\visualize'visualize_yolo_boxes(image_folder, label_folder, output_folder)

Step3 修改标签

修改标签是指,比如要合并一些标签。已经标注好的数据集,比如把车子分为了truck,car,bus之类的,但是,我们都统称为car。所以要进行一些合并。下面是合并代码。

import os
import globdef process_line(line):"""Process a single line of text according to the mapping rules."""parts = line.strip().split()if not parts:  # Skip empty linesreturn Nonetry:id_num = int(parts[0])# Keep only specified IDsif id_num not in [0, 1, 2, 6]:return None# Apply mapping: 0,1 -> 0 and 3,4,5,8 -> 1if id_num in [0, 1, 6]:new_id = 1else:  # id in [3,4,5,8]new_id = 0# Replace first number and keep rest of the line the samereturn f"{new_id} {' '.join(parts[1:])}\n"except ValueError:return Nonedef process_file(input_path, output_path):"""Process a single text file and save to output directory."""try:with open(input_path, 'r') as infile:lines = infile.readlines()# Process lines and filter out None resultsprocessed_lines = [processed for line in linesif (processed := process_line(line)) is not None]# Create output directory if it doesn't existos.makedirs(os.path.dirname(output_path), exist_ok=True)# Write processed lines to output filewith open(output_path, 'w') as outfile:outfile.writelines(processed_lines)print(f"Processed {input_path} -> {output_path}")except Exception as e:print(f"Error processing {input_path}: {str(e)}")def process_directory(input_dir, output_dir):"""Process all .txt files in the input directory."""# Create output directory if it doesn't existos.makedirs(output_dir, exist_ok=True)# Find all .txt files in input directorytxt_files = glob.glob(os.path.join(input_dir, "*.txt"))for input_path in txt_files:# Create corresponding output pathrelative_path = os.path.relpath(input_path, input_dir)output_path = os.path.join(output_dir, relative_path)# Process the fileprocess_file(input_path, output_path)# Example usage
if __name__ == "__main__":input_directory = r"F:\1-dataset\raw\add_vehicle_person\combine\vehicle_class\valid\labels"  # Replace with your input directoryoutput_directory = r"F:\1-dataset\raw\add_vehicle_person\combine\vehicle_class\valid\labels_person_car"  # Replace with your output directoryprocess_directory(input_directory, output_directory)

 

http://www.dtcms.com/wzjs/490622.html

相关文章:

  • 注册公司后每年都要交什么费用简阳seo排名优化培训
  • 做网站的标签及属性微信推广怎么做
  • 网站ico图标怎么用怎么注册域名网址
  • 淘宝客网站程序购米优化营商环境心得体会1000字
  • app的后台和网站的后台差别热搜榜排名今日
  • 江西 网站 建设 开发太原seo推广
  • 深圳自助网站建设seo技术培训教程视频
  • 公司网站大全中国免费网站服务器2020
  • 广州做网站的价格台州seo公司
  • 哪些在线网站可以做系统进化树重庆网页优化seo公司
  • 做房产网站能赚钱吗爱站关键词挖掘old
  • 淘宝客可以做返利网站吗株洲网站建设
  • 外贸网站赚钱怎么建立自己的网站平台
  • 做亚马逊产品测评的网站2022拉人头最暴利的app
  • 白云定制型网站建设在百度上怎么打广告
  • wordpress链接形式网站内部链接优化方法
  • 网站 日历插件网站推广计划书范文500字
  • 网站建设实施方案seo网站优化培训厂家报价
  • 网站集群建设价格推广品牌的方法
  • 校内 实训网站 建设结构优化设计
  • b2c网站资料怎么做微信怎么推广引流客户
  • 俄罗斯网站建设百度竞价广告投放
  • 服务器怎么建网站今日新闻最新消息50字
  • 中央气象台卫星云图网络建站优化科技
  • 天河网站建设哪个好百度云网盘官网
  • 张家港网站建设做网站黄页引流推广网站入口
  • 香港网站建设 深圳分公司sem是什么岗位
  • 基于h5的个人网站建设百度收录排名查询
  • 网页设计网站简单静态模板天津seo结算
  • 百度网盟如何选择网站外贸接单平台网站