当前位置: 首页 > article >正文

bytetrack 内存泄露问题

背景

bytetrack 在生产运行过程中,发现有内存泄露问题,程序跑了几天,通过free -m观察,内存验证不足
走查完bytetrack源码,发现有内存泄露bug,目前bytetrack官方已经没有维护就不提pr了

c++问题代码

ByteTrack-main\deploy\TensorRT\cpp\src\BYTETracker.cpp
内存泄露在 removed_stracks

  // Step 5: Update state //
  for (int i = 0; i < this->lost_stracks.size(); i++) {
    if (this->frame_id - this->lost_stracks[i].end_frame() >
        this->max_time_lost) {
      this->lost_stracks[i].mark_removed();
      removed_stracks.push_back(this->lost_stracks[i]);
    }
  }

  for (int i = 0; i < this->tracked_stracks.size(); i++) {
    if (this->tracked_stracks[i].state == TrackState::Tracked) {
      tracked_stracks_swap.push_back(this->tracked_stracks[i]);
    }
  }
  this->tracked_stracks.clear();
  this->tracked_stracks.assign(tracked_stracks_swap.begin(),
                               tracked_stracks_swap.end());

  this->tracked_stracks =
      joint_stracks(this->tracked_stracks, activated_stracks);
  this->tracked_stracks = joint_stracks(this->tracked_stracks, refind_stracks);

  this->lost_stracks = sub_stracks(this->lost_stracks, this->tracked_stracks);
  for (int i = 0; i < lost_stracks.size(); i++) {
    this->lost_stracks.push_back(lost_stracks[i]);
  }

  this->lost_stracks = sub_stracks(this->lost_stracks, this->removed_stracks);
  for (int i = 0; i < removed_stracks.size(); i++) {
    this->removed_stracks.push_back(removed_stracks[i]);
  }

修复c++代码

只保留 max_time_lost *10 范围内的跟踪对象,超过就删除

  // 更新 removed_stracks,只保留在 max_time_lost *10 范围内的跟踪对象
  std::vector<STrack> filtered_removed_stracks;
  for (auto& track : this->removed_stracks) {
      if (this->frame_id - track.end_frame() < 10 * this->max_time_lost) {
          filtered_removed_stracks.push_back(track);
      }
  }
  this->removed_stracks = filtered_removed_stracks;

python问题代码

yolox/tracker/byte_tracker.py

        """ Step 5: Update state"""
        for track in self.lost_stracks:
            if self.frame_id - track.end_frame > self.max_time_lost:
                track.mark_removed()
                removed_stracks.append(track)

        # print('Ramained match {} s'.format(t4-t3))

        self.tracked_stracks = [t for t in self.tracked_stracks if t.state == TrackState.Tracked]
        self.tracked_stracks = joint_stracks(self.tracked_stracks, activated_starcks)
        self.tracked_stracks = joint_stracks(self.tracked_stracks, refind_stracks)
        self.lost_stracks = sub_stracks(self.lost_stracks, self.tracked_stracks)
        self.lost_stracks.extend(lost_stracks)
        self.lost_stracks = sub_stracks(self.lost_stracks, self.removed_stracks)
        self.removed_stracks.extend(removed_stracks)
        self.tracked_stracks, self.lost_stracks = remove_duplicate_stracks(self.tracked_stracks, self.lost_stracks)
        # get scores of lost tracks
        output_stracks = [track for track in self.tracked_stracks if track.is_activated]

        return output_stracks

修复python代码

在removed_stracks后面添加类似c++的处理方式

        self.removed_stracks.extend(removed_stracks)
        self.removed_stracks = [track for track in self.removed_stracks if
                                self.frame_id - track.end_frame < 10 * self.max_time_lost]

http://www.kler.cn/a/324611.html

相关文章:

  • 了解 Solon MVC 的参数注入规则
  • <websocket><PLC>使用js和html实现webscoket,与PLC进行socket通讯的实例
  • Three.js PBR材质
  • 【一键整合包及教程】AI照片数字人工具EchoMimic技术解析
  • Android CALL按键同步切换通话界面上免提和听筒的图标显示
  • 【linux学习指南】VSCode部署Ubantu云服务器,与Xshell进行本地通信文件编写
  • 时间安全精细化管理平台/iapp/mobile/facereg/facereg.html接口存在未授权访问漏洞
  • 类与对象—python
  • ERP系统委外工单管理
  • java NIO实现UDP通讯
  • - 串口通信
  • 多线程篇八
  • SpringBoot集成阿里easyexcel(二)Excel监听以及常用工具类
  • 阴影的基本原理
  • 梳理一下C语言中的格式说明符
  • uniapp js判断key是否在json中?
  • ArcgisEngine开发中,Ifeatureclass.Addfield 报错0x80040655处理方法
  • 0基础学习CSS(六)字体
  • python-list-comprehension-three-way-partitioning-array-around-given-range
  • iText 5 通过创建 Document 对象,并使用 PdfWriter 将内容写入 PDF 文件
  • ubuntu重新安装clickhouse
  • 前端面试题(九)
  • 【Mybatis】常见面试题汇总 共56题
  • 复试经验分享《一、问答题自测》(408、相关前沿技术)
  • 在Kali Linux VNC服务器上安装RDP服务
  • Android使用RecyclerView仿美团分类界面