Skip to content

Conversation

zltf
Copy link

@zltf zltf commented May 8, 2022

No description provided.

@zltf zltf changed the title fix: #21 fix: [#21] May 8, 2022
@zltf zltf changed the title fix: [#21] fix: 工地防护检测BUG修复,见 issue #21 May 8, 2022
@HelloCodeFlow
Copy link

@MonkeyCode-AI review

Copy link

@MonkeyCode-AI MonkeyCode-AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request 概述

  • 本次PR主要修改了demo.py文件中的get_person_info_list函数,优化了人体检测与安全帽、防护服关联的逻辑。原实现中,当找到第一个满足IoU阈值的对象时就立即break,可能无法找到最佳匹配的对象。修改后,通过跟踪最大IoU值确保选择最佳匹配的帽子和防护服框,提高了检测的准确性。

Pull Request 变更详情

文件路径 变更类型 变更内容
codes/17.YOLOv5 jetson nano 工地防护检测/demo.py 修改 优化人体与安全帽、防护服的关联逻辑,通过跟踪最大IoU值确保选择最佳匹配对象

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在修改后的代码中,虽然通过跟踪最大IoU值可以确保选择最佳匹配对象,但hat_iou_thresh和vest_iou_thresh两个阈值被硬编码为0,这可能不是最佳实践。建议将这些阈值作为参数传入函数或从配置文件中读取,以提高代码的灵活性和可维护性。

Suggested change
max_hat_iou = 0
# 建议将阈值作为参数传入函数
def get_person_info_list(self, person_list, hat_list, vest_list, hat_iou_thresh=0.5, vest_iou_thresh=0.5):
"""
获取每个人的信息人体框安全帽防护服
@param: person_list list 人体框列表
@param: hat_list list 安全帽列表
@param: vest_list list 防护服列表
@param: hat_iou_thresh float 安全帽IOU阈值
@param: vest_iou_thresh float 防护服IOU阈值
@return person_info_list list
"""
# 使用传入的阈值参数而不是硬编码
person_info_list = []
for person in person_list:
person_info_item = [[],[],[]]
# 人体框
person_box = person[:5]
person_info_item[0]= person_box
# 依次与帽子计算IOU
max_hat_iou = 0
for hat in hat_list:
hat_box = hat[:6]
hat_iou = self.get_iou(person_box, hat_box)
if hat_iou > hat_iou_thresh and hat_iou > max_hat_iou:
person_info_item[1] = hat_box
max_hat_iou = hat_iou
# 依次与防护服计算IOU
max_vest_iou = 0
for vest in vest_list:
vest_box = vest[:5]
vest_iou = self.get_iou(person_box, vest_box)
if vest_iou > vest_iou_thresh and vest_iou > max_vest_iou:
person_info_item[2] = vest_box
max_vest_iou = vest_iou
person_info_list.append(person_info_item)
return person_info_list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

虽然优化后的算法能确保找到最佳匹配的对象,但时间复杂度有所增加。原实现中,一旦找到满足阈值的对象就会break,而修改后的实现需要遍历所有对象以找到最大IoU值。在对象数量较多的情况下,这可能会影响性能。建议添加注释说明这一权衡,或在性能关键场景下考虑其他优化方案。

Suggested change
max_vest_iou = 0
# 可以添加注释说明为何选择遍历所有对象而不是提前break
# 这样做是为了确保找到IoU最大的匹配对象,提高检测准确性
# 但会增加时间复杂度,在对象数量多时可能影响性能

@MonkeyCode-AI
Copy link

⏳ MonkeyCode-AI 正在分析,请稍等片刻...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants