def load_flags(mode="") -> Flags: parser = argparse.ArgumentParser(description='') parser.add_argument('--yaml_filepath', '-y', type=str, default="./flags/20200905_sample_flag.yaml", help='Flags yaml file path') args = parser.parse_args() # --- Default setting --- flags = load_yaml(args.yaml_filepath) # print("yaml flags", flags) base_flags = Flags() base_flags.update(flags) return base_flags
help='Directory to output the result') parser.add_argument('--debug', '-d', type=strtobool, default='false', help='Debug mode') args = parser.parse_args() return args if __name__ == '__main__': args = parse() out_dir = Path(args.out) debug = args.debug flags_dict = load_yaml(out_dir / 'flags.yaml') cfg = load_yaml(out_dir / 'cfg.yaml') # flags = DotDict(flags_dict) flags = Flags() flags.update(flags_dict) print(f"flags: {flags_dict}") # set env variable for data # Not use flags.l5kit_data_folder, but use fixed test data. l5kit_data_folder = "../../input/lyft-motion-prediction-autonomous-vehicles" os.environ["L5KIT_DATA_FOLDER"] = l5kit_data_folder dm = LocalDataManager(None) print("Load dataset...") default_test_cfg = { 'key': 'scenes/test.zarr',
from lib.training.lr_scheduler import LRScheduler from lib.training.snapshot_object_when_lr_increase import SnapshotObjectWhenLRIncrease from lib.utils.resumable_distributed_sampler import ResumableDistributedSampler from lib.functions.nll import pytorch_weighted_neg_multi_log_likelihood_batch, pytorch_neg_multi_log_likelihood_batch if __name__ == '__main__': # --- Distributed initial setup --- is_mpi, rank, world_size, local_rank = setup_distributed() print(f"is_mpi {is_mpi}, rank {rank}, world_size {world_size}, local_rank {local_rank}") # --- Distributed initial setup done --- mode = "distributed" if is_mpi else "" flags: Flags = load_flags(mode=mode) flags_dict = dataclasses.asdict(flags) cfg = load_yaml(flags.cfg_filepath) out_dir = Path(flags.out_dir) if local_rank == 0: print(f"cfg {cfg}") os.makedirs(str(out_dir), exist_ok=True) print(f"flags: {flags_dict}") save_yaml(out_dir / 'flags.yaml', flags_dict) save_yaml(out_dir / 'cfg.yaml', cfg) debug = flags.debug # set env variable for data os.environ["L5KIT_DATA_FOLDER"] = flags.l5kit_data_folder dm = LocalDataManager(None) # ===== INIT DATASET if local_rank == 0:
# h = torch.sum(h, dim=(-1, -2)) h = torch.mean(h, dim=(-1, -2)) else: # [128, 2048, 4, 4] when input is (128, 128) bs, ch, height, width = h.shape h = h.view(bs, ch*height*width) for layer in self.lin_layers: h = layer(h) return h if __name__ == '__main__': # --- test instantiation --- from lib.utils.yaml_utils import load_yaml cfg = load_yaml("../../../../modeling/configs/0905_cfg.yaml") num_modes = 3 model = ResNeStMulti(cfg, num_modes=num_modes) print(type(model)) print(model) bs = 3 in_channels = model.in_channels height, width = 224, 224 device = "cuda:0" x = torch.rand((bs, in_channels, height, width), dtype=torch.float32).to(device) model.to(device) # pred, confidences = model(x) # print("pred", pred.shape, "confidences", confidences.shape) h = model(x)
return len(self.get_frame_arguments) def __getitem__(self, index: int) -> dict: track_id, scene_index, state_index = self.get_frame_arguments[index] # return self.ego_dataset.get_frame(scene_index, state_index, track_id=track_id) return get_frame_custom(self.ego_dataset, scene_index, state_index, track_id=track_id) if __name__ == "__main__": from l5kit.data import LocalDataManager from l5kit.rasterization import build_rasterizer from lib.utils.yaml_utils import load_yaml repo_root = Path(__file__).parent.parent.parent.parent dm = LocalDataManager(local_data_folder=str(repo_root / "input" / "lyft-motion-prediction-autonomous-vehicles")) dataset = ChunkedDataset(dm.require("scenes/sample.zarr")).open(cached=False) cfg = load_yaml(repo_root / "src" / "modeling" / "configs" / "0905_cfg.yaml") rasterizer = build_rasterizer(cfg, dm) faster_agent_dataset = FasterAgentDataset(cfg, dataset, rasterizer, None) fast_agent_dataset = FastAgentDataset(cfg, dataset, rasterizer, None) assert len(faster_agent_dataset) == len(fast_agent_dataset) keys = ["image", "target_positions", "target_availabilities"] for index in tqdm(range(min(1000, len(faster_agent_dataset)))): actual = faster_agent_dataset[index] expected = fast_agent_dataset[index] for key in keys: assert (actual[key] == expected[key]).all()