当前位置: 首页 > 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/news/324611.html

相关文章:

  • 时间安全精细化管理平台/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仿美团分类界面
  • 【JavaEE】——阻塞队列,生产消费者模型(较难)
  • BACnet协议-(基于ISO 8802-3 UDP)(2)
  • 【系统方案】智慧城市大数据平台建设方案(Word)
  • 【小程序websocket最佳实践,有心跳和断线重连】
  • JD面试题
  • huggingface实现中文文本分类
  • Gitee基本指令操作
  • 若依生成主子表
  • 前端框架:选择的艺术
  • IP地址不足