Example #1
0
        if self.args.multi_maps:
            spatial_map = torch.cat(all_spatial_maps, dim=1).flatten(0, 1)
            mask = torch.cat(all_masks, dim=1).flatten(0, 1)

            seq = seq.unsqueeze(1).expand(-1, self.args.timesteps, -1).flatten(0, 1)
            seq_lens = seq_lens.unsqueeze(1).expand(-1, self.args.timesteps).flatten(0, 1)

        # Predict with unet
        pred = self.navigator(seq, seq_lens, spatial_map)

        # shape: (batch_size*timesteps, 2)
        goal_pred = pred[:, 0, :, :]
        path_pred = pred[:, 1, :, :]

        return goal_pred, path_pred, mask


if __name__ == "__main__":

    args = cfg.parse_args()
    args_text = cfg.print_args(args)

    if args.eval is False:
        trainer = PVNBaselineTrainer(args=args)
        trainer.train()
    else:
        filepath = "%s/%s/%s_%d" % (args.snapshot_dir, args.exp_name, args.exp_name, args.val_epoch)
        trainer = PVNBaselineEvaluator(filepath=filepath, args=args)
        trainer.evaluate("val_seen")
        trainer.evaluate("val_unseen")
Example #2
0
    def __init__(self, args, filepath=None, load_sim=True):
        self.args = copy.deepcopy(args)
        if filepath:
            # Copy args from the loaded config to self.args. This ensures old models can still
            # be loaded even after new args are added to the config
            self.loader = torch.load(filepath)
            print("Loading from checkpoint: %s" % filepath)
            for arg, value in vars(self.loader["args"]).items():
                setattr(self.args, arg, value)

            # eval parameters override
            self.args.filepath = filepath
            self.args.eval = args.eval
            self.args.val_epoch = args.val_epoch
            self.args.batch_size = args.batch_size
            self.args.viz_eval = args.viz_eval
            self.args.viz_gif = args.viz_gif
            self.args.viz_iterations = args.viz_iterations
            self.args.viz_folder = args.viz_folder
            self.args.visdom = args.visdom
            self.args.visdom_env = args.visdom_env
            self.args.visdom_server = args.visdom_server
            self.args.visdom_port = args.visdom_port
            self.args.preloading = args.preloading
            self.args.debug_scale = args.debug_scale
            self.args.debug_mode = args.debug_mode
            self.args.start_epoch = args.start_epoch

        if self.args.visdom:
            visdom_env = self.args.exp_name if self.args.visdom_env == "" else self.args.visdom_env
            self.visdom = VisdomVisualize(env_name=visdom_env,
                                          win_prefix=self.args.exp_name + "_",
                                          server=self.args.visdom_server,
                                          port=self.args.visdom_port)
            self.visdom.text(
                cfg.print_args(self.args, verbose=False).replace("\n", "<br>"))
        else:
            self.visdom = None

        # Set random seed before anything
        seed = self.args.random_seed
        if self.args.start_epoch != 1 and self.args.eval == False:
            seed = self.args.start_epoch + seed
        utils.set_random_seed(seed)

        if load_sim:
            self.sim = PanoSimulator(self.args)

        # Load data (trajectories, scans, graphs, vocab)
        if not self.args.eval:
            splits = ['train', 'val_seen', 'val_unseen'
                      ] if self.args.train_split == 'trainval' else ['train']
            self.traindata = DataLoader(self.args, splits=splits)
        self.valseendata = DataLoader(self.args, splits=['val_seen'])
        self.valunseendata = DataLoader(self.args, splits=['val_unseen'])

        self.all_scans = self.valseendata.scans | self.valunseendata.scans
        if not self.args.eval:
            self.all_scans |= self.traindata.scans
        self.floorplan = Floorplan(
            self.args.debug_scale / self.args.gridcellsize,
            list(self.all_scans))