linux_甦生 2025-03-09 20:24 采纳率: 0%
浏览 43

ubuntu20.04 yolov5 训练

ubuntu20.04
conda create -n mouse python==3.9 环境训练yolov5 v7.0

执行python train.py 最后提示:

Traceback (most recent call last):
  File "/home/zcz/workprj/rknn/yolov5v70/train.py", line 634, in <module>
    main(opt)
  File "/home/zcz/workprj/rknn/yolov5v70/train.py", line 528, in main
    train(opt.hyp, opt, device, callbacks)
  File "/home/zcz/workprj/rknn/yolov5v70/train.py", line 408, in train
    strip_optimizer(f)  # strip optimizers
  File "/home/zcz/workprj/rknn/yolov5v70/utils/general.py", line 1004, in strip_optimizer
    x = torch.load(f, map_location=torch.device('cpu'))
  File "/home/zcz/anaconda3/envs/mouse/lib/python3.9/site-packages/torch/serialization.py", line 1470, in load
    raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. 
    (1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
    (2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
    WeightsUnpickler error: Unsupported global: GLOBAL numpy._core.multiarray._reconstruct was not an allowed global by default. Please use `torch.serialization.add_safe_globals([_reconstruct])` or the `torch.serialization.safe_globals([_reconstruct])` context manager to allowlist this global if you trust this class/function.


Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.
  • 写回答

3条回答 默认 最新

  • 阿里嘎多学长 2025-03-09 20:24
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    Yolov5 训练在 Ubuntu 20.04 中遇到错误

    你使用 conda 创建了一个名为 mouse 的虚拟环境,并安装了 Python 3.9。然后,你尝试训练 Yolov5 v7.0 模型,但是最后遇到了错误。

    错误信息中显示了 Traceback,这意味着 Python 发生了错误。可能的原因是 yolov5 依赖项没有正确安装或配置。

    可以尝试以下解决方案:

    1. 检查 yolov5 依赖项是否正确安装:
    conda activate mouse
    pip install -r requirements.txt
    

    其中,requirements.txt 是 yolov5 项目中的依赖项文件。

    1. 检查 Python 版本是否正确:
    python --version
    

    如果 Python 版本不正确,可以尝试使用 conda 安装正确的 Python 版本。

    1. 检查 yolov5 代码是否正确:
    python train.py --help
    

    如果 yolov5 代码正确,这个命令应该显示帮助信息。

    如果以上解决方案不起作用,可以提供更多错误信息或 yolov5 项目的详细信息,以便更好地帮助你解决问题。

    评论

报告相同问题?

问题事件

  • 创建了问题 3月9日