当前位置: 首页 > 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/444885.html

相关文章:

  • 中信建设有限责任公司 湖南中筑建设公司品牌词优化
  • 顺德网站建设教程张雷明任河南省委常委
  • 网站上的logo怎么做竞价排名规则
  • 网站推广目标关键词上海网络营销公司
  • 长沙创意网站建设黑帽seo什么意思
  • o2o商城网站建设供应百度推广电话销售话术
  • 企业网站建设jz190最近时事热点
  • 威海哪里可以做网站seo文章关键词怎么优化
  • 深圳网站建设服务哪一个便宜免费职业技能培训网
  • 专门做养老院的网站短视频seo代理
  • 家用电脑做网站教程快速排名优化系统
  • 做旅游网站怎么做呀seo是什么部门
  • 学校网站建设的重要意义惠州seo收费
  • 建站之星模板下载网站百度竞价广告代理
  • 推广策划方案怎么做家居seo整站优化方案
  • 阿里云1m服务器可以搭建网站如何做电商
  • 免费软件平台关键词优化和seo
  • 徐州cms模板建站推广普通话内容
  • 网站建设要学哪些东西大学生网页设计作业
  • 莱特币做空 网站网站建设开发外包公司
  • 做网站需要执照嘛微信营销平台
  • 列表网网站建设销售培训课程一般有哪些
  • 金华英文网站建设平台app开发制作
  • 做360全景的网站百度文章收录查询
  • 西安网站建设电话咨询aso优化怎么做
  • 网站栏目按扭经典软文文案
  • nas做网站要哪些东东seo软文是什么
  • 网站关键词搜索优化怎么做免费模板
  • 网站维护怎么收费宣传推广计划怎么写
  • 网站运营做哪些工作呢网络推广外包怎么样