成功解决ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
在win11电脑上运行ultralytics代码时遇到报错:
UserWarning: Failed to initialize NumPy: DLL load failed while importing _multiarray_umath: 找不到指定的模块。 (Triggered internally at C:\actions-runner\_work\pytorch\pytorch\pytorch\torch\csrc\utils\tensor_numpy.cpp:81.)cpu = _conversion_method_template(device=torch.device("cpu"))
ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
应该是conda环境下和pip安装路径的问题,只需要先卸载pip安装的numpy,再使用conda安装一次即可。
pip uninstall numpy
conda install numpy
继续遇到numpy新问题:
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.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
这个错误是由于你使用的代码(或依赖的库)中使用了 np.float,而 NumPy 1.20+ 已移除了 np.float 这个 deprecated(弃用)的别名,它原本是 Python 内置 float 的别名。解决方法很简单,核心是将代码中的 np.float 替换为正确的类型。
这个时候就需要你根据代码的实际情况去除np.float中的np了。比如终端报错输出:
ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=np.float)
需要改为:
ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=float)