running_loss = coach.train(trainloader, epoch=epoch) writter.add_scalar("Loss", running_loss, epoch) evaluate(valider=valider, trainloader=trainloader, testloader=testloader, acc_logger=acc_logger, rob_logger=rob_logger, writter=writter, epoch=opts.epochs) acc_logger.plotter.plot() rob_logger.plotter.plot() acc_logger.plotter.save(writter) rob_logger.plotter.save(writter) if __name__ == "__main__": from torch.utils.tensorboard import SummaryWriter from src.utils import mkdirs, readme cfg = load_cfg() mkdirs(cfg.info_path, cfg.log_path) readme(cfg.info_path, opts) readme(cfg.log_path, opts, mode="a") writter = SummaryWriter(log_dir=cfg.log_path, filename_suffix=METHOD) main(**cfg) cfg['coach'].save(cfg.info_path) writter.close()
# { # "Linf": running_distance_linf[epsilon], # "L2": running_distance_l2[epsilon], # }, # epsilon # ) running_accuracy = list(map(lambda x: 1. - x, running_success)) running_accuracy = ', '.join([f"{acc:.3%}" for acc in running_accuracy]) running_distance_linf = ', '.join( [f"{dis_linf:.5f}" for dis_linf in running_distance_linf]) running_distance_l2 = ', '.join( [f"{dis_l2:.5f}" for dis_l2 in running_distance_l2]) print(f"Accuracy: {running_accuracy}") print(f"Distance-Linf: {running_distance_linf}") print(f"Distance-L2: {running_distance_l2}") if __name__ == "__main__": from torch.utils.tensorboard import SummaryWriter from src.utils import mkdirs, readme cfg, log_path = load_cfg() mkdirs(log_path) readme(log_path, opts, mode="a") writter = SummaryWriter(log_dir=log_path, filename_suffix=METHOD) main(**cfg) writter.close()