mirror of
https://gitee.com/nanjing-yimao-information/ieemoo-ai-gift.git
synced 2025-08-18 21:30:25 +00:00
修改测试
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -166,3 +166,5 @@ pnnx*
|
|||||||
/ultralytics/assets/
|
/ultralytics/assets/
|
||||||
confusion_gift_cls4_0.45/
|
confusion_gift_cls4_0.45/
|
||||||
*.jpg
|
*.jpg
|
||||||
|
*.png
|
||||||
|
*.txt
|
7
demo.py
7
demo.py
@ -3,8 +3,9 @@ import numpy as np
|
|||||||
# model = YOLOv10.from_pretrained('jameslahm/yolov10{n/s/m/b/l/x}')
|
# model = YOLOv10.from_pretrained('jameslahm/yolov10{n/s/m/b/l/x}')
|
||||||
# or
|
# or
|
||||||
# wget https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10{n/s/m/b/l/x}.pt
|
# wget https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10{n/s/m/b/l/x}.pt
|
||||||
model = YOLOv10('ckpts/20250514/best_gift_v10n.pt')
|
model = YOLOv10('ckpts/20250630/best_gift_v10n.pt')
|
||||||
|
|
||||||
result = model.predict('./data/bandage.jpg', save=False, imgsz=[224, 224], conf=0.1)
|
# result = model.predict('./data/bandage.jpg', save=True, imgsz=[224, 224], conf=0.1)
|
||||||
|
result = model.predict('/home/lc/data_center/gift/trace_subimgs/predict_actual_test/gift', save=True, imgsz=[224, 224], conf=0.1)
|
||||||
print(result)
|
print(result)
|
||||||
print(result[0].boxes.conf)
|
# print(result[0].boxes.conf)
|
||||||
|
@ -43,7 +43,7 @@ def get_image_list(path):
|
|||||||
|
|
||||||
|
|
||||||
def _init():
|
def _init():
|
||||||
model = YOLOv10('ckpts/20250620/best_gift_v10n.pt')
|
model = YOLOv10('ckpts/20250701/best_gift_v10n.pt')
|
||||||
return model
|
return model
|
||||||
|
|
||||||
|
|
||||||
@ -94,8 +94,5 @@ def main(path):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# path = '../data_center/gift/trace_subimgs/d50' # 间距为50时
|
|
||||||
# path = '../data_center/gift/trace_subimgs/actual_test' # 永辉超市实测
|
|
||||||
path = '../data_center/gift/gift_test' #yolov10单图测试
|
path = '../data_center/gift/gift_test' #yolov10单图测试
|
||||||
# path = '../data_center/gift/trace_subimgs/tracluster' # tracluster方法过滤
|
|
||||||
main(path)
|
main(path)
|
@ -43,7 +43,7 @@ def get_image_list(path):
|
|||||||
|
|
||||||
|
|
||||||
def _init():
|
def _init():
|
||||||
model = YOLOv10('ckpts/20250620/best_gift_v10n.pt')
|
model = YOLOv10('ckpts/20250701/best_gift_v10n.pt')
|
||||||
return model
|
return model
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,6 +253,8 @@ class BasePredictor:
|
|||||||
# Postprocess
|
# Postprocess
|
||||||
with profilers[2]:
|
with profilers[2]:
|
||||||
self.results = self.postprocess(preds, im, im0s)
|
self.results = self.postprocess(preds, im, im0s)
|
||||||
|
if len(self.results) == 0:
|
||||||
|
continue
|
||||||
self.run_callbacks("on_predict_postprocess_end")
|
self.run_callbacks("on_predict_postprocess_end")
|
||||||
|
|
||||||
# Visualize, save, write results
|
# Visualize, save, write results
|
||||||
|
@ -16,7 +16,7 @@ class YOLOv10DetectionPredictor(DetectionPredictor):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
preds = preds.transpose(-1, -2)
|
preds = preds.transpose(-1, -2)
|
||||||
bboxes, scores, labels = ops.v10postprocess(preds, self.args.max_det, preds.shape[-1]-4)
|
bboxes, scores, labels = ops.v10postprocess(preds, self.args.max_det, preds.shape[-1] - 4)
|
||||||
bboxes = ops.xywh2xyxy(bboxes)
|
bboxes = ops.xywh2xyxy(bboxes)
|
||||||
preds = torch.cat([bboxes, scores.unsqueeze(-1), labels.unsqueeze(-1)], dim=-1)
|
preds = torch.cat([bboxes, scores.unsqueeze(-1), labels.unsqueeze(-1)], dim=-1)
|
||||||
|
|
||||||
@ -31,6 +31,18 @@ class YOLOv10DetectionPredictor(DetectionPredictor):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
for i, pred in enumerate(preds):
|
for i, pred in enumerate(preds):
|
||||||
|
#### 不保存负样本predict的结果#######
|
||||||
|
# if pred.numel() == 0:
|
||||||
|
# continue
|
||||||
|
# print('pred >>> {}'.format(pred[:, 4]))
|
||||||
|
# if float(pred[:, 4][0]) < 0.1:
|
||||||
|
# continue
|
||||||
|
##################################
|
||||||
|
#####保存正样本predict漏检的结果######
|
||||||
|
# if pred.numel() != 0:
|
||||||
|
# if float(pred[:, 4][-1]) > 0.1:
|
||||||
|
# continue
|
||||||
|
##################################
|
||||||
orig_img = orig_imgs[i]
|
orig_img = orig_imgs[i]
|
||||||
pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], orig_img.shape)
|
pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], orig_img.shape)
|
||||||
img_path = self.batch[0][i]
|
img_path = self.batch[0][i]
|
||||||
|
@ -26,6 +26,17 @@ class ShowPR:
|
|||||||
values.append(value)
|
values.append(value)
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
def calculate_mena(self, ratio=0.5):
|
||||||
|
values = []
|
||||||
|
for data in self.prec_value:
|
||||||
|
thres_num = int(len(data)*ratio)
|
||||||
|
sorted_data = sorted(data, reverse=True)
|
||||||
|
value = sorted_data[:thres_num]
|
||||||
|
if len(value) == 0:
|
||||||
|
value = sorted_data[:1]
|
||||||
|
values.append(sum(value)/len(value))
|
||||||
|
return values
|
||||||
|
|
||||||
def _calculate_pr(self, prec_value):
|
def _calculate_pr(self, prec_value):
|
||||||
FN, FP, TN, TP = 0, 0, 0, 0
|
FN, FP, TN, TP = 0, 0, 0, 0
|
||||||
for output, target in zip(prec_value, self.tags):
|
for output, target in zip(prec_value, self.tags):
|
||||||
@ -53,7 +64,7 @@ class ShowPR:
|
|||||||
# print("TP>>{}, FP>>{}, TN>>{}, FN>>{}".format(TP, FP, TN, FN))
|
# print("TP>>{}, FP>>{}, TN>>{}, FN>>{}".format(TP, FP, TN, FN))
|
||||||
return prec, recall, tn_prec, tn_recall
|
return prec, recall, tn_prec, tn_recall
|
||||||
|
|
||||||
def calculate_multiple(self, ratio=0.2):
|
def calculate_multiple_1(self, ratio=0.2): # 方案1 计算满足阈值判断的占比(ratio)
|
||||||
recall, recall_TN, PrecisePos, PreciseNeg = [], [], [], []
|
recall, recall_TN, PrecisePos, PreciseNeg = [], [], [], []
|
||||||
for thre in self.thres:
|
for thre in self.thres:
|
||||||
prec_value = []
|
prec_value = []
|
||||||
@ -73,6 +84,21 @@ class ShowPR:
|
|||||||
recall_TN.append(tn_recall)
|
recall_TN.append(tn_recall)
|
||||||
return recall, recall_TN, PrecisePos, PreciseNeg
|
return recall, recall_TN, PrecisePos, PreciseNeg
|
||||||
|
|
||||||
|
def calculate_multiple_2(self, ratio=0.2): # 方案2 计算前ratio的预测试值的平均值大于thre为赠品小于为非赠品
|
||||||
|
recall, recall_TN, PrecisePos, PreciseNeg = [], [], [], []
|
||||||
|
event_value = self.calculate_mena(ratio)
|
||||||
|
for thre in self.thres:
|
||||||
|
prec_value = [1 if num >= thre else 0 for num in event_value]
|
||||||
|
prec, recall_pos, tn_prec, tn_recall = self._calculate_pr(prec_value)
|
||||||
|
print(
|
||||||
|
f"thre>>{ratio:.2f}, recall>>{recall_pos:.4f}, precise_pos>>{prec:.4f}, recall_tn>>{tn_recall:.4f}, precise_neg>>{tn_prec:4f}")
|
||||||
|
PrecisePos.append(prec)
|
||||||
|
recall.append(recall_pos)
|
||||||
|
PreciseNeg.append(tn_prec)
|
||||||
|
recall_TN.append(tn_recall)
|
||||||
|
return recall, recall_TN, PrecisePos, PreciseNeg
|
||||||
|
|
||||||
|
|
||||||
def write_results_to_file(self, recall, recall_TN, PrecisePos, PreciseNeg, ratio):
|
def write_results_to_file(self, recall, recall_TN, PrecisePos, PreciseNeg, ratio):
|
||||||
file_path = os.sep.join(['./ckpts/tracePR', self.title_name + f"_{ratio:.2f}" + '.txt'])
|
file_path = os.sep.join(['./ckpts/tracePR', self.title_name + f"_{ratio:.2f}" + '.txt'])
|
||||||
with open(file_path, 'w') as file:
|
with open(file_path, 'w') as file:
|
||||||
@ -112,5 +138,6 @@ class ShowPR:
|
|||||||
# ratio = 0.5
|
# ratio = 0.5
|
||||||
if ratio < 0.1 or ratio > 0.95:
|
if ratio < 0.1 or ratio > 0.95:
|
||||||
continue
|
continue
|
||||||
recall, recall_TN, PrecisePos, PreciseNeg = self.calculate_multiple(ratio)
|
recall, recall_TN, PrecisePos, PreciseNeg = self.calculate_multiple_1(ratio)
|
||||||
|
# recall, recall_TN, PrecisePos, PreciseNeg = self.calculate_multiple_2(ratio)
|
||||||
self.show_pr(recall, recall_TN, PrecisePos, PreciseNeg, ratio)
|
self.show_pr(recall, recall_TN, PrecisePos, PreciseNeg, ratio)
|
||||||
|
2
val.py
2
val.py
@ -1,4 +1,4 @@
|
|||||||
from ultralytics import YOLOv10
|
from ultralytics import YOLOv10
|
||||||
|
|
||||||
model = YOLOv10('/home/lc/ieemoo-ai-gift/runs/detect/train/weights/best_gift_v10n.pt')
|
model = YOLOv10('./ckpts/20250701/best_gift_v10n.pt')
|
||||||
metrics = model.val(batch=1, data='gift.yaml', imgsz=224)
|
metrics = model.val(batch=1, data='gift.yaml', imgsz=224)
|
||||||
|
Reference in New Issue
Block a user