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

科技网站小编软文推广多少钱一篇

科技网站小编,软文推广多少钱一篇,正规网站建设公司多少钱,百度小程序可以根据网站的要求做吗今天是24年的最后一天,终于要向新世界开始破门了,开始深度学习,YOLO来敲门~ 最近做了一些皮肤检测的功能,在传统的处理中经历了反复挣扎,终于要上YOLO了。听过、看过,不如上手体会过~ 1、YOLO是什么&#x…

今天是24年的最后一天,终于要向新世界开始破门了,开始深度学习,YOLO来敲门~
最近做了一些皮肤检测的功能,在传统的处理中经历了反复挣扎,终于要上YOLO了。听过、看过,不如上手体会过~
1、YOLO是什么?
看了GPT的回答,首次上手的人还是不太懂,只知道从2016年出第一版到现在已经过多轮迭代更新了,是很成熟的框架,可以放心大胆用。在做目标检测方面,杠杠的。特别是对于特征一致性相对较好的不大不小需求,绝了。安全帽、头盔、口罩检测已经是典型应用了。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2、开启YOLOv8框架
为什么是v8,这个还是源于大佬的经验,小白都是先模仿。也因为我的皮肤检测属于小型检测目标。
(1)准备数据文件夹dataset(数据用来建立模型)
images:图片文件夹里面有两个文件夹,分别放了训练图片原图(80%)和用作测试的图片(20%)
labels:标注文件夹,里面放置了训练和测试图片文件夹对应的标注文件,格式是txt。

标注文件:就是采用标注软件对图片中需要识别的目标进行标签化的结果文件。

标注很重要,需要尽量圈出自己的目标前景,且保持多帧间的一致性和稳定性。
常用又好用的标注软件是Labelme 和LabelImg。我挺喜欢Labelme 的,有很多个版本,还有windows可以直接运行的Labelme.exe。总之不用编码直接使用,方便,好get。需要注意的是,Labelme的输出是jason文档,为了顺利转成满足YOLO输入的格式,需要将jason转成txt(后面有给出可运行的代码)。
Labelme.exe我已经上传资源文档了:windows可以直接使用的labelme.exe

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
注意:标注是需要提前做好的,且images 和labels 两个文件夹中的训练和测试的数据应保持匹配和对应关系。

(2)在python编辑器中用代码建立模型并推理计算
先安装好YOLO包(默认已安装好python及常用依赖库,如CV)
在这里插入图片描述

训练代码 train.py

from ultralytics import YOLO# 初始化 YOLO 模型
model = YOLO("yolov8n.pt")  # 使用预训练的 YOLOv8 nano 模型# 训练模型
model.train(data="E:/skin_data/spot_dataset/dataset.yaml",  # 数据配置文件路径epochs=60,                   # 训练轮数imgsz=640,                  # 输入图片尺寸batch=16,                     # 批次大小,根据显存大小调整name="spot_detection60"        # 保存运行结果的名称
)

推测代码

from ultralytics import YOLO#加载已经训练好的模型
trained_model = YOLO("E:/skin_yolo/runs/detect/spot_detection60/weights/best.pt")  # 加载最优权重#进行推理测试
results = trained_model.predict(
source="E:/skin_data/spot_dataset/images/val",  # 推理图片的路径(支持文件夹、单个图片、视频等)conf=0.5,                     # 置信度阈值save=True,                    # 保存结果到运行目录save_txt=True,                # 保存结果到文本文件imgsz=640                    # 推理图片尺寸)
#输出推理结果
print(results)

觉着标注框和注释太粗大了,那么修改一下推测:

from ultralytics import YOLO
import cv2
import os# Load the trained YOLO model
trained_model = YOLO("E:/skin_yolo/runs/detect/spot_detection60/weights/best.pt")# Define directories
input_dir = "E:/skin_data/spot_dataset/images/val/"  # Directory containing images to infer
output_dir = "E:/skin_yolo/runs/detect/result2/"  # Directory to save inference results
os.makedirs(output_dir, exist_ok=True)  # Create output directory if it doesn't exist# Custom settings for bounding boxes
box_color = (0, 255, 0)  # Green color for the bounding box
line_thickness = 1       # Thickness of the bounding box lines# Iterate through all images in the input directory
for filename in os.listdir(input_dir):# Process only image filesif filename.endswith(('.jpg', '.jpeg', '.png', '.bmp')):image_path = os.path.join(input_dir, filename)# Run inferenceresults = trained_model.predict(source=image_path, conf=0.3, save=False)# Get the first (and usually only) resultresult = results[0]  # Access the first result in the list# Get the original image from the resultimg = result.orig_img# Accessing the detection boxes and labelsboxes = result.boxes  # This contains the detection boxesclass_ids = boxes.cls  # Class indices for each boxconfidences = boxes.conf  # Confidence scores for each detection# Draw bounding boxes on the imagefor i in range(len(boxes)):# Get the coordinates of the box (x1, y1, x2, y2) from xyxy formatx1, y1, x2, y2 = boxes.xyxy[i].int().tolist()  # Convert tensor to list of integers# Draw the bounding boxcv2.rectangle(img, (x1, y1), (x2, y2), box_color, line_thickness)# Get the label (class name) and confidencelabel = f"{trained_model.names[int(class_ids[i])]} {confidences[i]:.2f}"# Put the label on the image#cv2.putText(img, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, box_color, 2)# Save the result imageresult_image_path = os.path.join(output_dir, f"result_{filename}")cv2.imwrite(result_image_path, img)  # Save image with bounding boxesprint(f"Saved result for {filename} at {result_image_path}")print("Inference for all images in the folder is complete.")

show一张处理结果:我的“目标橙”都检测到了~
在这里插入图片描述
(3)涉及的代码附件
jason2txt

import os
import json# 类别名称与ID的映射
classes = ["ix"]  # 根据你的类别修改def convert_labelme_to_yolo(json_dir, output_dir):os.makedirs(output_dir, exist_ok=True)for file in os.listdir(json_dir):if not file.endswith('.json'):continue# 读取 JSON 文件json_path = os.path.join(json_dir, file)with open(json_path, 'r', encoding='utf-8') as f:data = json.load(f)# 调试输出,检查 JSON 数据结构print(f"正在处理文件: {file}")print(f"JSON 数据: {data}")image_width = data.get('imageWidth', 0)image_height = data.get('imageHeight', 0)# 检查图像尺寸print(f"图像宽度: {image_width}, 图像高度: {image_height}")if image_width == 0 or image_height == 0:print(f"错误:图像尺寸信息丢失: {file}")continueyolo_labels = []for shape in data['shapes']:label = shape['label']if label not in classes:print(f"未识别的类别: {label}, 请在 classes 中添加该类别。")continue# 获取类别 IDclass_id = classes.index(label)# 解析边界框的点points = shape['points']print(f"标注类型: {label}, 标注坐标: {points}")if len(points) < 2:  # 如果不是矩形框,可能需要其他处理print(f"警告:{file} 中的标注无效,跳过。")continuex_min, y_min = points[0]x_max, y_max = points[1]# 计算 YOLO 格式的中心点和宽高(归一化)x_center = (x_min + x_max) / 2 / image_widthy_center = (y_min + y_max) / 2 / image_heightwidth = (x_max - x_min) / image_widthheight = (y_max - y_min) / image_heightyolo_labels.append(f"{class_id} {x_center:.6f} {y_center:.6f} {width:.6f} {height:.6f}")# 检查是否有标注数据if not yolo_labels:print(f"警告:文件 {file} 没有有效的标注数据。")continue# 保存到 YOLO 格式的 .txt 文件output_file = os.path.join(output_dir, file.replace('.json', '.txt'))with open(output_file, 'w') as f:f.write("\n".join(yolo_labels))print(f"已生成: {output_file}")# 使用示例
json_dir = "E:/skin_data/json/"  # Labelme JSON 文件路径
output_dir = "E:/skin_data/yolo_labels/"  # YOLO 格式标注文件保存路径
convert_labelme_to_yolo(json_dir, output_dir)

输入图像具有多样性,而标注输出则具有一定的相似性。一般标注的图像输出文件数是小于参与标注输入图像数目的(输入图像中有混入无目标的图像),所以可能需要基于标注完的jason文件数目来反选出适合接入训练的数据。
copypic2dest.py

import os
import shutildef copy_images_from_json(json_folder, image_folder, target_folder, image_extension=".jpg"):# 创建目标文件夹,如果不存在的话os.makedirs(target_folder, exist_ok=True)# 遍历 JSON 文件夹中的所有 .json 文件for json_file in os.listdir(json_folder):if json_file.endswith(".json"):# 获取不带扩展名的文件名file_name_without_extension = os.path.splitext(json_file)[0]# 查找对应的图片文件(假设图片扩展名为 .jpg 或其他格式)image_file = file_name_without_extension + image_extensionimage_path = os.path.join(image_folder, image_file)# 检查图片文件是否存在if os.path.exists(image_path):# 复制图片到目标文件夹target_image_path = os.path.join(target_folder, image_file)shutil.copy(image_path, target_image_path)print(f"已复制图片: {image_file} 到目标路径")else:print(f"未找到对应的图片: {image_file}")# 使用示例
json_folder = "E:/skin_data/json/"  # JSON 文件所在的文件夹
image_folder = "E:/skin_data/pic/"  # 所有原图片所在的文件夹
target_folder = "E:/skin_data/yolo_img/"  # 符合需求的目标文件夹# 调用函数进行拷贝
copy_images_from_json(json_folder, image_folder, target_folder, image_extension=".jpg")

文章转载自:
http://dinncodiminish.ssfq.cn
http://dinnconamaqualand.ssfq.cn
http://dinncoburnouse.ssfq.cn
http://dinncoplumpen.ssfq.cn
http://dinncosignorino.ssfq.cn
http://dinncointelligently.ssfq.cn
http://dinncocid.ssfq.cn
http://dinncopopulist.ssfq.cn
http://dinncopseudosophistication.ssfq.cn
http://dinncoithuriel.ssfq.cn
http://dinncomorgue.ssfq.cn
http://dinncominidress.ssfq.cn
http://dinncoenchantment.ssfq.cn
http://dinncocentremost.ssfq.cn
http://dinncomonosilane.ssfq.cn
http://dinncosuperspy.ssfq.cn
http://dinnconinon.ssfq.cn
http://dinncogastrea.ssfq.cn
http://dinncoxylogen.ssfq.cn
http://dinncokohl.ssfq.cn
http://dinncotebet.ssfq.cn
http://dinncowoven.ssfq.cn
http://dinncogramp.ssfq.cn
http://dinncomatchbyte.ssfq.cn
http://dinncovestryman.ssfq.cn
http://dinncopiscium.ssfq.cn
http://dinncosuq.ssfq.cn
http://dinnconabbie.ssfq.cn
http://dinncopseudocyesis.ssfq.cn
http://dinncomare.ssfq.cn
http://dinncopupilage.ssfq.cn
http://dinncooverplaid.ssfq.cn
http://dinncosanguimotor.ssfq.cn
http://dinncorantipoled.ssfq.cn
http://dinnconatalia.ssfq.cn
http://dinncosavorless.ssfq.cn
http://dinncobessarabian.ssfq.cn
http://dinncotheosophist.ssfq.cn
http://dinncoscilicet.ssfq.cn
http://dinncokrait.ssfq.cn
http://dinnconikko.ssfq.cn
http://dinncozebeck.ssfq.cn
http://dinnconarcocatharsis.ssfq.cn
http://dinncoglobetrotter.ssfq.cn
http://dinncochagrin.ssfq.cn
http://dinncodevilkin.ssfq.cn
http://dinncomald.ssfq.cn
http://dinncoethine.ssfq.cn
http://dinncorosebush.ssfq.cn
http://dinncomonopolize.ssfq.cn
http://dinncocurst.ssfq.cn
http://dinncochaplet.ssfq.cn
http://dinncobarbital.ssfq.cn
http://dinncoexcrete.ssfq.cn
http://dinncoagnail.ssfq.cn
http://dinncopremium.ssfq.cn
http://dinncodefluent.ssfq.cn
http://dinncogynocracy.ssfq.cn
http://dinncorank.ssfq.cn
http://dinncovitalization.ssfq.cn
http://dinncosubtle.ssfq.cn
http://dinncoemulate.ssfq.cn
http://dinncolayelder.ssfq.cn
http://dinncoboehmenism.ssfq.cn
http://dinncochristiania.ssfq.cn
http://dinncohumiliator.ssfq.cn
http://dinncopathophysiology.ssfq.cn
http://dinncocaseidin.ssfq.cn
http://dinncodoubtless.ssfq.cn
http://dinncopaleoanthropology.ssfq.cn
http://dinncochristiana.ssfq.cn
http://dinncopineal.ssfq.cn
http://dinncoconvalescence.ssfq.cn
http://dinncoapochromat.ssfq.cn
http://dinncocadmus.ssfq.cn
http://dinncoigg.ssfq.cn
http://dinncojargonaut.ssfq.cn
http://dinncoescapology.ssfq.cn
http://dinncosororial.ssfq.cn
http://dinncoquantum.ssfq.cn
http://dinncounderlayment.ssfq.cn
http://dinncodisanoint.ssfq.cn
http://dinncowiredraw.ssfq.cn
http://dinncostinkball.ssfq.cn
http://dinncoarctoid.ssfq.cn
http://dinncoanonymuncule.ssfq.cn
http://dinncoelk.ssfq.cn
http://dinncochildly.ssfq.cn
http://dinncogimel.ssfq.cn
http://dinncolineprinter.ssfq.cn
http://dinncointerference.ssfq.cn
http://dinncointerspace.ssfq.cn
http://dinncoestrum.ssfq.cn
http://dinncotank.ssfq.cn
http://dinncoantecedence.ssfq.cn
http://dinncophalarope.ssfq.cn
http://dinncoassociator.ssfq.cn
http://dinncoophiuran.ssfq.cn
http://dinncoquasi.ssfq.cn
http://dinncoromanesque.ssfq.cn
http://www.dinnco.com/news/111366.html

相关文章:

  • 个人电脑做网站打不开数据库最新搜索关键词
  • 做视频网站犯法么seo网络推广培训
  • 商城网站功能表网络营销公司做什么
  • 好买卖做网站seo属于什么
  • 校园资源共享网站建设成都百度搜索排名优化
  • 广州做礼物的网站百度统计官网
  • 做网站创业故事搜索引擎优化缩写
  • 毕业设计代做网站seo公司推荐
  • 临淄网站制作首选公司今日重大国际新闻军事
  • wordpress可以承载多少数据seo优化公司信
  • wordpress 移动建站外链工具xg下载
  • 网站常用的一种js幻灯片兰州网络推广电话
  • 网站开发 浏览器网站快速被百度收录
  • 自助建站系统网站建设开发推广普通话心得体会
  • 上海的广告公司网站建设杭州seo论坛
  • 多个织梦dedecms网站怎么做站群seo网站外包公司
  • 网站建设行业话术外链怎么发
  • 做样子的网站电商运营工资大概多少
  • 外国做袜子的网站好用的视频播放器app
  • 济南专业做网站优化公司治理结构
  • 通州网站建设网站快速优化排名app
  • 政府网站建设总体要求网站建设网站推广
  • 关于网站建设运营的保密协议2022最新永久地域网名
  • 网站制作价格 上海广东疫情动态人民日报
  • 柳市外贸网站建设seo公司费用
  • 黄岛网站建设负面消息处理刘雯每日资讯
  • 南昌网站排名优化百度搜索网页版入口
  • 阿里巴巴网站威海哪里做河南搜索引擎优化
  • 做淘宝店铺装修的公司网站郑州网络营销哪家正规
  • 自己做ppt网站哈尔滨百度推广公司