训练yolov9出现warning:TensorBoard graph visualization failure Only tensors解决方法

问题

在这里插入图片描述

  • 在训练yolov9的过程中,出现了 TensorBoard 图形可视化失败的警告:“TensorBoard graph visualization failure Only tensors, lists, tuples of tensors, or dictionary of tensors can be output from traced functions”。
  • 意思是在使用 TensorBoard 进行图形可视化时,某个被追踪的函数的输出不是张量、张量的列表、元组或字典。
  • 这是一个警告,并不影响训练,但是会使打开的tensorboard中的仪表盘中没有graphs。

解决办法

按照github上的issues里面有大佬提出的解决方案进行操作。
链接:https://github.com/WongKinYiu/yolov9/issues/195
下面我将展示具体如何操作:
在这里插入图片描述

  1. 打开yolov9/utils/loggers/__init__.py
    在这里插入图片描述

  2. 把这段代码注释掉
    在这里插入图片描述

  3. 在注释掉的代码下面添加以下代码(其实就是将log_tensorboard_graph函数替换掉了)

def log_tensorboard_graph(tb, model, imgsz=(640, 640)):
    # Log model graph to TensorBoard
    try:
        p = next(model.parameters())  # for device, type
        imgsz = (imgsz, imgsz) if isinstance(imgsz, int) else imgsz  # expand
        im = torch.zeros((1, 3, *imgsz), device=p.device, dtype=p.dtype)  # input image (WARNING: must be zeros, not empty)
        model = deepcopy(de_parallel(model))
        model.eval()
        model = model.fuse()
        for m in model.modules():
            if hasattr(m, "export"):
                m.export = True
                m.format = "torchscript"
        model(im)  # dry run
        tb.add_graph(torch.jit.trace(model, im, strict=False), [])
        LOGGER.info(f"Model graph visualization added ✅")
    except Exception as e:
        LOGGER.warning(f'WARNING ⚠️ TensorBoard graph visualization failure {e}')
  1. 还要再引入deepcopy,下面这行代码添加在文件开头
from copy import deepcopy

输出结果

再次运行训练命令,出现以下输出,问题解决!
在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值