Пример #1
0
 def post_procesiing(self, outputs):
     outputs['hm_cen'] = _sigmoid(outputs['hm_cen'])
     outputs['cen_offset'] = _sigmoid(outputs['cen_offset'])
     # detections size (batch_size, K, 10)
     detections = decode(outputs['hm_cen'], outputs['cen_offset'], outputs['direction'], outputs['z_coor'],outputs['dim'], K=self.configs.K)
     detections = detections.cpu().detach().numpy().astype(np.float32)
     detections = post_processing(detections, self.configs.num_classes, self.configs.down_ratio, self.configs.peak_thresh)
     detections = detections[0]
     detections = convert_det_to_real_values(detections)
     return detections
        for sample_idx in range(len(demo_dataset)):
            metadatas, bev_map, img_rgb = demo_dataset.load_bevmap_front(sample_idx)
            detections, bev_map, fps = do_detect(configs, model, bev_map, is_front=True)

            # Draw prediction in the image
            bev_map = (bev_map.permute(1, 2, 0).numpy() * 255).astype(np.uint8)
            bev_map = cv2.resize(bev_map, (cnf.BEV_WIDTH, cnf.BEV_HEIGHT))
            bev_map = draw_predictions(bev_map, detections, configs.num_classes)

            # Rotate the bev_map
            bev_map = cv2.rotate(bev_map, cv2.ROTATE_180)

            img_path = metadatas['img_path'][0]
            img_bgr = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
            calib = Calibration(configs.calib_path)
            kitti_dets = convert_det_to_real_values(detections)
            if len(kitti_dets) > 0:
                kitti_dets[:, 1:] = lidar_to_camera_box(kitti_dets[:, 1:], calib.V2C, calib.R0, calib.P2)
                img_bgr = show_rgb_image_with_boxes(img_bgr, kitti_dets, calib)

            out_img = merge_rgb_to_bev(img_bgr, bev_map, output_width=configs.output_width)
            write_credit(out_img, (80, 210), text_author='Cre: github.com/maudzung', org_fps=(80, 250), fps=fps)
            if out_cap is None:
                out_cap_h, out_cap_w = out_img.shape[:2]
                fourcc = cv2.VideoWriter_fourcc(*'MJPG')
                out_path = os.path.join(configs.results_dir, '{}_front.avi'.format(configs.foldername))
                print('Create video writer at {}'.format(out_path))
                out_cap = cv2.VideoWriter(out_path, fourcc, 30, (out_cap_w, out_cap_h))

            out_cap.write(out_img)
Пример #3
0
            bev_map = makeBEVMap(lidardata, cnf.boundary)
            bev_map = bev_map.transpose((1, 2, 0)) * 255

            bev_map = cv2.resize(bev_map, (cnf.BEV_WIDTH, cnf.BEV_HEIGHT))
            bev_map = draw_predictions(bev_map, detections.copy(),
                                       configs.num_classes)

            # Rotate the bev_map
            bev_map = cv2.rotate(bev_map, cv2.ROTATE_180)

            img_rgb = metadatas['img_rgb'][0]
            img_rgb = cv2.resize(img_rgb, (img_rgb.shape[1], img_rgb.shape[0]))
            img_bgr = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
            calib = Calibration(
                img_path.replace(".png", ".txt").replace("image_2", "calib"))
            kitti_dets = convert_det_to_real_values(detections,
                                                    configs.num_classes)
            '''datap = img_path.split("/")
            filename = datap[9].split('.')
            lidar_path = '/' + datap[1] + '/' + datap[2]+ '/' + datap[3]+ '/' +\
                         datap[4] +'/' +datap[5]+ '/' +datap[6]+ '/'+datap[7]+ '/' +'velodyne' + '/' + filename[0]+'.bin'
            if len(kitti_dets) > 0:
                show3dlidar(lidar_path, kitti_dets, calib)'''

            if len(kitti_dets) > 0:
                kitti_dets[:,
                           1:] = lidar_to_camera_box(kitti_dets[:,
                                                                1:], calib.V2C,
                                                     calib.R0, calib.P2)
                img_bgr = show_rgb_image_with_boxes(img_bgr, kitti_dets, calib)

            out_img = merge_rgb_to_bev(img_bgr,
Пример #4
0
def evaluate_mAP(val_loader, model, configs, logger):
    batch_time = AverageMeter('Time', ':6.3f')
    data_time = AverageMeter('Data', ':6.3f')

    progress = ProgressMeter(len(val_loader), [batch_time, data_time],
                             prefix="Evaluation phase...")
    labels = []
    sample_metrics = []  # List of tuples (TP, confs, pred)
    # switch to evaluate mode
    model.eval()

    class_id = {0:'Car', 1:'Pedestrian', 2:'Cyclist'}

    with torch.no_grad():
        start_time = time.time()
        for batch_idx, batch_data in enumerate(tqdm(val_loader)):
            metadatas, targets= batch_data

            batch_size = len(metadatas['img_path'])

            voxelinput = metadatas['voxels']
            coorinput = metadatas['coors']
            numinput = metadatas['num_points']

            dtype = torch.float32
            voxelinputr = torch.tensor(
                voxelinput, dtype=torch.float32, device=configs.device).to(dtype)

            coorinputr = torch.tensor(
                coorinput, dtype=torch.int32, device=configs.device)

            numinputr = torch.tensor(
                numinput, dtype=torch.int32, device=configs.device)
            t1 = time_synchronized()
            outputs =  model(voxelinputr, coorinputr, numinputr)
            outputs = outputs._asdict()

            outputs['hm_cen'] = _sigmoid(outputs['hm_cen'])
            outputs['cen_offset'] = _sigmoid(outputs['cen_offset'])
            # detections size (batch_size, K, 10)
            img_path = metadatas['img_path'][0]
            #print(img_path)
            calib = Calibration(img_path.replace(".png", ".txt").replace("image_2", "calib"))

            detections = decode(outputs['hm_cen'], outputs['cen_offset'], outputs['direction'], outputs['z_coor'],
                                outputs['dim'], K=configs.K)
            detections = detections.cpu().numpy().astype(np.float32)
            detections = post_processing(detections, configs.num_classes, configs.down_ratio, configs.peak_thresh)

            for i in range(configs.batch_size):
                detections[i] = convert_det_to_real_values(detections[i])
                img_path = metadatas['img_path'][i]
                #rint(img_path)
                datap = str.split(img_path,'/')
                filename = str.split(datap[7],'.')
                file_write_obj = open('../result/' + filename[0] + '.txt', 'w')
                lidar_path = '/' + datap[1] + '/' + datap[2] + '/' + datap[3] + '/' + \
                             datap[4] + '/' + datap[5] + '/' + 'velodyne' + '/' + filename[0] + '.bin'
                #print(lidar_path)
                #show3dlidar(lidar_path, detections[i], calib.V2C, calib.R0, calib.P2)
                dets = detections[i]
                if len(dets) >0 :
                    dets[:, 1:] = lidar_to_camera_box(dets[:, 1:], calib.V2C, calib.R0, calib.P2)
                    for box_idx, label in enumerate(dets):
                        location, dim, ry = label[1:4], label[4:7], label[7]
                        if ry < -np.pi:
                            ry = 2*np.pi + ry
                        if ry > np.pi:
                            ry = -2*np.pi + ry
                        corners_3d = compute_box_3d(dim, location, ry)
                        corners_2d = project_to_image(corners_3d, calib.P2)
                        minxy = np.min(corners_2d, axis=0)
                        maxxy = np.max(corners_2d, axis=0)
                        bbox = np.concatenate([minxy, maxxy], axis=0)
                        if bbox[0] < 0 or bbox[2]<0:
                            continue
                        if bbox[1] > 1272 or bbox[3] > 375:
                            continue
                        oblist = ['Car',' ','0.0', ' ', '0', ' ', '-10', ' ','%.2f'%bbox[0], ' ', \
                              '%.2f' %bbox[1], ' ','%.2f'%bbox[2], ' ','%.2f'%bbox[3], ' ','%.2f'%dim[0], ' ','%.2f'%dim[1], ' ','%.2f'%dim[2], ' ', \
                              '%.2f' %location[0], ' ','%.2f'%location[1], ' ','%.2f'%location[2], ' ', '%.2f'%ry, '\n']
                        file_write_obj.writelines(oblist)
                file_write_obj.close()

            '''for sample_i in range(len(detections)):