首页 > 解决方案 > Numpy 连接错误 (np.concatenate)

问题描述

我试图data_prepare_s3dis.pyGithub 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

标签: pythonnumpy

解决方案


推荐阅读