更新了diff的rknn3568
This commit is contained in:
69
ailai_pc/change_label.py
Normal file
69
ailai_pc/change_label.py
Normal file
@ -0,0 +1,69 @@
|
||||
import os
|
||||
import glob
|
||||
|
||||
# ======================
|
||||
# 配置部分(你要改这里)
|
||||
# ======================
|
||||
|
||||
# 标签文件所在文件夹
|
||||
LABEL_DIR = "/media/hx/04e879fa-d697-4b02-ac7e-a4148876ebb0/dataset/point2/2"
|
||||
|
||||
# 新的关键点顺序 (0-based)
|
||||
# 例如:原顺序 1,2,3,4 → 新顺序 1,2,4,3
|
||||
#new_order = [0, 1, 3, 2]
|
||||
new_order = [0, 2, 3, 1]
|
||||
|
||||
# ======================
|
||||
# 程序部分
|
||||
# ======================
|
||||
|
||||
def reorder_keypoints(line, new_order):
|
||||
parts = line.strip().split()
|
||||
|
||||
if len(parts) < 17:
|
||||
print(f"数据格式不对,字段数为 {len(parts)},应 ≥ 17 :", line)
|
||||
return line
|
||||
|
||||
# 前 5 个保持不变
|
||||
head = parts[:5]
|
||||
|
||||
# 后 12 个是 4 个关键点 (4 * 3)
|
||||
kps = parts[5:]
|
||||
|
||||
# 分组成 [(x1,y1,v1),(x2,y2,v2)...]
|
||||
keypoints = [kps[i:i+3] for i in range(0, 12, 3)]
|
||||
|
||||
# 按新顺序重排
|
||||
reordered = []
|
||||
for idx in new_order:
|
||||
reordered.extend(keypoints[idx])
|
||||
|
||||
return " ".join(head + reordered)
|
||||
|
||||
|
||||
def process_all_labels(label_dir, new_order):
|
||||
txt_files = glob.glob(os.path.join(label_dir, "*.txt"))
|
||||
|
||||
print(f"找到 {len(txt_files)} 个标签文件\n")
|
||||
|
||||
for txt_path in txt_files:
|
||||
lines_out = []
|
||||
|
||||
with open(txt_path, "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
for line in lines:
|
||||
if line.strip():
|
||||
line = reorder_keypoints(line, new_order)
|
||||
lines_out.append(line)
|
||||
|
||||
# 覆写文件
|
||||
with open(txt_path, "w") as f:
|
||||
f.write("\n".join(lines_out))
|
||||
|
||||
print(f"✓ 已处理:{txt_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
process_all_labels(LABEL_DIR, new_order)
|
||||
print("\n全部处理完成!")
|
||||
@ -4,7 +4,7 @@ import os
|
||||
from ultralytics import YOLO
|
||||
|
||||
# ====================== 用户配置 ======================
|
||||
MODEL_PATH = '11.pt'
|
||||
MODEL_PATH = '/home/hx/yolo/ultralytics_yolo11-main/runs/train/exp_ailai2/weights/best.pt'
|
||||
IMAGE_SOURCE_DIR = '/media/hx/04e879fa-d697-4b02-ac7e-a4148876ebb0/dataset/point2/train' # 验证集图片目录
|
||||
LABEL_DIR = '/media/hx/04e879fa-d697-4b02-ac7e-a4148876ebb0/dataset/point2/train' # 标签目录(与图片同名 .txt)
|
||||
OUTPUT_DIR = './output_images'
|
||||
@ -96,12 +96,14 @@ if __name__ == "__main__":
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
# 计算误差
|
||||
errors = np.linalg.norm(pred_kpts - gt_kpts, axis=1)
|
||||
# ====================== 只计算关键点 0 和 1 ======================
|
||||
selected_idx = [0, 1] # 只算前两个点
|
||||
|
||||
errors = np.linalg.norm(pred_kpts[selected_idx] - gt_kpts[selected_idx], axis=1)
|
||||
mean_error = np.mean(errors)
|
||||
total_errors.append(mean_error)
|
||||
|
||||
print(f"📸 {img_filename}: 每点误差={np.round(errors, 2)} 像素, 平均误差={mean_error:.2f}px")
|
||||
print(f"📸 {img_filename}: 点0&1误差={np.round(errors, 2)} 像素, 平均误差={mean_error:.2f}px")
|
||||
|
||||
# 可视化
|
||||
vis_img = img.copy()
|
||||
@ -4,8 +4,8 @@ from ultralytics import YOLO
|
||||
import os
|
||||
|
||||
# ====================== 用户配置 ======================
|
||||
MODEL_PATH = 'best.pt'
|
||||
IMAGE_SOURCE_DIR = '/media/hx/04e879fa-d697-4b02-ac7e-a4148876ebb0/dataset/point2/val' # 👈 修改为你的图像文件夹路径
|
||||
MODEL_PATH = '/home/hx/yolo/ultralytics_yolo11-main/runs/train/exp_ailai/weights/best.pt'
|
||||
IMAGE_SOURCE_DIR = '/home/hx/开发/ailai_image_obb/ailai_pc/yolo_obb_dataset/test' # 👈 修改为你的图像文件夹路径
|
||||
OUTPUT_DIR = './output_images' # 保存结果的文件夹
|
||||
|
||||
# 支持的图像扩展名
|
||||
|
||||
BIN
ailai_pc/yolo_obb_dataset/test/4.jpg
Normal file
BIN
ailai_pc/yolo_obb_dataset/test/4.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 724 KiB |
Reference in New Issue
Block a user