yolo5---运行报错记录

报错1: ImportError: cannot import name 'TryExcept' from 'utils'

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/IPython/core/interactiveshell.py", line 3550, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-388ad7e07587>", line 1, in <module>
    runfile('/media/pi/Lexar3/python_test/Visual_Test/models/yolo.py', wdir='/media/pi/Lexar3/python_test/Visual_Test/models')
  File "/home/pi/Downloads/pycharm-2024.1/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/Downloads/pycharm-2024.1/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/media/pi/Lexar3/python_test/Visual_Test/models/yolo.py", line 24, in <module>
    from models.common import *  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/Downloads/pycharm-2024.1/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/media/pi/Lexar3/python_test/Visual_Test/models/common.py", line 49, in <module>
    from utils import TryExcept
ImportError: cannot import name 'TryExcept' from 'utils' (/media/pi/Lexar3/python_test/utils.py)

报错原因:因为打开目录不是yolov5的根目录,所以找不到yolov5文件夹下的utils模块

解决方案1:直接把文件夹名字加上

 
from utils import TryExcept, emojis
from utils.downloads import gsutil_getsize
from utils.metrics import box_iou, fitness
改成
from <.utils所在的文件夹名>.utils import TryExcept, emojis
from <.utils所在的文件夹名>.utils.downloads import gsutil_getsize
from <.utils所在的文件夹名>.utils.metrics import box_iou, fitness

解决方案2:直接打开源代码所在的文件夹

报错2:All git commands will error until this is rectified.

WARNING:tensorflow:From C:\Users\23665\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.

Traceback (most recent call last):
  File "C:\Users\23665\AppData\Local\Programs\Python\Python311\Lib\site-packages\git\__init__.py", line 296, in <module>
    refresh()
  File "C:\Users\23665\AppData\Local\Programs\Python\Python311\Lib\site-packages\git\__init__.py", line 287, in refresh
    if not Git.refresh(path=path):
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\23665\AppData\Local\Programs\Python\Python311\Lib\site-packages\git\cmd.py", line 631, in refresh
    raise ImportError(err)
ImportError: Bad git executable.
The git executable must be specified in one of the following ways:
    - be included in your $PATH
    - be set via $GIT_PYTHON_GIT_EXECUTABLE
    - explicitly set via git.refresh(<full-path-to-git-executable>)

All git commands will error until this is rectified.

This initial message can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
    - quiet|q|silence|s|silent|none|n|0: for no message or exception
    - warn|w|warning|log|l|1: for a warning message (logging level CRITICAL, displayed by default)
    - error|e|exception|raise|r|2: for a raised exception

Example:
    export GIT_PYTHON_REFRESH=quiet


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\python_test\Visual_Test\train.py", line 72, in <module>
    GIT_INFO = check_git_info()
               ^^^^^^^^^^^^^^^^
  File "C:\Users\23665\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "E:\python_test\Visual_Test\utils\general.py", line 370, in check_git_info
    import git
  File "C:\Users\23665\AppData\Local\Programs\Python\Python311\Lib\site-packages\git\__init__.py", line 298, in <module>
    raise ImportError("Failed to initialize: {0}".format(_exc)) from _exc
ImportError: Failed to initialize: Bad git executable.
The git executable must be specified in one of the following ways:
    - be included in your $PATH
    - be set via $GIT_PYTHON_GIT_EXECUTABLE
    - explicitly set via git.refresh(<full-path-to-git-executable>)

All git commands will error until this is rectified.

This initial message can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
    - quiet|q|silence|s|silent|none|n|0: for no message or exception
    - warn|w|warning|log|l|1: for a warning message (logging level CRITICAL, displayed by default)
    - error|e|exception|raise|r|2: for a raised exception

Example:
    export GIT_PYTHON_REFRESH=quiet

保存原因:git环境变量设置问题

解决·方案:在导入包的上方增加以下代码 

import os
os.environ["GIT_PYTHON_REFRESH"] = "quiet"

报错3:cv2.error: OpenCV(4.8.1) /io/opencv/modules/imgcodecs/src/loadsave.cpp:802: error: (-215:Assertion failed) !buf.empty() in function 'imdecode_'

(注:报错原因:我在使用绿联hdmi采集卡进行图像采集时所遇到的问题。)

M_predict_test: weights=yolov5s.pt, source=0, data=data/coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_csv=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs/detect, name=exp, exist_ok=False, line_thickness=1, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=180
YOLOv5 🚀 f573f3b Python-3.11.2 torch-2.1.2 CPU
Fusing layers... 
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients, 16.4 GFLOPs
WARNING ⚠️ Environment does not support cv2.imshow() or PIL Image.show()
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/IPython/core/interactiveshell.py", line 3550, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-148bbbd5c4c3>", line 1, in <module>
    runfile('/media/pi/Lexar3/python_test/Visual_Test/M_predict_test.py', wdir='/media/pi/Lexar3/python_test/Visual_Test')
  File "/home/pi/Downloads/pycharm-2024.1/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/Downloads/pycharm-2024.1/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/media/pi/Lexar3/python_test/Visual_Test/M_predict_test.py", line 428, in <module>
    main(opt)
  File "/media/pi/Lexar3/python_test/Visual_Test/M_predict_test.py", line 423, in main
    run(**vars(opt))
  File "/home/pi/.local/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/media/pi/Lexar3/python_test/Visual_Test/M_predict_test.py", line 174, in run
    dataset = LoadStreams(source, img_size=imgsz, stride=stride, auto=pt, vid_stride=vid_stride)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/media/pi/Lexar3/python_test/Visual_Test/utils/dataloaders.py", line 379, in __init__
    _, self.imgs[i] = cap.read()  # guarantee first frame
                      ^^^^^^^^^^
cv2.error: OpenCV(4.8.1) /io/opencv/modules/imgcodecs/src/loadsave.cpp:802: error: (-215:Assertion failed) !buf.empty() in function 'imdecode_'

解决方案:hdmi采集卡与摄像头断开再重新连接

  • 24
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
YOLO系列是基于深度学习的端到端实时目标检测方法。 PyTorch版的YOLOv5轻量而高性能,更加灵活和易用,当前非常流行。 本课程将手把手地教大家使用labelImg标注和使用YOLOv5训练自己的数据集。课程实战分为两个项目:单目标检测(足球目标检测)和多目标检测(足球和梅西同时检测)。  本课程的YOLOv5使用ultralytics/yolov5,在Windows和Ubuntu系统上分别做项目演示。包括:安装YOLOv5、标注自己的数据集、准备自己的数据集(自动划分训练集和验证集)、修改配置文件、使用wandb训练可视化工具、训练自己的数据集、测试训练出的网络模型和性能统计。 除本课程《YOLOv5实战训练自己的数据集(Windows和Ubuntu演示)》外,本人推出了有关YOLOv5目标检测的系列课程。请持续关注该系列的其它视频课程,包括:《YOLOv5(PyTorch)目标检测:原理与源码解析》课程链接:https://edu.csdn.net/course/detail/31428《YOLOv5目标检测实战:Flask Web部署》课程链接:https://edu.csdn.net/course/detail/31087《YOLOv5(PyTorch)目标检测实战:TensorRT加速部署》课程链接:https://edu.csdn.net/course/detail/32303《YOLOv5目标检测实战:Jetson Nano部署》课程链接:https://edu.csdn.net/course/detail/32451《YOLOv5+DeepSORT多目标跟踪与计数精讲》课程链接:https://edu.csdn.net/course/detail/32669《YOLOv5实战口罩佩戴检测》课程链接:https://edu.csdn.net/course/detail/32744《YOLOv5实战中国交通标志识别》课程链接:https://edu.csdn.net/course/detail/35209 《YOLOv5实战垃圾分类目标检测》课程链接:https://edu.csdn.net/course/detail/35284  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值