merge_imgs

This commit is contained in:
2025-06-23 11:29:52 +08:00
parent a17373d576
commit 56b161dc49
8 changed files with 182 additions and 48 deletions

2
.gitignore vendored
View File

@ -164,3 +164,5 @@ pnnx*
# Autogenerated files for tests
/ultralytics/assets/
confusion_gift_cls4_0.45/
*.jpg

80
prt/.txt Normal file
View File

@ -0,0 +1,80 @@
0
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.013 0.014 0.016 0.018 0.020 0.021 0.023 0.025 0.027 0.030 0.033 0.037 0.041 0.045 0.052 0.059 0.067 0.079 0.090 0.104 0.123 0.138 0.179 0.225 0.272 0.311 0.362 0.428 0.551 0.618
R 0.950 0.950 0.949 0.947 0.946 0.946 0.946 0.945 0.945 0.940 0.939 0.939 0.939 0.937 0.936 0.934 0.932 0.927 0.925 0.924 0.922 0.920 0.917 0.912 0.903 0.901 0.899 0.887 0.867 0.855
1
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.036 0.039 0.041 0.045 0.049 0.052 0.056 0.060 0.065 0.070 0.076 0.083 0.091 0.100 0.108 0.115 0.129 0.142 0.155 0.174 0.189 0.201 0.226 0.254 0.289 0.318 0.350 0.409 0.472 0.517
R 0.934 0.934 0.934 0.933 0.931 0.931 0.930 0.928 0.928 0.927 0.927 0.925 0.924 0.923 0.922 0.921 0.919 0.917 0.916 0.914 0.910 0.909 0.905 0.903 0.899 0.897 0.890 0.878 0.871 0.866
2
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.189 0.195 0.210 0.218 0.228 0.233 0.244 0.251 0.264 0.275 0.288 0.294 0.300 0.318 0.337 0.343 0.358 0.365 0.384 0.404 0.430 0.499 0.517 0.555 0.566 0.608 0.647 0.662 0.675 0.696
R 0.645 0.640 0.629 0.623 0.617 0.613 0.606 0.603 0.593 0.584 0.576 0.571 0.568 0.560 0.545 0.537 0.522 0.514 0.503 0.493 0.485 0.436 0.418 0.400 0.398 0.375 0.349 0.342 0.329 0.311
3
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.006 0.006 0.006 0.007 0.007 0.008 0.009 0.009 0.010 0.013 0.018 0.021 0.023 0.026 0.027 0.035 0.038 0.039 0.041 0.049 0.052 0.064 0.087
R 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984
0
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.013 0.014 0.016 0.018 0.020 0.021 0.023 0.025 0.027 0.030 0.033 0.037 0.041 0.045 0.052 0.059 0.067 0.079 0.090 0.104 0.123 0.138 0.179 0.225 0.272 0.311 0.362 0.428 0.551 0.618
R 0.950 0.950 0.949 0.947 0.946 0.946 0.946 0.945 0.945 0.940 0.939 0.939 0.939 0.937 0.936 0.934 0.932 0.927 0.925 0.924 0.922 0.920 0.917 0.912 0.903 0.901 0.899 0.887 0.867 0.855
1
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.036 0.039 0.041 0.045 0.049 0.052 0.056 0.060 0.065 0.070 0.076 0.083 0.091 0.100 0.108 0.115 0.129 0.142 0.155 0.174 0.189 0.201 0.226 0.254 0.289 0.318 0.350 0.409 0.472 0.517
R 0.934 0.934 0.934 0.933 0.931 0.931 0.930 0.928 0.928 0.927 0.927 0.925 0.924 0.923 0.922 0.921 0.919 0.917 0.916 0.914 0.910 0.909 0.905 0.903 0.899 0.897 0.890 0.878 0.871 0.866
2
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.189 0.195 0.210 0.218 0.228 0.233 0.244 0.251 0.264 0.275 0.288 0.294 0.300 0.318 0.337 0.343 0.358 0.365 0.384 0.404 0.430 0.499 0.517 0.555 0.566 0.608 0.647 0.662 0.675 0.696
R 0.645 0.640 0.629 0.623 0.617 0.613 0.606 0.603 0.593 0.584 0.576 0.571 0.568 0.560 0.545 0.537 0.522 0.514 0.503 0.493 0.485 0.436 0.418 0.400 0.398 0.375 0.349 0.342 0.329 0.311
3
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.006 0.006 0.006 0.007 0.007 0.008 0.009 0.009 0.010 0.013 0.018 0.021 0.023 0.026 0.027 0.035 0.038 0.039 0.041 0.049 0.052 0.064 0.087
R 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984
0
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.013 0.014 0.015 0.018 0.020 0.021 0.023 0.025 0.027 0.030 0.033 0.037 0.041 0.046 0.052 0.059 0.065 0.079 0.090 0.104 0.122 0.134 0.168 0.214 0.261 0.310 0.358 0.432 0.553 0.617
R 0.950 0.950 0.950 0.947 0.945 0.945 0.945 0.944 0.944 0.939 0.938 0.938 0.938 0.936 0.935 0.934 0.932 0.927 0.925 0.924 0.923 0.921 0.917 0.912 0.905 0.901 0.899 0.887 0.867 0.856
1
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.036 0.039 0.041 0.045 0.049 0.052 0.056 0.060 0.066 0.070 0.077 0.084 0.092 0.102 0.108 0.116 0.129 0.142 0.155 0.174 0.188 0.202 0.226 0.255 0.289 0.317 0.349 0.410 0.473 0.515
R 0.934 0.934 0.934 0.933 0.931 0.931 0.930 0.928 0.928 0.927 0.927 0.925 0.924 0.923 0.923 0.921 0.919 0.917 0.916 0.914 0.911 0.908 0.905 0.903 0.899 0.897 0.890 0.877 0.871 0.866
2
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.190 0.196 0.211 0.218 0.228 0.233 0.244 0.251 0.264 0.275 0.289 0.294 0.300 0.319 0.337 0.343 0.358 0.367 0.383 0.404 0.429 0.498 0.514 0.555 0.566 0.609 0.647 0.662 0.675 0.694
R 0.643 0.640 0.629 0.623 0.617 0.613 0.606 0.603 0.593 0.585 0.574 0.571 0.568 0.559 0.545 0.537 0.522 0.513 0.504 0.493 0.487 0.436 0.422 0.400 0.397 0.375 0.349 0.342 0.329 0.316
3
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.006 0.006 0.006 0.007 0.007 0.008 0.009 0.009 0.010 0.013 0.018 0.021 0.023 0.026 0.028 0.035 0.038 0.039 0.042 0.049 0.052 0.065 0.088
R 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984
0
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.013 0.014 0.015 0.018 0.020 0.021 0.023 0.025 0.027 0.030 0.033 0.037 0.041 0.046 0.052 0.059 0.065 0.079 0.090 0.104 0.122 0.134 0.168 0.214 0.261 0.310 0.358 0.432 0.553 0.617
R 0.950 0.950 0.950 0.947 0.945 0.945 0.945 0.944 0.944 0.939 0.938 0.938 0.938 0.936 0.935 0.934 0.932 0.927 0.925 0.924 0.923 0.921 0.917 0.912 0.905 0.901 0.899 0.887 0.867 0.856
1
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.036 0.039 0.041 0.045 0.049 0.052 0.056 0.060 0.066 0.070 0.077 0.084 0.092 0.102 0.108 0.116 0.129 0.142 0.155 0.174 0.188 0.202 0.226 0.255 0.289 0.317 0.349 0.410 0.473 0.515
R 0.934 0.934 0.934 0.933 0.931 0.931 0.930 0.928 0.928 0.927 0.927 0.925 0.924 0.923 0.923 0.921 0.919 0.917 0.916 0.914 0.911 0.908 0.905 0.903 0.899 0.897 0.890 0.877 0.871 0.866
2
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.190 0.196 0.211 0.218 0.228 0.233 0.244 0.251 0.264 0.275 0.289 0.294 0.300 0.319 0.337 0.343 0.358 0.367 0.383 0.404 0.429 0.498 0.514 0.555 0.566 0.609 0.647 0.662 0.675 0.694
R 0.643 0.640 0.629 0.623 0.617 0.613 0.606 0.603 0.593 0.585 0.574 0.571 0.568 0.559 0.545 0.537 0.522 0.513 0.504 0.493 0.487 0.436 0.422 0.400 0.397 0.375 0.349 0.342 0.329 0.316
3
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.006 0.006 0.006 0.007 0.007 0.008 0.009 0.009 0.010 0.013 0.018 0.021 0.023 0.026 0.028 0.035 0.038 0.039 0.042 0.049 0.052 0.065 0.088
R 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984
0
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.013 0.014 0.015 0.018 0.020 0.021 0.023 0.025 0.027 0.030 0.033 0.037 0.041 0.046 0.052 0.059 0.065 0.079 0.090 0.104 0.122 0.134 0.168 0.214 0.261 0.310 0.358 0.432 0.553 0.617
R 0.950 0.950 0.950 0.947 0.945 0.945 0.945 0.944 0.944 0.939 0.938 0.938 0.938 0.936 0.935 0.934 0.932 0.927 0.925 0.924 0.923 0.921 0.917 0.912 0.905 0.901 0.899 0.887 0.867 0.856
1
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.036 0.039 0.041 0.045 0.049 0.052 0.056 0.060 0.066 0.070 0.077 0.084 0.092 0.102 0.108 0.116 0.129 0.142 0.155 0.174 0.188 0.202 0.226 0.255 0.289 0.317 0.349 0.410 0.473 0.515
R 0.934 0.934 0.934 0.933 0.931 0.931 0.930 0.928 0.928 0.927 0.927 0.925 0.924 0.923 0.923 0.921 0.919 0.917 0.916 0.914 0.911 0.908 0.905 0.903 0.899 0.897 0.890 0.877 0.871 0.866
2
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.190 0.196 0.211 0.218 0.228 0.233 0.244 0.251 0.264 0.275 0.289 0.294 0.300 0.319 0.337 0.343 0.358 0.367 0.383 0.404 0.429 0.498 0.514 0.555 0.566 0.609 0.647 0.662 0.675 0.694
R 0.643 0.640 0.629 0.623 0.617 0.613 0.606 0.603 0.593 0.585 0.574 0.571 0.568 0.559 0.545 0.537 0.522 0.513 0.504 0.493 0.487 0.436 0.422 0.400 0.397 0.375 0.349 0.342 0.329 0.316
3
P 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770 0.780 0.790 0.800 0.810 0.820 0.830 0.840 0.850 0.860 0.870 0.880 0.890 0.900 0.910 0.920 0.930 0.940 0.950 0.960 0.970 0.980 0.990
T 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.006 0.006 0.006 0.007 0.007 0.008 0.009 0.009 0.010 0.013 0.018 0.021 0.023 0.026 0.028 0.035 0.038 0.039 0.042 0.049 0.052 0.065 0.088
R 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984 0.984

View File

@ -3,6 +3,7 @@
import os
from pathlib import Path
import cv2
import numpy as np
import torch
@ -10,8 +11,13 @@ from ultralytics.data import build_dataloader, build_yolo_dataset, converter
from ultralytics.engine.validator import BaseValidator
from ultralytics.utils import LOGGER, ops
from ultralytics.utils.checks import check_requirements
from ultralytics.utils.metrics import ConfusionMatrix, DetMetrics, box_iou
from ultralytics.utils.plotting import output_to_target, plot_images
# from ultralytics.utils.metrics import ConfusionMatrix, DetMetrics, box_iou
from ultralytics.utils.metrics_confusion_visual import ConfusionMatrix, DetMetrics, box_iou
from ultralytics.utils.plotting import output_to_target, plot_images, Colors
### val时可视化图片增加
from ultralytics.utils.plotting import Annotator, Colors
colors = Colors()
class DetectionValidator(BaseValidator):
@ -146,8 +152,40 @@ class DetectionValidator(BaseValidator):
# Evaluate
if nl:
stat["tp"] = self._process_batch(predn, bbox, cls)
# ####===========增加匹配结果返回==================
# stat["tp"], matches, iou_list = self._process_batch(predn, bbox, cls) ### 生成gt和pred box匹配
# colors = Colors()
# if len(matches) > 0: ## 有匹配结果
# print('len(match)', len(matches))
# indl = matches[:, 0] ## label index
# indp = matches[:, 1] ## pred index
# # print('img', img)
# # img_name = batch['im_file']
# # print('img_name', img_name[0])
# # img = cv2.imread(img_name[0])
# img = cv2.imread(batch['im_file'][0])
# # annotator = Annotator(img, line_width=3)
# annotator = Annotator(img, line_width=3, font_size=3, pil=True, example=self.names)
# for ind, (*xyxy, conf, p_cls) in enumerate(predn):
# if ind in indp:
# p_ind = list(indp).index(ind) ## ind在match中的索引
# t_ind = indl[p_ind]
# iou = iou_list[t_ind, p_ind]
# conf_c = conf.cpu().item()
# label = self.names[int(p_cls)] + str(conf_c) + '_iou' + str(f'{iou:.2f}')
# annotator.box_label(xyxy, label, color=(128, 0, 128))
#
# img = annotator.result()
# path_save = 'tp'
# os.makedirs(path_save, exist_ok=True)
# save_path1 = os.path.join(path_save, batch['im_file'][0].split('/')[-1])
# print('save_path', save_path1)
# cv2.imwrite(save_path1, img)
####==================================
if self.args.plots:
self.confusion_matrix.process_batch(predn, bbox, cls)
###=======修改可视化匹配框=============
# self.confusion_matrix.process_batch(predn, bbox, cls)
self.confusion_matrix.process_batch(predn, bbox, cls, batch['im_file'][0], self.names, Annotator, colors)
for k in self.stats.keys():
self.stats[k].append(stat[k])

View File

@ -3,7 +3,6 @@
import os
from pathlib import Path
import cv2
import numpy as np
import torch
@ -11,13 +10,8 @@ from ultralytics.data import build_dataloader, build_yolo_dataset, converter
from ultralytics.engine.validator import BaseValidator
from ultralytics.utils import LOGGER, ops
from ultralytics.utils.checks import check_requirements
# from ultralytics.utils.metrics import ConfusionMatrix, DetMetrics, box_iou
from ultralytics.utils.metrics_confusion_visual import ConfusionMatrix, DetMetrics, box_iou
from ultralytics.utils.plotting import output_to_target, plot_images, Colors
### val时可视化图片增加
from ultralytics.utils.plotting import Annotator, Colors
colors = Colors()
from ultralytics.utils.metrics import ConfusionMatrix, DetMetrics, box_iou
from ultralytics.utils.plotting import output_to_target, plot_images
class DetectionValidator(BaseValidator):
@ -152,40 +146,8 @@ class DetectionValidator(BaseValidator):
# Evaluate
if nl:
stat["tp"] = self._process_batch(predn, bbox, cls)
# ####===========增加匹配结果返回==================
# stat["tp"], matches, iou_list = self._process_batch(predn, bbox, cls) ### 生成gt和pred box匹配
# colors = Colors()
# if len(matches) > 0: ## 有匹配结果
# print('len(match)', len(matches))
# indl = matches[:, 0] ## label index
# indp = matches[:, 1] ## pred index
# # print('img', img)
# # img_name = batch['im_file']
# # print('img_name', img_name[0])
# # img = cv2.imread(img_name[0])
# img = cv2.imread(batch['im_file'][0])
# # annotator = Annotator(img, line_width=3)
# annotator = Annotator(img, line_width=3, font_size=3, pil=True, example=self.names)
# for ind, (*xyxy, conf, p_cls) in enumerate(predn):
# if ind in indp:
# p_ind = list(indp).index(ind) ## ind在match中的索引
# t_ind = indl[p_ind]
# iou = iou_list[t_ind, p_ind]
# conf_c = conf.cpu().item()
# label = self.names[int(p_cls)] + str(conf_c) + '_iou' + str(f'{iou:.2f}')
# annotator.box_label(xyxy, label, color=(128, 0, 128))
#
# img = annotator.result()
# path_save = 'tp'
# os.makedirs(path_save, exist_ok=True)
# save_path1 = os.path.join(path_save, batch['im_file'][0].split('/')[-1])
# print('save_path', save_path1)
# cv2.imwrite(save_path1, img)
####==================================
if self.args.plots:
###=======修改可视化匹配框=============
# self.confusion_matrix.process_batch(predn, bbox, cls)
self.confusion_matrix.process_batch(predn, bbox, cls, batch['im_file'][0], self.names, Annotator, colors)
self.confusion_matrix.process_batch(predn, bbox, cls)
for k in self.stats.keys():
self.stats[k].append(stat[k])

View 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)

View File

@ -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 = []
###=========================

View File

@ -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

4
val.py
View File

@ -1,4 +1,4 @@
from ultralytics import YOLOv10
model = YOLOv10('runs/detect/train/weights/last.pt')
metrics = model.val(batch=8, data='gift.yaml')
model = YOLOv10('runs/detect/train/weights/best_gift_v10n.pt')
metrics = model.val(batch=1, data='gift.yaml', imgsz=224)