制作数据集
使用labelme,在里面配置SAM分割一切模型,辅助标注得到所有图像的json文件
检查json格式文件,确保是实例分割格式( class x1 y1 x2 y2 ... xn yn
,表示多边形点坐标),避免是目标检测格式(class x_center y_center width height,
表示矩形框坐标宽高)
环境安装
使用Anaconda创建虚拟环境
conda create -n yolov11 python=3.11.3
conda activate yolov11
安装pytorch,在控制台输入nvidia-smi
即可查看CUDA Version,此处版本为cuda最高支持版本,安装cuda时不大于该版本即可
在PyTorch Foundation里面选择CUDA11.8不高于本机12.2的版本
数据集json转txt
python脚本代码:
import os
import json
from tqdm import tqdm
# 设置路径
json_dir = "D:\打靶项目" # 存放 .json 的目录
output_txt_dir = "D:\ShootDetection\Demo\data\labels" # 转换后 .txt 保存目录
os.makedirs(output_txt_dir, exist_ok=True)
# 遍历所有 json 文件
for json_file in tqdm(os.listdir(json_dir)):
if not json_file.endswith(".json"):
continue
json_path = os.path.join(json_dir, json_file)
with open(json_path, 'r') as f:
data = json.load(f)
image_width = data.get("imageWidth")
image_height = data.get("imageHeight")
txt_lines = []
for shape in data.get("shapes", []):
if shape.get("shape_type") != "polygon":
continue # 跳过非多边形的标注
label = shape.get("label")
class_id = int