def loader(filename, test_angle=None): P = np.asarray(open3d.read_point_cloud(filename).points) cls = classmap['_'.join(os.path.basename(filename).split('_')[:-1])] #transform into ball of diameter 32 (obj scale in modelnet has no meaning, original meshes have random sizes) # (in the paper we used a unit ball and ./32 grid sizes, this is equivalent in effect) diameter = np.max(np.max(P, axis=0) - np.min(P, axis=0)) M = transforms3d.zooms.zfdir2mat(32 / diameter) # training data augmentation if training: if args.pc_augm_input_dropout > 0: # removing points here changes graph structure (unlike zeroing features) P, _ = pcu.dropout(P, None, args.pc_augm_input_dropout) if args.pc_augm_scale > 1: s = random.uniform(1 / args.pc_augm_scale, args.pc_augm_scale) M = np.dot(transforms3d.zooms.zfdir2mat(s), M) if args.pc_augm_rot: angle = random.uniform(0, 2 * math.pi) M = np.dot(transforms3d.axangles.axangle2mat([0, 0, 1], angle), M) # z=upright assumption if args.pc_augm_mirror_prob > 0: # mirroring x&y, not z if random.random() < args.pc_augm_mirror_prob / 2: M = np.dot(transforms3d.zooms.zfdir2mat(-1, [1, 0, 0]), M) if random.random() < args.pc_augm_mirror_prob / 2: M = np.dot(transforms3d.zooms.zfdir2mat(-1, [0, 1, 0]), M) else: if test_angle: M = np.dot( transforms3d.axangles.axangle2mat([0, 0, 1], test_angle), M) # z=upright assumption P = np.dot(P, M.T) # coarsen to initial resolution (btw, axis-aligned quantization of rigidly transformed cloud adds jittering noise) P -= np.min( P, axis=0 ) #move to positive octant (voxelgrid has fixed boundaries at axes planes) cloud = pcu.create_cloud(P) cloud = open3d.voxel_down_sample(cloud, voxel_size=pyramid_conf[0][0]) F = np.ones((len(cloud.points), 1), dtype=np.float32) # no point features in modelnet graphs, poolmaps = pcu.create_graph_pyramid(args, cloud, pyramid_conf) return F, cls, graphs, poolmaps
def loader(filename): data = np.fromfile(filename, binType) cls = classmap[os.path.basename(filename).split('.')[0]] P = np.vstack([data['x'], data['y'], data['z']]).T # metric units F = data['intensity'].reshape(-1, 1) # training data augmentation if training: if args.pc_augm_input_dropout > 0: # removing points here changes graph structure (unlike zeroing features) P, F = pcu.dropout(P, F, args.pc_augm_input_dropout) M = np.eye(3) if args.pc_augm_scale > 1: s = random.uniform(1 / args.pc_augm_scale, args.pc_augm_scale) M = np.dot(transforms3d.zooms.zfdir2mat(s), M) if args.pc_augm_rot: angle = random.uniform(0, 2 * math.pi) M = np.dot(transforms3d.axangles.axangle2mat([0, 0, 1], angle), M) # z=upright assumption if args.pc_augm_mirror_prob > 0: # mirroring x&y, not z if random.random() < args.pc_augm_mirror_prob / 2: M = np.dot(transforms3d.zooms.zfdir2mat(-1, [1, 0, 0]), M) if random.random() < args.pc_augm_mirror_prob / 2: M = np.dot(transforms3d.zooms.zfdir2mat(-1, [0, 1, 0]), M) P = np.dot(P, M.T) # coarsen to initial resolution (btw, axis-aligned quantization of rigidly transformed cloud adds jittering noise) P -= np.min( P, axis=0 ) #move to positive octant (voxelgrid has fixed boundaries at axes planes) PF = np.hstack([P, F]).astype(np.float32) PF_filtered = pcu.voxelgrid( pcl.PointCloud_PointXYZI(PF), pyramid_conf[0][0] ).to_array( ) # aggregates intensities too (note pcl wrapper bug: only int intensities accepted) F = PF_filtered[:, 3] / 255 - 0.5 # laser return intensities in [-0.5,0.5] cloud = pcl.PointCloud( PF_filtered[:, 0:3] ) # (pcl wrapper bug: XYZI cannot query kd-tree by radius) graphs, poolmaps = pcu.create_graph_pyramid(args, cloud, pyramid_conf) return F, cls, graphs, poolmaps
def loader(filename): data = np.fromfile(filename, binType) cls = classmap[os.path.basename(filename).split('.')[0]] P = np.vstack([data['x'], data['y'], data['z']]).T # metric units F = data['intensity'].reshape(-1, 1) # training data augmentation if training: if args.pc_augm_input_dropout > 0: # removing points here changes graph structure (unlike zeroing features) P, F = pcu.dropout(P, F, args.pc_augm_input_dropout) M = np.eye(3) if args.pc_augm_scale > 1: s = random.uniform(1 / args.pc_augm_scale, args.pc_augm_scale) M = np.dot(transforms3d.zooms.zfdir2mat(s), M) if args.pc_augm_rot: angle = random.uniform(0, 2 * math.pi) M = np.dot(transforms3d.axangles.axangle2mat([0, 0, 1], angle), M) # z=upright assumption if args.pc_augm_mirror_prob > 0: # mirroring x&y, not z if random.random() < args.pc_augm_mirror_prob / 2: M = np.dot(transforms3d.zooms.zfdir2mat(-1, [1, 0, 0]), M) if random.random() < args.pc_augm_mirror_prob / 2: M = np.dot(transforms3d.zooms.zfdir2mat(-1, [0, 1, 0]), M) P = np.dot(P, M.T) # coarsen to initial resolution (btw, axis-aligned quantization of rigidly transformed cloud adds jittering noise) P -= np.min( P, axis=0 ) #move to positive octant (voxelgrid has fixed boundaries at axes planes) cloud = pcu.create_cloud(P, intensity=F) cloud = open3d.voxel_down_sample( cloud, voxel_size=pyramid_conf[0][0]) # aggregates intensities too F = np.asarray( cloud.colors )[:, 0] / 255 - 0.5 # laser return intensities in [-0.5,0.5] graphs, poolmaps = pcu.create_graph_pyramid(args, cloud, pyramid_conf) return F.astype(np.float32), cls, graphs, poolmaps