python - Numpy 连接错误 (np.concatenate)
问题描述
我试图data_prepare_s3dis.py
从Github repo运行。我收到一个data_list
似乎是空列表的错误,即使它包含数组集合。
错误信息
Traceback (most recent call last):
File "utils/data_prepare_s3dis.py", line 87, in <module>
convert_pc2ply(annotation_path, join(original_pc_folder, out_file_name))
File "utils/data_prepare_s3dis.py", line 53, in convert_pc2ply
pc_label = np.concatenate(data_list, 0)
ValueError: need at least one array to concatenate
检查
所以我通过打印出 data_list 来检查 data_list 的内容。让我感到困惑的是,这似乎data_list
是一个列表,其中包含来自打印结果的数组列表集合(如附件)。
尽管打印出了数组,但我仍然得到一个空列表(倒数第二行),我相信这是导致错误的结果。
for f in glob.glob(join(anno_path, '*.txt')):
class_name = os.path.basename(f).split('_')[0]
if class_name not in gt_class: # note: in some room there is 'stairs' class..
class_name = 'clutter'
pc = pd.read_csv(f, header=None, delim_whitespace=True).values
labels = np.ones((pc.shape[0], 1)) * gt_class2label[class_name]
print(data_list) #Checkpoint: where the data_list printed the arrays
data_list.append(np.concatenate([pc, labels], 1)) # Nx7
# Checkpoint: To check the data_list
print(data_list)
if not data_list:
print("data_list is empty")
pc_label = np.concatenate(data_list, 0)
xyz_min = np.amin(pc_label, axis=0)[0:3]
pc_label[:, 0:3] -= xyz_min
pc_label = np.concatenate(data_list, 0)
xyz_min = np.amin(pc_label, axis=0)[0:3]
pc_label[:, 0:3] -= xyz_minpc_label = np.concatenate(data_list, 0)
xyz_min = np.amin(pc_label, axis=0)[0:3]
pc_label[:, 0:3] -= xyz_min
结果
[array([[ -5.388, 45.08 , 2.956, ..., 88. , 62. , 0. ],
...,
[ -4.399, 44.002, 2.961, ..., 142. , 138. , 0. ]]),
array([[ -5.528, 43.541, 0.795, ..., 109. , 88. , 12. ],
...,
[ -5.504, 43.881, 0.835, ..., 129. , 103. , 12. ]]),
array([[ -3.277, 43.192, 0.622, ..., 79. , 63. , 6. ],
...,
[ -3.267, 45.061, 1.18 , ..., 114. , 121. , 6. ]])
...]
[]
data_list is empty
原始脚本
def convert_pc2ply(anno_path, save_path):
"""
Convert original dataset files to ply file (each line is XYZRGBL).
We aggregated all the points from each instance in the room.
:param anno_path: path to annotations. e.g. Area_1/office_2/Annotations/
:param save_path: path to save original point clouds (each line is XYZRGBL)
:return: None
"""
data_list = []
for f in glob.glob(join(anno_path, '*.txt')):
class_name = os.path.basename(f).split('_')[0]
if class_name not in gt_class: # note: in some room there is 'stairs'..
class_name = 'clutter'
pc = pd.read_csv(f, header=None, delim_whitespace=True).values
labels = np.ones((pc.shape[0], 1)) * gt_class2label[class_name]
data_list.append(np.concatenate([pc, labels], 1)) # Nx7
pc_label = np.concatenate(data_list, 0)
xyz_min = np.amin(pc_label, axis=0)[0:3]
pc_label[:, 0:3] -= xyz_min
解决方案
推荐阅读
- javascript - 如何通过在 typescript 中调用函数来关闭 bootstrap 4 模型
- arrays - 如何使该算法在 dx,dy 的不同值上重复并将这些值存储在数组中
- git - Git 正在寻找错误的 SSH 密钥
- python - Pandas 根据分隔符将行中的值拆分为多行
- vega - Vega-lite 重复的 x 轴标签
- laravel - 如何从 Laravel 发现请求主体以生成 OpenAPI 规范?
- python - 如何使用 matplotlib 获取开始时间和结束时间最多毫秒的任务的甘特图
- c++builder - C++ Builder TStringGrid 行颜色
- jena - 如何在自定义内置原语中添加三元组以进一步查询?
- sql-server - 如何在更新语句中使用变量名作为表名