def generate_single_sample_dict(batch_index, box_dict): pred_scores = box_dict['pred_scores'].cpu().numpy() pred_boxes = box_dict['pred_boxes'].cpu().numpy() pred_labels = box_dict['pred_labels'].cpu().numpy() pred_dict = get_template_prediction(pred_scores.shape[0]) if pred_scores.shape[0] == 0: return pred_dict calib = batch_dict['calib'][batch_index] image_shape = batch_dict['image_shape'][batch_index] pred_boxes_camera = box_utils.boxes3d_lidar_to_kitti_camera(pred_boxes, calib) pred_boxes_img = box_utils.boxes3d_kitti_camera_to_imageboxes( pred_boxes_camera, calib, image_shape=image_shape ) pred_dict['name'] = np.array(class_names)[pred_labels - 1] # 这里是 label - 1 !! pred_dict['alpha'] = -np.arctan2(-pred_boxes[:, 1], pred_boxes[:, 0]) + pred_boxes_camera[:, 6] pred_dict['bbox'] = pred_boxes_img pred_dict['dimensions'] = pred_boxes_camera[:, 3:6] pred_dict['location'] = pred_boxes_camera[:, 0:3] pred_dict['rotation_y'] = pred_boxes_camera[:, 6] pred_dict['score'] = pred_scores pred_dict['boxes_lidar'] = pred_boxes return pred_dict
def run(self, points, calib, frame): t_t = time.time() num_features = 4 # X,Y,Z,intensity self.points = points.reshape([-1, num_features]) frame = 0 timestamps = np.empty((len(self.points), 1)) timestamps[:] = frame self.points = np.append(self.points, timestamps, axis=1) self.points[:, 0] += move_lidar_center input_dict = { 'points': self.points, 'frame_id': frame, } data_dict = self.demo_dataset.prepare_data(data_dict=input_dict) data_dict = self.demo_dataset.collate_batch([data_dict]) load_data_to_gpu(data_dict) torch.cuda.synchronize() t = time.time() pred_dicts, _ = self.net.forward(data_dict) torch.cuda.synchronize() inference_time = time.time() - t inference_time_list.append(inference_time) mean_inference_time = sum(inference_time_list) / len( inference_time_list) boxes_lidar = pred_dicts[0]["pred_boxes"].detach().cpu().numpy() scores = pred_dicts[0]["pred_scores"].detach().cpu().numpy() types = pred_dicts[0]["pred_labels"].detach().cpu().numpy() pred_boxes = np.copy(boxes_lidar) pred_dict = self.get_template_prediction(scores.shape[0]) if scores.shape[0] == 0: return pred_dict pred_boxes_camera = box_utils.boxes3d_lidar_to_kitti_camera( pred_boxes, calib) pred_boxes_img = box_utils.boxes3d_kitti_camera_to_imageboxes( pred_boxes_camera, calib, image_shape=image_shape) pred_dict['name'] = np.array(cfg.CLASS_NAMES)[types - 1] pred_dict['alpha'] = -np.arctan2( -pred_boxes[:, 1], pred_boxes[:, 0]) + pred_boxes_camera[:, 6] pred_dict['bbox'] = pred_boxes_img pred_dict['dimensions'] = pred_boxes_camera[:, 3:6] pred_dict['location'] = pred_boxes_camera[:, 0:3] pred_dict['rotation_y'] = pred_boxes_camera[:, 6] pred_dict['score'] = scores pred_dict['boxes_lidar'] = pred_boxes return scores, boxes_lidar, types, pred_dict
def run(self, points, calib, image_shape): t_t = time.time() print(f"input points shape: {points.shape}") num_features = 4 self.points = points.reshape([-1, num_features]) #print("points", self.points) timestamps = np.zeros((len(self.points), 1)) self.points = np.append(self.points, timestamps, axis=1) self.points[:, 0] += movelidarcenter #print("points2", self.points) input_dict = { 'points': self.points, 'frame_id': 0, } data_dict = self.demo_dataset.prepare_data(data_dict=input_dict) data_dict = self.demo_dataset.collate_batch([data_dict]) load_data_to_gpu(data_dict) torch.cuda.synchronize() t = time.time() pred_dicts, _ = self.net.forward(data_dict) torch.cuda.synchronize() print(f"inference time: {time.time() - t}") boxes_lidar = pred_dicts[0]["pred_boxes"].detach().cpu().numpy() scores = pred_dicts[0]["pred_scores"].detach().cpu().numpy() types = pred_dicts[0]["pred_labels"].detach().cpu().numpy() # print(f" pred boxes: { boxes_lidar }") # print(f" pred_scores: { scores }") # print(f" pred_labels: { types }") pred_boxes = boxes_lidar pred_dict = self.get_template_prediction(scores.shape[0]) if scores.shape[0] == 0: return pred_dict #calib = get_calib(sample_idx) #P2 = np.concatenate([calib.P2, np.array([[0., 0., 0., 1.]])], axis=0) #R0_4x4 = np.zeros([4, 4], dtype=calib.R0.dtype) #R0_4x4[3, 3] = 1. #R0_4x4[:3, :3] = calib.R0 #V2C_4x4 = np.concatenate([calib.V2C, np.array([[0., 0., 0., 1.]])], axis=0) #calib = {'P2': P2, 'R0_rect': R0_4x4, 'Tr_velo_to_cam': V2C_4x4} #calib = input_dict['calib'][batch_index] #image_shape = input_dict['image_shape'][batch_index] pred_boxes_camera = box_utils.boxes3d_lidar_to_kitti_camera( pred_boxes, calib) pred_boxes_img = box_utils.boxes3d_kitti_camera_to_imageboxes( pred_boxes_camera, calib, image_shape=image_shape) pred_dict['name'] = np.array(cfg.CLASS_NAMES)[types - 1] pred_dict['alpha'] = -np.arctan2( -pred_boxes[:, 1], pred_boxes[:, 0]) + pred_boxes_camera[:, 6] pred_dict['bbox'] = pred_boxes_img pred_dict['dimensions'] = pred_boxes_camera[:, 3:6] pred_dict['location'] = pred_boxes_camera[:, 0:3] pred_dict['rotation_y'] = pred_boxes_camera[:, 6] pred_dict['score'] = scores pred_dict['boxes_lidar'] = pred_boxes return pred_dict