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

替换SlowFast中Detectron2为Yolov8

一 需求

FaceBookReserch中SlowFast源码中检测框是用Detectron2进行目标检测,本文想实现用yolov8替换detectron2

二 实施方案

首先,yolov8 支持有自定义库ultralytics(仅支持yolov8),安装对应库

pip install ultralytics

源码中slowfast/visualization.py 43行中

if cfg.DETECTION.ENABLE:self.object_detector = Detectron2Predictor(cfg, gpu_id=self.gpu_id)

根据ultralytics文档进行定义
创建对应YOLOPredictor类(加入了检测框及其标签,具体见前一篇文章)

class YOLOPredictor:def __init__(self, cfg, gpu_id=None):# 加载预训练的 YOLOv8n 模型self.model = YOLO('/root/autodl-tmp/data/runs/detect/train/weights/best.pt')self.detect_names, _, _ = get_class_names(cfg.DEMO.Detect_File_Path, None, None)def __call__(self, task):"""Return bounding boxes predictions as a tensor.Args:task (TaskInfo object): task object that containthe necessary information for action prediction. (e.g. frames)Returns:task (TaskInfo object): the same task info object but filled withprediction values (a tensor) and the corresponding boxes foraction detection task."""# """得到预测置信度"""# scores = outputs["instances"].scores[mask].tolist()# """获取类别标签"""# pred_labels = outputs["instances"].pred_classes[mask]# pred_labels = pred_labels.tolist()# """进行标签匹配"""# for i in range(len(pred_labels)):#     pred_labels[i] = self.detect_names[pred_labels[i]]# preds = [#     "[{:.4f}] {}".format(s, labels) for s, labels in zip(scores, pred_labels)# ]# """加入预测标签"""# task.add_detect_preds(preds)# task.add_bboxes(pred_boxes)middle_frame = task.frames[len(task.frames) // 2]outputs = self.model(middle_frame)boxes = outputs[0].boxesmask = boxes.conf >= 0.5pred_boxes = boxes.xyxy[mask]scores = boxes.conf[mask].tolist()pred_labels = boxes.cls[mask].to(torch.int)pred_labels = pred_labels.tolist()for i in range(len(pred_labels)):pred_labels[i] = self.detect_names[pred_labels[i]]preds = ["[{:.4f}] {}".format(s, labels) for s, labels in zip(scores, pred_labels)]"""加入预测标签"""task.add_detect_preds(preds)task.add_bboxes(pred_boxes)return task
http://www.lryc.cn/news/234664.html

相关文章:

  • 轻量化网络--MobileNet V1
  • gittee启动器
  • Spark数据倾斜_产生原因及定位处理办法_生产环境
  • 2023OceanBase年度发布会后,有感
  • ubuntu18.04中代码迁移到20.04报错
  • QQ五毛项目记
  • 小程序实现登录持久化
  • 2023年亚太杯数学建模思路 - 案例:ID3-决策树分类算法
  • C复习-输入输出函数+流
  • duplicate复制数据库单个数据文件复制失败报错rman-03009 ora-03113
  • golang 解析oracle 数据文件头
  • van-popup滑动卡顿并且在有时候在ios上经常性滑动卡顿的情况
  • YOLOv7独家原创改进:最新原创WIoU_NMS改进点,改进有效可以直接当做自己的原创改进点来写,提升网络模型性能精度
  • ubuntu20.04中编译zlib1.2.11(源码编译)
  • 计算机毕业设计选题推荐-高校后勤报修微信小程序/安卓APP-项目实战
  • 如何零基础自学AI人工智能
  • pm2使用
  • 在Ubuntu或linux中为coreutils工具包的cp和mv命令添加进度条
  • 力扣-58. 最后一个单词的长度
  • 快递鸟荣获全球电子商务创业创新大赛总决赛一等奖
  • 阶段七-Day02-SpringMVC
  • YOLOv5独家原创改进:最新原创WIoU_NMS改进点,改进有效可以直接当做自己的原创改进点来写,提升网络模型性能精度
  • 【深度学习】pytorch快速得到mobilenet_v2 pth 和onnx
  • 高防CDN安全防护系统在业务方面的应用
  • opencv(3):控制鼠标,创建 tackbar控件
  • UE4动作游戏实例RPG Action解析二:GAS系统播放武器绑定的技能,以及GE效果
  • 做完这些_成为机器学习方面的专家
  • kubernetes|云原生| 如何优雅的重启和更新pod---pod生命周期管理实务
  • 【总结】坐标变换和过渡矩阵(易忘记)
  • 第十一周任务总结