fix: 工地防护检测BUG修复,见 issue #21#22
Open
zltf wants to merge 1 commit intoenpeizhao:mainfrom
Open
Conversation
|
@MonkeyCode-AI review |
MonkeyCode-AI
left a comment
There was a problem hiding this comment.
Pull Request 概述
- 本次PR主要修改了
demo.py文件中的get_person_info_list函数,优化了人体检测与安全帽、防护服关联的逻辑。原实现中,当找到第一个满足IoU阈值的对象时就立即break,可能无法找到最佳匹配的对象。修改后,通过跟踪最大IoU值确保选择最佳匹配的帽子和防护服框,提高了检测的准确性。
Pull Request 变更详情
| 文件路径 | 变更类型 | 变更内容 |
|---|---|---|
| codes/17.YOLOv5 jetson nano 工地防护检测/demo.py | 修改 | 优化人体与安全帽、防护服的关联逻辑,通过跟踪最大IoU值确保选择最佳匹配对象 |
There was a problem hiding this comment.
在修改后的代码中,虽然通过跟踪最大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 |
There was a problem hiding this comment.
虽然优化后的算法能确保找到最佳匹配的对象,但时间复杂度有所增加。原实现中,一旦找到满足阈值的对象就会break,而修改后的实现需要遍历所有对象以找到最大IoU值。在对象数量较多的情况下,这可能会影响性能。建议添加注释说明这一权衡,或在性能关键场景下考虑其他优化方案。
Suggested change
| max_vest_iou = 0 | |
| # 可以添加注释说明为何选择遍历所有对象而不是提前break | |
| # 这样做是为了确保找到IoU最大的匹配对象,提高检测准确性 | |
| # 但会增加时间复杂度,在对象数量多时可能影响性能 |
|
⏳ MonkeyCode-AI 正在分析,请稍等片刻... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.