[MF]修改文件

This commit is contained in:
songbingle 2025-06-06 14:08:13 +08:00
parent 51afd06383
commit 0db3481d94
2 changed files with 1 additions and 43 deletions

View File

@ -1,42 +0,0 @@
import cv2
from PIL import Image
import os
folder_path = 'C:/workspace/le-yolo/data/images/train'
for filename in os.listdir(folder_path):
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
img_path = os.path.join(folder_path, filename)
img = cv2.imread(img_path)
height, width, _ = img.shape
file_path = 'C:/workspace/le-yolo/data/labels/aut'
txt_files = os.listdir(file_path)
for txt_file in txt_files:
file_path = os.path.join(folder_path, txt_file)
with open(file_path, "r", ) as f:
lines = f.readlines()
for line in lines:
# 解析标注信息
parts = line.strip().split()
category_id = int(parts[0])
category_name = 'person'
x_center = float(parts[1])
y_center = float(parts[2])
w = float(parts[3])
h = float(parts[4])
# 转换为绝对坐标
x1 = int((x_center - w / 2) * width)
y1 = int((y_center - h / 2) * height)
x2 = int((x_center + w / 2) * width)
y2 = int((y_center + h / 2) * height)
# 在图片上绘制矩形框
cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 0), 2)
# 在图片上绘制标注类别
cv2.putText(img, category_name, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (255, 0, 0), 2)
cv2.imshow('Annotated Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('annotated_image.jpg', img)

View File

@ -1,5 +1,5 @@
from ultralytics import YOLO
model = YOLO(r"C:\workspace\le-yolo\runs\detect\train35\weights\last.pt")
model = YOLO(r"C:\workspace\le-yolo\runs\detect\train36\weights\last.pt")
model.train(data="data.yaml", epochs=100, batch=8, device='cpu', imgsz=640)
model.val()
print('训练完成')