mirror of
https://gitee.com/nanjing-yimao-information/ieemoo-ai-gift.git
synced 2025-08-19 22:00:25 +00:00
merge_imgs
This commit is contained in:
50
ultralytics/utils/img_joint.py
Normal file
50
ultralytics/utils/img_joint.py
Normal file
@ -0,0 +1,50 @@
|
||||
from PIL import Image
|
||||
import os
|
||||
|
||||
def merge_imgs(path1, path2, save_path):
|
||||
for img_name in os.listdir(path1):
|
||||
# img_dir1 = os.path.join(path1, img_dir)
|
||||
# if os.path.isdir(img_dir1):
|
||||
# img_dir2 = os.path.join(path2, img_dir)
|
||||
# for img_name in os.listdir(img_dir1):
|
||||
try:
|
||||
img1_path = os.path.join(path1, img_name)
|
||||
img2_path = os.path.join(path2, img_name)
|
||||
|
||||
img1 = Image.open(img1_path)
|
||||
img2 = Image.open(img2_path)
|
||||
print('img1_path',img1)
|
||||
print('img2_path', img2)
|
||||
assert img1.height == img2.height
|
||||
|
||||
|
||||
new_img = Image.new('RGB', (img1.width + img2.width+10, img1.height))
|
||||
|
||||
# print('new_img', new_img)
|
||||
new_img.paste(img1, (0, 0))
|
||||
new_img.paste(img2, (img1.width+10, 0))
|
||||
# save_dir = os.path.join(save_path, img_name)
|
||||
os.makedirs(save_path, exist_ok=True)
|
||||
img_save = os.path.join(save_path, img_name)
|
||||
# print('img-save', img_save)
|
||||
new_img.save(img_save)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
#print(img_name)
|
||||
|
||||
|
||||
#path1 = '/home/yujia/yj/yolov5-6.1/0518_cls10_v5s_new_delTP0.5/labelFn_5/'
|
||||
# path1 = 'predict5_ori_v10s/'
|
||||
# path1 = 'predict_best0524/'
|
||||
# path2 = 'predict_0613_epoch27/'
|
||||
|
||||
# path1 = 'predict_labels110_0524/'
|
||||
# path2 = 'predict_labels110_0613/'
|
||||
|
||||
path1 = '/home/lc/ieemoo-ai-gift/confusion_gift_cls4_0.45/FN/FN_3'
|
||||
path2 = '/home/lc/ieemoo-ai-gift/confusion_gift_cls4_0.45/allBox/allBox_1'
|
||||
|
||||
#save_path = '/home/yujia/yj/yolov5-6.1/0518_cls10_v5s_new_delTP0.5/labelFn_5_allBox_merge/'
|
||||
save_path = '/home/lc/ieemoo-ai-gift/confusion_gift_cls4_0.45/FN/FN_3_joint/'
|
||||
# os.makedirs(save_path, exist_ok=True)
|
||||
merge_imgs(path1, path2, save_path)
|
@ -389,6 +389,7 @@ class ConfusionMatrix:
|
||||
cls = detect_cur_cpu[5]
|
||||
c = int(cls)
|
||||
label = f'{names[c]} {conf:.2f} iou:{float(iou):.2f}'
|
||||
print(">>>>>>>>>>>>>>>>>>> label: {} C: {}".format(label, c))
|
||||
if fp_flag:
|
||||
annotator.box_label(xyxy, label, color=(125, 0, 125)) ##fp iou匹配上,类别错误 紫色框
|
||||
else:
|
||||
@ -465,7 +466,7 @@ class ConfusionMatrix:
|
||||
annotators_tp = self.create_annotator(images_tp, Annotator, names)
|
||||
annotators_all = self.create_annotator(images_all, Annotator, names)
|
||||
### 新建不同检测类别保存的文件夹,文件夹名称为类别索引
|
||||
date_path = 'confusion_0717_cls10_' + str(self.iou_thres)
|
||||
date_path = 'confusion_gift_cls4_' + str(self.iou_thres)
|
||||
paths_fn = self.makdirs_file(date_path, img_name, self.nc, str_c='FN')
|
||||
paths_fp = self.makdirs_file(date_path, img_name, self.nc, str_c='FP')
|
||||
paths_fp_bg = self.makdirs_file(date_path, img_name, self.nc, str_c='FP_bg')
|
||||
@ -485,7 +486,7 @@ class ConfusionMatrix:
|
||||
cls_flag_list_tp = [False for _ in range(self.nc)] ###混淆矩阵斜对角线上类别flag
|
||||
|
||||
## 混淆矩阵可视化 flag 设置
|
||||
save_oneImg = False ### 将所有pred_box与gt_box匹配结果画在一张图片上
|
||||
save_oneImg = True #pred_box与gt_box匹配结果画在一张图片上
|
||||
save_byClass = True ### 将所有pred_box与gt_box匹配结果按box类别分类保存,其中tp、fn、fp按gt_box类别划分,fp_bg按pred_box划分
|
||||
cls_flag_list = []
|
||||
###=========================
|
||||
|
@ -84,6 +84,7 @@ class Colors:
|
||||
|
||||
def __call__(self, i, bgr=False):
|
||||
"""Converts hex color codes to RGB values."""
|
||||
i=0
|
||||
c = self.palette[int(i) % self.n]
|
||||
return (c[2], c[1], c[0]) if bgr else c
|
||||
|
||||
|
Reference in New Issue
Block a user