train.py报错

下载好yolov5,跑train.py报错,用debug跳到了__init__.py小面图片小闪电这个位置,不知道怎么改,最下面的代码是运行train.py的报错。

img

Traceback (most recent call last):
  File "D:\xunlei\ANACADON3\envs\pytorch\lib\site-packages\git\__init__.py", line 89, in <module>
    refresh()
  File "D:\xunlei\ANACADON3\envs\pytorch\lib\site-packages\git\__init__.py", line 76, in refresh
    if not Git.refresh(path=path):
  File "D:\xunlei\ANACADON3\envs\pytorch\lib\site-packages\git\cmd.py", line 392, 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()

All git commands will error until this is rectified.

This initial warning 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|none|n|0: for no warning or exception
    - warn|w|warning|1: for a printed warning
    - error|e|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 "D:\2anaconda\yolov5-master\train.py", line 72, in <module>
    GIT_INFO = check_git_info()
  File "D:\xunlei\ANACADON3\envs\pytorch\lib\contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "D:\2anaconda\yolov5-master\utils\general.py", line 360, in check_git_info
    import git
  File "D:\xunlei\ANACADON3\envs\pytorch\lib\site-packages\git\__init__.py", line 91, 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()

All git commands will error until this is rectified.

This initial warning 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|none|n|0: for no warning or exception
    - warn|w|warning|1: for a printed warning
    - error|e|raise|r|2: for a raised exception

Example:
    export GIT_PYTHON_REFRESH=quiet


进程已结束,退出代码1


是不是git环境变量没配置正确?

ImportError: Bad git executable.
git没有装对吧。

这个报错是说没有找到git可执行文件,你先确认一下电脑装了官方git没有

如果有的话,看下有没有环境变量

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 这篇博客: YOLOv5代码详解(train.py部分)中的 1.5 创建模型 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
    # Create model
        model = Model(opt.cfg).to(device)
        assert model.md['nc'] == nc, '%s nc=%g classes but %s nc=%g classes' % (opt.data, nc, opt.cfg, model.md['nc'])
        model.names = data_dict['names']
    

    assert是一个判断表达式,在assert后面成立时创建模型。

    参考链接

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^