def __getitem__(self, index): # index = 4 # print("get_item_index: ", index) info = copy.deepcopy(self.kitti_infos[index]) # print(1111111111111) sample_idx = info['point_cloud']['lidar_idx'] points = self.get_lidar(sample_idx) if not cfg.DATA_CONFIG.TS_DATA: calib = self.get_calib(sample_idx) img_shape = info['image']['image_shape'] if cfg.DATA_CONFIG.FOV_POINTS_ONLY: pts_rect = calib.lidar_to_rect(points[:, 0:3]) fov_flag = self.get_fov_flag(pts_rect, img_shape, calib) points = points[fov_flag] if not cfg.DATA_CONFIG.TS_DATA: input_dict = { 'points': points, 'sample_idx': sample_idx, 'calib': calib, } else: input_dict = { 'points': points, 'sample_idx': sample_idx, } if 'annos' in info: annos = info['annos'] if not cfg.DATA_CONFIG.TS_DATA: annos = common_utils.drop_info_with_name(annos, name='DontCare') else: annos = common_utils.drop_info_with_name(annos, name='0') loc, dims, rots = annos['location'], annos['dimensions'], annos['rotation_y'] gt_names = annos['name'] bbox = annos['bbox'] gt_boxes = np.concatenate([loc, dims, rots[..., np.newaxis]], axis=1).astype(np.float32) if 'gt_boxes_lidar' in annos: gt_boxes_lidar = annos['gt_boxes_lidar'] else: gt_boxes_lidar = box_utils.boxes3d_camera_to_lidar(gt_boxes, calib) input_dict.update({ 'gt_boxes': gt_boxes, 'gt_names': gt_names, 'gt_box2d': bbox, 'gt_boxes_lidar': gt_boxes_lidar }) example = self.prepare_data(input_dict=input_dict, has_label='annos' in info) example['sample_idx'] = sample_idx if not cfg.DATA_CONFIG.TS_DATA: example['image_shape'] = img_shape return example
def __getitem__(self, index): # index = 4 if self._merge_all_iters_to_one_epoch: index = index % len(self.kitti_infos) info = copy.deepcopy(self.kitti_infos[index]) sample_idx = info['point_cloud']['lidar_idx'] points = self.get_lidar(sample_idx) if self.raw: #use raw data contains ground points raw_points_fov = None else: raw_points_fov = self.get_lidar_raw(sample_idx) calib = self.get_calib(sample_idx) #kdtree = self.get_kdtree(sample_idx) img_shape = info['image']['image_shape'] if self.dataset_cfg.FOV_POINTS_ONLY: pts_rect = calib.lidar_to_rect(points[:, 0:3]) fov_flag = self.get_fov_flag(pts_rect, img_shape, calib) points = points[fov_flag] input_dict = { 'points': points, 'frame_id': sample_idx, 'calib': calib, 'raw_points': raw_points_fov #'kd_tree': kdtree } if 'annos' in info: annos = info['annos'] annos = common_utils.drop_info_with_name(annos, name='DontCare') loc, dims, rots = annos['location'], annos['dimensions'], annos[ 'rotation_y'] gt_names = annos['name'] gt_boxes_camera = np.concatenate( [loc, dims, rots[..., np.newaxis]], axis=1).astype(np.float32) gt_boxes_lidar = box_utils.boxes3d_kitti_camera_to_lidar( gt_boxes_camera, calib) input_dict.update({ 'gt_names': gt_names, 'gt_boxes': gt_boxes_lidar }) road_plane = self.get_road_plane(sample_idx) if road_plane is not None: input_dict['road_plane'] = road_plane data_dict = self.prepare_data(data_dict=input_dict) data_dict['image_shape'] = img_shape data_dict['raw_points'] = raw_points_fov data_dict['calib'] = calib return data_dict
def __getitem__(self, index): # # for debug purpose, uncomment this to fix the frame # index = 0 # index = 300 # for index, info in enumerate(self.kitti_infos): # if info['point_cloud']['lidar_idx'] == '100001284': # break # print(self.kitti_infos[index]['point_cloud']['lidar_idx']) info = copy.deepcopy(self.kitti_infos[index]) sample_idx = info['point_cloud']['lidar_idx'] if cfg.TAG_PTS_WITH_RGB: points = self.get_colored_lidar(sample_idx) else: points = self.get_lidar(sample_idx) calib = self.get_calib(sample_idx) img_shape = info['image']['image_shape'] if cfg.DATA_CONFIG.FOV_POINTS_ONLY: pts_rect = calib.lidar_to_rect(points[:, 0:3]) fov_flag = self.get_fov_flag(pts_rect, img_shape, calib) points = points[fov_flag] input_dict = { 'points': points, 'sample_idx': sample_idx, 'calib': calib, } if 'annos' in info: annos = info['annos'] annos = common_utils.drop_info_with_name(annos, name='DontCare') loc, dims, rots = annos['location'], annos['dimensions'], annos[ 'rotation_y'] gt_names = annos['name'] bbox = annos['bbox'] gt_boxes = np.concatenate([loc, dims, rots[..., np.newaxis]], axis=1).astype(np.float32) if 'gt_boxes_lidar' in annos: gt_boxes_lidar = annos['gt_boxes_lidar'] else: gt_boxes_lidar = box_utils.boxes3d_camera_to_lidar( gt_boxes, calib) input_dict.update({ 'gt_boxes': gt_boxes, 'gt_names': gt_names, 'gt_box2d': bbox, 'gt_boxes_lidar': gt_boxes_lidar }) # debuggin model; here we cheat by tagging if each point is in the object bbox if cfg.TAG_PTS_IF_IN_GT_BBOXES: points[:, 3] = 0 corners_lidar = box_utils.boxes3d_to_corners3d_lidar( gt_boxes_lidar) for k in range(len(gt_boxes_lidar)): if gt_names[k] == 'Car': flag = box_utils.in_hull(points[:, 0:3], corners_lidar[k]) points[flag, 3] = 1 input_dict['points'] = points example = self.prepare_data(input_dict=input_dict, has_label='annos' in info) example['sample_idx'] = sample_idx example['image_shape'] = img_shape # add the bev maps if HD map is available (eg, argoverse) if 'bev' in cfg.MODE: bev = self.get_bev(sample_idx) example['bev'] = bev if cfg.INJECT_SEMANTICS or cfg.USE_PSEUDOLIDAR: # todo: check the ordering of the imagenet mean and std. is it rgb or bgr? img = self.get_image(sample_idx) # preprocessing for the image to work for hrnet which works on cityscapes # if on kitti (not on argoverse), some of the images don't have the same size, # so we must scale them to the same size, then during voxelization, rescale # to the right size for projecting lidar pts onto image plane to work # if the height is not set, then we scale it according to the width if cfg.INJECT_SEMANTICS_HEIGHT == 0: img = image_resize(img, cfg.INJECT_SEMANTICS_WIDTH) else: img = cv2.resize( img, (cfg.INJECT_SEMANTICS_WIDTH, cfg.INJECT_SEMANTICS_HEIGHT), interpolation=cv2.INTER_LINEAR) mean = np.array([0.485, 0.456, 0.406]) std = np.array([0.229, 0.224, 0.225]) img = input_transform(img, mean, std) # normalize wrt to imagenet img = img.transpose( (2, 0, 1)) # change dim ordering to c, h, w for torch example['img'] = img example['pseudolidar_image_shape'] = img.shape[-2:] # if using pseudolidar from depth estimation, we need to crop out the sky and the road if cfg.USE_PSEUDOLIDAR: # first scale down, then crop out sky and roads oh, ow = img.shape[-2:] bottom_p, top_p = .15, cfg.DEPTH_MAP_TOP_MARGIN_PCT top = oh * top_p bottom = oh - (oh * bottom_p) top = int(top) bottom = int(bottom) img_cropped = img[:, top:bottom, :] example['img'] = img_cropped return example
def __getitem__(self, index): # index = 4 if self._merge_all_iters_to_one_epoch: index = index % len(self.kitti_infos) info = copy.deepcopy(self.kitti_infos[index]) sample_idx = info['point_cloud']['lidar_idx'] points = self.get_lidar(sample_idx) raw_points_fov = self.get_lidar_raw(sample_idx) calib = self.get_calib(sample_idx) #kdtree = self.get_kdtree(sample_idx) img_shape = info['image']['image_shape'] if self.dataset_cfg.FOV_POINTS_ONLY: pts_rect = calib.lidar_to_rect(points[:, 0:3]) fov_flag = self.get_fov_flag(pts_rect, img_shape, calib) points = points[fov_flag] #pts_rect = calib.lidar_to_rect(raw_points[:, 0:3]) #fov_flag = self.get_fov_flag(pts_rect, img_shape, calib) #raw_points_fov = raw_points_fov[fov_flag] img_path = '/media/ddd/data2/3d_MOTS_Ex./Code/OpenPCDet/data/kitti/training/image_2/' + info['image']['image_idx'] + '.png' img = cv2.imread(img_path) image = np.float32(img) image *= 1. / 255 img = cv2.cvtColor(image, cv2.COLOR_BGR2Lab) ''' calib_result = calib.lidar_to_img(points) # [N,3] in lidar to [N,2] in img points_color = self.painted_point_cloud(calib_result,img,points) ''' input_dict = { 'points': points, 'frame_id': sample_idx, 'calib': calib, 'raw_points': raw_points_fov #'kd_tree': kdtree } if 'annos' in info: annos = info['annos'] annos = common_utils.drop_info_with_name(annos, name='DontCare') loc, dims, rots = annos['location'], annos['dimensions'], annos['rotation_y'] gt_names = annos['name'] gt_boxes_camera = np.concatenate([loc, dims, rots[..., np.newaxis]], axis=1).astype(np.float32) gt_boxes_lidar = box_utils.boxes3d_kitti_camera_to_lidar(gt_boxes_camera, calib) input_dict.update({ 'gt_names': gt_names, 'gt_boxes': gt_boxes_lidar }) road_plane = self.get_road_plane(sample_idx) if road_plane is not None: input_dict['road_plane'] = road_plane data_dict = self.prepare_data(data_dict=input_dict) data_dict['image_shape'] = img_shape data_dict['raw_points'] = raw_points_fov #img_path = '/media/ddd/data2/3d_MOTS_Ex./Code/OpenPCDet/data/kitti/training/image_2/' + info['image']['image_idx'] + '.png' #img = cv2.imread(img_path) #image = np.float32(img) #image *= 1. / 255 #img = cv2.cvtColor(image, cv2.COLOR_BGR2Lab) data_dict['calib'] = calib #data_dict['image'] = img return data_dict