def update_cfg(): import argparse import warnings parser = argparse.ArgumentParser(description='Testing Complex-YOLO.') parser.add_argument("--use_cuda", action="store_true", default=False, help="Whether to use CUDA. Default is `False`.") args = parser.parse_args() kwargs = {} if torch.cuda.is_available(): if not args.use_cuda: warnings.warn("CUDA devices are available. " + "It is recommended to run with `--use_cuda`.") elif args.use_cuda: warnings.warn( "CUDA devices are excepted but not available. CPU will be used.") args.use_cuda = False kwargs["device"] = torch.device("cuda" if args.use_cuda else "cpu") kwargs["split"] = "val" cfg.update(vars(args), kwargs)
def filter_dataset(): '''Filter dataset according to active class. A new split file named `active_train.txt` will be generated. ''' active_split_dir = os.path.join(cfg.get_datasets_cache_root(), "Kitti") if not os.path.exists(os.path.dirname(active_split_dir)): os.makedirs(active_split_dir) active_split_path = os.path.join(active_split_dir, "active_train.txt") dataset = BEVKitti() ids = dataset.get_ids() active_ids = [] active_clss = cfg.get_active_cls_str() for idx in ids: objs = dataset.get_objs(idx) for obj in objs: if obj.get_cls_str() in active_clss: active_ids.append("{:0>6}\n".format(idx)) break active_ids[-1] = active_ids[-1][:-1] with open(active_split_path, 'w') as f: f.writelines(active_ids) kwargs = {"split": "active_train"} cfg.update(kwargs)
# def show_bev(bev): # fig, ax = plt.subplots(ncols=3, nrows=1) # height_map = bev[0] # density_map = bev[1] # intensity_map = bev[2] # ax[0].imshow(height_map, cmap=plt.cm.gray) # ax[1].imshow(density_map, cmap=plt.cm.gray) # ax[2].imshow(intensity_map, cmap=plt.cm.gray) # plt.show() if __name__ == "__main__": datasets_cache_root = cfg.get_datasets_cache_root() kwargs = {"split": "trainval"} cfg.update(kwargs) dataset = BasicKitti() ids = dataset.get_ids() for idx in ids: # idx = ids[0] print("Generating BEV maps {:0>6} ...".format(idx)) pts_lidar = dataset.get_valid_pts_lidar(idx) bev = generate_BEV(pts_lidar) # show_bev(bev) # break BEVKitti.save_bev(bev, idx) print("Successfully save BEV to " + datasets_cache_root + "/Kitti/bev/")