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

摄影赚钱的网站百度搜索关键词指数

摄影赚钱的网站,百度搜索关键词指数,二维码生成器在线制作图片加文字,新手学做网站的书yolo11使用教程(docker篇) 本文介绍如何在docker中部署yolo11以及如何对实例分割进行训练 文章目录 yolo11使用教程(docker篇)先决条件一、安装yolo二、使用自定义训练实例分割1.构建自定义数据 总结 先决条件 确保系统中已安装 Docker。如果没有,可以从Docker 网站…

yolo11使用教程(docker篇)

本文介绍如何在docker中部署yolo11以及如何对实例分割进行训练


文章目录

  • yolo11使用教程(docker篇)
  • 先决条件
  • 一、安装yolo
  • 二、使用自定义训练实例分割
    • 1.构建自定义数据
  • 总结


先决条件

确保系统中已安装 Docker。如果没有,可以从Docker 网站下载并安装。 确保系统已安装NVIDIA GPU 和NVIDIA
驱动程序。

过NVIDIA 支持设置 Docker
首先,运行NVIDIA 驱动程序,验证是否已正确安装:

nvidia-smi
  • 有以下输出则说明已经安装
    在这里插入图片描述
  • 没有输出,则需要装NVIDIA Docker 运行时,安装NVIDIA Docker 运行时,以便在 Docker 容器中启用GPU 支持:
# Add NVIDIA package repositories
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
distribution=$(lsb_release -cs)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list# Install NVIDIA Docker runtime
sudo apt-get update
sudo apt-get install -y nvidia-docker2# Restart Docker service to apply changes
sudo systemctl restart docker
  • 使用 Docker 验证NVIDIA 运行时
    运行 docker info | grep -i runtime 以确保 nvidia 出现在运行时列表中:
docker info | grep -i runtime

一、安装yolo

  1. 拉取yolo镜像,yolo11在github上更名为ultralytics
docker pull ultralytics/ultralytics:latest
  1. 运行容器
  • 使用命令运行,但是需要记住指令
docker run -it --ipc=host --gpus all
  • 使用docker-compose 运行
    • 下载yaml文件
    • 运行指令
version: "2.3"
services:detectron2:image: ultralytics/ultralytics:latestcontainer_name: zx_yoloruntime: nvidia    # 添加此行,确保 GPU 可用shm_size: "8gb"ipc: hostulimits:memlock: -1stack: 67108864volumes:- /app/ai/yolo/code:/home/zx/codeenvironment:- DISPLAY=$DISPLAY- NVIDIA_VISIBLE_DEVICES=all- NVIDIA_DRIVER_CAPABILITIES=compute,utility  # 重要:增强 GPU 功能stdin_open: truetty: true
docker-compose -p yolo11 up -d

二、使用自定义训练实例分割

1.构建自定义数据

  1. yolo10数据集结构
├── ultralytics
└── datasets└── zx└── images└── train└── val└── labels└── train└── val
  1. 使用labelme(查看labelme安装教程)标注,将标注的照片一部分作为训练集放在train文件夹下面,一部分作为验证集放在val文件夹下,验证集尽量平均,每个类别的数量平均,且验证集达到训练集数量的10%左右。

  2. 将labelme的标注文件转为yolo支持的格式,使用以下脚本

  • 实例分割的json格式:<class-index> <x1> <y1> <x2> <y2> ... <xn> <yn>
import json
import os'''
任务:实例分割,labelme的json文件, 转txt文件
Ultralytics YOLO format
<class-index> <x1> <y1> <x2> <y2> ... <xn> <yn>
'''# 类别映射表,定义每个类别对应的ID
label_to_class_id = {"person": 0,"car": 1,"handbag": 2,"bottle": 3# 根据需要添加更多类别
}# json转txt
def convert_labelme_json_to_yolo(json_file, output_dir, img_width, img_height):with open(json_file, 'r', encoding='utf-8') as f:labelme_data = json.load(f)# 获取文件名(不含扩展名)file_name = os.path.splitext(os.path.basename(json_file))[0]# 输出的txt文件路径txt_file_path = os.path.join(output_dir, f"{file_name}.txt")with open(txt_file_path, 'w') as txt_file:for shape in labelme_data['shapes']:label = shape['label']points = shape['points']# 根据类别映射表获取类别ID,如果类别不在映射表中,跳过该标签class_id = label_to_class_id.get(label)if class_id is None:print(f"Warning: Label '{label}' not found in class mapping. Skipping.")continue# 将点的坐标归一化到0-1范围normalized_points = [(x / img_width, y / img_height) for x, y in points]# 写入类别IDtxt_file.write(f"{class_id}")# 写入多边形掩膜的所有归一化顶点坐标for point in normalized_points:txt_file.write(f" {point[0]:.6f} {point[1]:.6f}")txt_file.write("\n")if __name__ == "__main__":json_dir = r"E:/zxlz/project/AI/data/yolouse/val"  # 替换为LabelMe标注的JSON文件目录output_dir = os.path.join(json_dir, 'out')  # 输出的YOLO格式txt文件目录img_width = 640   # 图像宽度,根据实际图片尺寸设置img_height = 512  # 图像高度,根据实际图片尺寸设置# 创建输出文件夹if not os.path.exists(output_dir):os.makedirs(output_dir)# 批量处理所有json文件for json_file in os.listdir(json_dir):if json_file.endswith(".json"):json_path = os.path.join(json_dir, json_file)convert_labelme_json_to_yolo(json_path, output_dir, img_width, img_height)
  • 实例检测的json格式:<class-index> <Minx> <Miny> width height
import os
import json
import glob# LabelMe JSON 数据路径
json_dir = r"E:\zxlz\project\AI\yolo\exchange\val02juxing"  # 替换为LabelMe标注的JSON文件目录
output_dir = os.path.join(json_dir, 'out')  # 输出的YOLO格式txt文件目录# 创建输出目录
os.makedirs(output_dir, exist_ok=True)# 类别映射(根据实际情况修改)
class_map = {"person": 0,"car": 1,"handbag": 2,"bottle": 3# 根据需要添加更多类别
}# 转换函数
def convert_labelme_json_to_yolo(json_path, output_dir, img_width, img_height):with open(json_path, "r", encoding="utf-8") as f:labelme_data = json.load(f)# 获取标签文件名output_file = os.path.join(output_dir, os.path.splitext(os.path.basename(json_path))[0] + ".txt")with open(output_file, "w") as yolo_file:for shape in labelme_data["shapes"]:label = shape["label"]points = shape["points"]# 获取矩形框坐标x_min, y_min = points[0]x_max, y_max = points[1]# 计算 YOLO 格式的坐标和尺寸(归一化)x_center = ((x_min + x_max) / 2) / img_widthy_center = ((y_min + y_max) / 2) / img_heightwidth = (x_max - x_min) / img_widthheight = (y_max - y_min) / img_height# 写入 YOLO 标签文件yolo_file.write(f"{class_map[label]} {x_center:.6f} {y_center:.6f} {width:.6f} {height:.6f}\n")# 读取所有 JSON 文件并转换
for json_file in glob.glob(os.path.join(json_dir, "*.json")):# 读取图像尺寸 (可根据你的项目需求调整)img_width, img_height = 640, 480convert_labelme_json_to_yolo(json_file, output_dir, img_width, img_height)print("✅ 转换完成!")
  1. 编辑自己的yml文件
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC by University of Oxford
# Documentation: # Documentation: https://docs.ultralytics.com/datasets/detect/voc/
# Example usage: yolo train data=VOC.yaml
# parent
# ├── ultralytics
# └── datasets
#     └── VOC  ← downloads here (2.8 GB)# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: /home/zx/code/datasets/
train: # train images (relative to 'path')  16551 images- images/train01
val: # val images (relative to 'path')  4952 images- images/val01# Classes
names:0: person1: car2: handbag3: bottle
  1. 训练模型train.py
import sys
sys.path.append('/ultralytics')
from ultralytics import YOLO# Load a model
model = YOLO("yolo11-seg.yaml")  # build a new model from YAML
# model = YOLO("yolo11n-seg.pt")  # load a pretrained model (recommended for training)
# model = YOLO("yolo11n-seg.yaml").load("yolo11n.pt")  # build from YAML and transfer weights# Train the model
results = model.train(data="/home/zx/code/datasets/zx.yaml", epochs=100, imgsz=640)
  • 输出部分内容如下
    在这里插入图片描述在这里插入图片描述
  1. 使用模型对测试照片输出结果predict.py
import sys
sys.path.append('/ultralytics')
from ultralytics import YOLO# 加载模型
model = YOLO("/ultralytics/runs/segment/train4/weights/best.pt")# 进行预测
results = model.predict(source="/home/zx/code/test/source",   # 输入数据路径imgsz=640,                     # 图像大小conf=0.3,                      # 置信度阈值project="/home/zx/code/test/out",  # 输出结果的项目路径name="result",                  # 结果文件夹名称save=True
)
  1. 导出模型export.py
import sys
sys.path.append('/ultralytics')
from ultralytics import YOLO# Load a model
model = YOLO("/ultralytics/runs/segment/train4/weights/best.pt")  # load a custom trained model# Export the model
model.export(format="onnx")

总结

  • 一定要确保训练时使用的是GPU,训练过程会显示GPU使用率(或者在容器中使用nvidia-smi指令查看显卡使用情况),如果使用的cpu那么你的电脑可能会顶不住卡死
http://www.dtcms.com/wzjs/442593.html

相关文章:

  • 桂阳做网站的软件定制开发外包网络推广运营推广
  • 做游戏制作 网站制作一个网站的费用是多少
  • 唐山建设网站网站网络顾问
  • 给素材网站做签约设计不想做了黑龙江网络推广好做吗
  • 怎么才能创个网站百度实时热点排行榜
  • 南京培训网站建设网络营销和传统营销的区别有哪些
  • 北京做校园的网站效果好的东莞品牌网站建设
  • 网站建站哪家公司好品牌策划的五个步骤
  • 公司网站建设开发企业培训课程名称
  • 独立站shopify头条广告入口
  • 多语种网站建设一键关键词优化
  • 提供提供手机网站建设临沂seo网站管理
  • 网站建设要经历哪些步骤?seo推广软件费用
  • 海外广告投放平台班级优化大师的利和弊
  • 定制开发网站百度网盘登录入口
  • 国外有哪些优秀的网站网络营销策划方案
  • 怎样才能建设网站新冠疫情最新消息今天公布
  • 网站吸引人的功能网页模板设计
  • 本地建设网站现在做百度快速收录的方法
  • b2b网站建设seo就业前景
  • 洛阳网站建设外包百度网盘链接
  • wordpress打开特别慢批量优化网站软件
  • 注册个人公司流程及费用360优化大师下载安装
  • 品质好的深圳装修首页关键词优化公司
  • 制作免费个人网站外贸接单十大网站
  • 做网站除甲醛需不需要营业执照广州百度搜索优化
  • 网站名称如何设置西安seo推广
  • html做网站收藏按钮免费国外ddos网站
  • wordpress博客联盟seo推广公司有哪些
  • 动态网站站内广告怎么做代做seo关键词排名