server_url = 'https://s3.eu-central-1.amazonaws.com/avg-kitti/raw_data' download_url = '{}/{}/{}.zip'.format(server_url, configs.foldername[:-5], configs.foldername) download_and_unzip(configs.dataset_dir, download_url) model = create_model(configs) print('\n\n' + '-*=' * 30 + '\n\n') assert os.path.isfile(configs.pretrained_path), "No file at {}".format(configs.pretrained_path) model.load_state_dict(torch.load(configs.pretrained_path, map_location='cpu')) print('Loaded weights from {}\n'.format(configs.pretrained_path)) configs.device = torch.device('cpu' if configs.no_cuda else 'cuda:{}'.format(configs.gpu_idx)) model = model.to(device=configs.device) model.eval() out_cap = None demo_dataset = Demo_KittiDataset(configs) with torch.no_grad(): 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)
server_url = 'https://s3.eu-central-1.amazonaws.com/avg-kitti/raw_data' download_url = '{}/{}/{}.zip'.format(server_url, configs.foldername[:-5], configs.foldername) download_and_unzip(configs.dataset_dir, download_url) model = create_model(configs) print('\n\n' + '-*=' * 30 + '\n\n') assert os.path.isfile(configs.pretrained_path), "No file at {}".format(configs.pretrained_path) model.load_state_dict(torch.load(configs.pretrained_path, map_location='cpu')) print('Loaded weights from {}\n'.format(configs.pretrained_path)) configs.device = torch.device('cpu' if configs.no_cuda else 'cuda:{}'.format(configs.gpu_idx)) model = model.to(device=configs.device) model.eval() out_cap = None demo_dataset = Demo_KittiDataset(configs) with torch.no_grad(): for sample_idx in range(len(demo_dataset)): metadatas, front_bevmap, back_bevmap, img_rgb = demo_dataset.load_bevmap_front_vs_back(sample_idx) front_detections, front_bevmap, fps = do_detect(configs, model, front_bevmap, is_front=True) back_detections, back_bevmap, _ = do_detect(configs, model, back_bevmap, is_front=False) # Draw prediction in the image front_bevmap = (front_bevmap.permute(1, 2, 0).numpy() * 255).astype(np.uint8) front_bevmap = cv2.resize(front_bevmap, (cnf.BEV_WIDTH, cnf.BEV_HEIGHT)) front_bevmap = draw_predictions(front_bevmap, front_detections, configs.num_classes) # Rotate the front_bevmap front_bevmap = cv2.rotate(front_bevmap, cv2.ROTATE_90_COUNTERCLOCKWISE) # Draw prediction in the image back_bevmap = (back_bevmap.permute(1, 2, 0).numpy() * 255).astype(np.uint8)