运行DeepSORT_YOLOv5_Pytorch时出现的问题


前言

记录一下复现GitHub中以下这份代码时出现的一些问题。
代码链接:https://github.com/HowieMa/DeepSORT_YOLOv5_Pytorch/tree/master

问题1:Loader=yaml.FullLoader

【问题描述】

self.update(yaml.load(fo.read()))
TypeError: load() missing 1 required positional argument: 'Loader'

【解决方式】
找到deep_sort文件夹下的utils文件夹中的parser.py文件,将两处 cfg_dict.update(yaml.load(fo.read())) 改为 cfg_dict.update(yaml.load(fo, Loader=yaml.FullLoader))

在这里插入图片描述


问题2:utils. -> yolov5.utils.

【问题描述】

from utils.general import check_anchor_order, make_divisible, check_file
ModuleNotFoundError: No module named 'utils.general'

from utils.torch_utils import (
    time_synchronized, fuse_conv_and_bn, model_info, scale_img, initialize_weights, select_device)
ModuleNotFoundError: No module named 'utils.torch_utils'

【解决方式】
找到yolov5文件夹下的models文件夹中的yolo.py文件,将

from utils.general import check_anchor_order, make_divisible, check_file
from utils.torch_utils import (
    time_synchronized, fuse_conv_and_bn, model_info, scale_img, initialize_weights, select_device)

改为

from yolov5.utils.general import check_anchor_order, make_divisible, check_file
from yolov5.utils.torch_utils import (
    time_synchronized, fuse_conv_and_bn, model_info, scale_img, initialize_weights, select_device)

问题3:np.float -> float

【问题描述】

<class 'AttributeError'> module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.

【解决方式】
找到deep_sort文件夹下的sort文件夹中的detection.py文件和preprocessing.py文件,分别将30行代码和第40行代码中的np.float改为float


问题4:np.int -> int

【问题描述】

<class 'AttributeError'> module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` 

【解决方式】
找到deep_sort文件夹下的deep_sort.py文件,将第67行代码中的np.int 改为int


问题5:ImportError: cannot import name ‘time_synchronized’ from ‘yolov5.utils.torch_utils’

【问题描述】

from yolov5.utils.torch_utils import select_device, time_synchronized
ImportError: cannot import name 'time_synchronized' from 'yolov5.utils.torch_utils' 

【解决方式】
main.py中的

from yolov5.utils.torch_utils import select_device, time_synchronized

改为

from yolov5.utils.torch_utils import select_device, time_sync

time_synchronized()改为time_sync()
在这里插入图片描述


<think>好的,我现在需要帮助用户解决在PyCharm中安装deep_sort包的问题。用户已经提供了几个站内引用,我需要仔细分析这些引用,并结合之前的对话内容来给出合适的解决方案。 首先,用户之前尝试通过pip install deep_sort安装失败,因为该包不在PyPI上。之前的回答建议从GitHub克隆仓库或者安装替代库如deep-sort-realtime。现在用户的新问题是如何在PyCharm中成功安装deep_sort,包括依赖和环境配置,并参考了提供的引用内容。 接下来,我需要查看用户提供的引用内容: 引用[1]提到克隆一个GitHub仓库,并安装依赖,创建虚拟环境。引用[2]和[3]涉及使用Anaconda创建虚拟环境,安装mmcv等依赖,可能与环境配置有关。引用[4]和[5]强调了使用requirements.txt安装依赖,特别是通过conda和pip安装。 综合这些信息,用户可能是在尝试配置一个包含YOLOv5DeepSORT的项目,需要正确设置环境和依赖。关键点包括:创建虚拟环境,从源码安装deep_sort,处理可能的依赖冲突,以及正确配置项目结构。 现在需要将这些步骤整合成一个清晰的指南,适用于PyCharm环境。需要注意PyCharm中的终端使用、虚拟环境设置、以及如何安装本地包。同,用户可能遇到的常见问题包括路径错误、依赖版本不匹配、权限问题等,需要提前给出解决方案。 可能的步骤包括: 1. 在PyCharm中创建虚拟环境。 2. 克隆或下载deep_sort源码到项目目录。 3. 安装依赖项,可能需要通过requirements.txt或手动安装。 4. 处理环境变量或特定库的编译问题,如mmcv-full。 5. 验证安装是否正确。 同,需要参考用户提供的引用,比如使用conda激活环境,安装requirements.txt中的依赖,以及处理mmcv的编译步骤。此外,用户可能混淆了deep_sort的不同实现,需要明确指导正确的仓库地址,如ZQPei的PyTorch版本。 最后,确保回答结构清晰,分步骤说明,并包含常见问题解决方法,帮助用户逐步完成安装和配置。</think>### 在PyCharm中安装`deep_sort`的完整解决方案(附环境配置) --- #### **1. 明确`deep_sort`的安装本质** 根据引用[1][3][4],`deep_sort`并非PyPI官方库,而是**需要源码安装的本地模块**。以下是关键步骤: --- #### **2. 创建PyCharm虚拟环境(核心步骤)** 通过引用[3][4]的指导,建立隔离环境避免依赖冲突: 1. **新建项目配置环境**: - 打开PyCharm → `File` → `New Project` - 在`Location`选择项目路径,`Python Interpreter`选择`New Environment` → `Virtualenv`或`Conda` ![PyCharm环境配置示意图](https://via.placeholder.com/600x400?text=PyCharm+New+Project+Setup) 2. **手动激活现有环境**(若已创建): - 打开PyCharm终端(底部`Terminal`选项卡) ```bash conda create -n deepsort python=3.8 # 引用[3]的conda命令 conda activate deepsort ``` --- #### **3. 安装`deep_sort`源码(关键操作)** 根据引用[1][5],正确获取源码并配置路径: 1. **克隆官方仓库到项目目录**: ```bash git clone https://github.com/ZQPei/deep_sort_pytorch.git # 推荐PyTorch适配版 mv deep_sort_pytorch/deep_sort ./ # 将模块移动到项目根目录 ``` *注意:必须确保项目目录中存在`deep_sort`文件夹(参考引用[4]的依赖结构)* 2. **手动下载(备用方案)**: - 访问GitHub仓库 [deep_sort_pytorch](https://github.com/ZQPei/deep_sort_pytorch) → 下载ZIP → 解压到项目目录 --- #### **4. 安装依赖库(版本敏感)** 根据引用[2][4][5],通过`requirements.txt`安装核心依赖: 1. **在PyCharm终端执行**: ```bash pip install -r requirements.txt # 确保文件包含以下关键库[^5] ``` *若项目无requirements.txt,手动安装以下依赖*: ```bash pip install numpy scipy opencv-python sklearn pillow pyyaml easydict pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113 # CUDA版本 ``` 2. **特殊库处理(如mmcv)**: 引用[2]中提到的`mmcv-full`需编译安装: ```bash cd mmcv-full-1.3.17 # 进入下载的mmcv目录 $env:TORCH_CUDA_ARCH_LIST="6.1" # Windows设置环境变量 pip install -r requirements/runtime.txt python setup.py build_ext # 编译 python setup.py develop ``` --- #### **5. 验证安装与路径配置** 1. **检查模块导入**: 在PyCharm中新建Python文件,输入: ```python try: from deep_sort import DeepSort print(">>> deep_sort 导入成功!") except ImportError as e: print(f">>> 错误: {e}") ``` 2. **解决路径问题**: - 若报错`ModuleNotFoundError`,右击`deep_sort`文件夹 → `Mark Directory as` → `Sources Root` ![标记源码目录示意图](https://via.placeholder.com/600x400?text=Mark+as+Sources+Root) --- #### **6. 常见问题与解决** | 问题现象 | 解决方案 | 相关引用 | |---------|---------|---------| | `No module named 'box_utils'` | 将`deep_sort/utils/`添加到系统路径 | [^5] | | CUDA版本不匹配 | 使用`conda install cudatoolkit=11.3` | [^2] | | 权限不足错误 | 以管理员身份运行PyCharm或终端 | [^2] | --- ### 关键提示 - **环境隔离**:务必使用虚拟环境(如引用[3][4]所述),避免污染全局Python环境 - **版本对齐**:PyTorch、CUDA、mmcv需版本匹配(参考引用[2]的编译参数) - **项目结构**:确保`deep_sort`目录与主代码同级(参考引用[1]的克隆操作) --- ### 测试代码(目标跟踪示例) ```python from deep_sort import DeepSort deepsort = DeepSort( model_path="deep_sort/deep/checkpoint/ckpt.t7", # 模型路径 max_dist=0.2, min_confidence=0.3 ) print(">>> DeepSORT初始化成功!") ``` --- ### 相关问题 1. 如何在PyCharm中修复`ImportError: cannot import name 'generate_detections'`错误? 2. 如何为DeepSORT配置自定义的目标检测模型(如YOLOv5)? 3. 在Windows系统编译mmcv-full如何避免CL编译器错误?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值