问题
yolov9训练出现下面警告:
WARNING TensorBoard graph visualization failure Only tensors, lists, tuples of tensors, or dictionary of tensors can be output from traced functions
这句话意思就是:警告:TensorBoard图形可视化失败,仅允许从跟踪函数输出张量、张量列表、张量元组或张量字典。简单来说打开的tensorboard中的仪表盘中没有graphs。
解决方法
1.打开utils/loggers/init.py
2.找到log_tensorboard_graph方法,大概381行,注释该方法,换成新的,新的代码如下:
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)
from copy import deepcopy
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}')
验证
终端TensorBoard看看是否有结构图,命令如下
tensorboard --logdir=runs/train
成功显示
总结
创作不易,对你有帮助点个小爱心,谢谢