162: DeprecationWarning: The numpy.linalg.linalg has been made private and renamed to numpy.linalg._linalg. All public functions exported by it are available from numpy.linalg. Please use numpy.linalg.svd instead. rot,transGT,trans_errorGT,trans,trans_error, scale = align(second_xyz,first_xyz) /home/gyh/ORB_SLAM3/Examples/../evaluation/evaluate_ate_scale.py:85: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.) s = float(dots/norms) Traceback (most recent call last): File "/home/gyh/ORB_SLAM3/Examples/../evaluation/evaluate_ate_scale.py", line 168, in <module> first_stamps.sort() AttributeError: 'dict_keys' object has no attribute 'sort'
时间: 2025-07-14 17:52:17 浏览: 3
<think>好的,我现在需要解决用户提到的几个问题:DeprecationWarning和AttributeError,具体涉及numpy的linalg模块、_linalg属性错误、dict_keys对象的排序问题,以及ORB_SLAM3中的evaluate_ate_scale.py的解决方案。让我分步骤思考。
首先,用户遇到了DeprecationWarning,可能与numpy的某些函数或模块被弃用有关。例如,numpy.linalg中的某些子模块可能在较新版本中被重新组织或重命名,导致警告。比如,用户可能导入了numpy.linalg._linalg,但新版本中这个内部模块可能不再公开,所以会抛出DeprecationWarning。正确的做法应该是使用公开的API,比如直接使用numpy.linalg中的函数,而不是内部模块。
其次,AttributeError: 'Generator' object has no attribute 'randint'。根据引用[2],用户可能在代码中使用了numpy.random.Generator对象的randint方法,但正确的名称是integers。因为在numpy的新版本中,Generator的randint被重命名为integers,所以需要将代码中的randint替换为integers。例如,将np.random.default_rng().randint(...)改为np.random.default_rng().integers(...)。
接下来是dict_keys对象没有sort属性的问题。在Python 3中,dict.keys()返回的是一个视图对象,而不是列表,因此没有sort方法。用户可能需要将dict_keys转换为列表后再排序。例如,使用sorted(keys)或者list(keys).sort(),但后者需要先转换为列表。
关于ORB_SLAM3的evaluate_ate_scale.py的问题,可能涉及到脚本中的某些代码与新版本的库不兼容。比如,可能使用了旧版本的numpy函数,或者数据结构发生了变化。需要具体查看错误信息,但常见的解决方法包括更新脚本中的API调用,或者调整数据处理的步骤,确保使用当前库版本的正确方法。
综合以上分析,用户的问题可能源于版本升级导致的API变化,如numpy中的Generator方法更名,内部模块的弃用,以及Python 3中字典视图对象的处理。解决方案包括替换弃用的方法名,避免使用内部模块,转换数据类型,以及更新脚本代码。</think>### 问题解决方案
#### 1. **DeprecationWarning 与 AttributeError 问题**
**问题原因与解决方案:**
- **`numpy.linalg._linalg` 弃用警告**
NumPy 1.20+ 版本中,内部模块 `_linalg` 被重构,直接调用会触发警告。应改用公开接口 `numpy.linalg` 中的标准函数(如 `np.linalg.eig`)[^1]。
**错误示例:**
```python
from numpy.linalg import _linalg # 触发警告
```
**修正后:**
```python
from numpy.linalg import eig # 正确导入
```
- **`Generator` 对象没有 `randint` 属性**
NumPy 1.17+ 引入新的随机数生成器 API,`randint` 方法更名为 `integers`[^2]。
**错误示例:**
```python
rng = np.random.default_rng()
rng.randint(0, 10) # 触发 AttributeError
```
**修正后:**
```python
rng = np.random.default_rng()
rng.integers(0, 10) # 正确调用
```
#### 2. **`dict_keys` 对象排序问题**
**问题原因与解决方案:**
Python 3 中 `dict.keys()` 返回视图对象而非列表,需显式转换为列表后再排序。
**错误示例:**
```python
d = {"a": 1, "b": 2}
keys = d.keys()
keys.sort() # 触发 AttributeError
```
**修正后:**
```python
keys = list(d.keys()) # 转换为列表
keys.sort() # 或直接使用 sorted(d.keys())
```
#### 3. **ORB_SLAM3 `evaluate_ate_scale.py` 脚本问题**
**常见问题与解决方案:**
- **依赖库版本不兼容**
检查脚本中使用的 NumPy、Matplotlib 等库的版本,确保与 ORB_SLAM3 要求的版本一致。例如,旧脚本可能依赖 `numpy.matrix`,而新版本推荐使用 `numpy.ndarray`。
- **数据类型转换错误**
若出现类似 `TypeError: Expected sequence or array-like, got <class 'pandas.core.series.Series'>`,需将数据显式转换为 NumPy 数组:
```python
import numpy as np
data = np.array(data_series) # 转换为 ndarray
```
---
### 代码修正示例
**场景:解决 `Generator` 与 `dict_keys` 问题**
```python
import numpy as np
# 修正随机数生成器调用
rng = np.random.default_rng()
random_int = rng.integers(0, 100) # 使用 integers 替代 randint
# 修正字典键排序
data = {"z": 3, "a": 1, "b": 2}
sorted_keys = sorted(data.keys()) # 直接排序视图对象
print(sorted_keys) # 输出: ['a', 'b', 'z']
```
---
### 相关问题
1. **如何检查 NumPy 函数的弃用状态?**
2. **Python 中字典视图对象与列表有何区别?**
3. **如何避免 ORB_SLAM3 脚本的版本兼容性问题?**
: NumPy 官方文档建议使用公开的 `numpy.linalg` 接口,避免直接调用内部模块。
: NumPy 1.17 版本后,随机数生成器的 API 更名,需使用 `integers` 替代 `randint`。
阅读全文
相关推荐



















