def main(): args = arg_parser.parse_args() config_name = args.config.split("/")[-1].split(".")[0] with open(args.log_config) as log_config_f: log_filename = "logs/%s.log" % config_name log_config = yaml.load(log_config_f) log_config["handlers"]["fileHandler"]["filename"] = log_filename logging.config.dictConfig(log_config) with open(args.config) as config_f: config = util.Struct(**yaml.load(config_f)) task = tasks.load_task(config.task) model = models.build_model(config.model, config.opt) for i_iter in range(config.opt.iters): do_eval = i_iter % 5 == 0 train_loss, train_acc = batched_iter( task.train, model, config, train=True, compute_eval=do_eval) if do_eval: val_loss, val_acc = batched_iter( task.val, model, config, compute_eval=True) visualizer.begin(config_name, 100) test_loss, test_acc = batched_iter( task.test, model, config, compute_eval=True) visualizer.end() logging.info("%5d : %2.4f %2.4f %2.4f : %2.4f %2.4f %2.4f", i_iter, train_loss, val_loss, test_loss, train_acc, val_acc, test_acc) model.save("saves/%s_%d.caffemodel" % (config_name, i_iter)) else: logging.info("%5d : %2.4f", i_iter, train_loss)
def main(): config = configure() task = tasks.load_task(config) model = models.build_model(config.model, config.opt) for i_epoch in range(config.opt.iters): train_loss, train_acc, _ = \ do_iter(task.train, model, config, train=True) val_loss, val_acc, val_predictions = \ do_iter(task.val, model, config, vis=True) test_loss, test_acc, test_predictions = \ do_iter(task.test, model, config) logging.info("%5d | %8.3f %8.3f %8.3f | %8.3f %8.3f %8.3f", i_epoch, train_loss, val_loss, test_loss, train_acc, val_acc, test_acc) with open("logs/val_predictions_%d.json" % i_epoch, "w") as pred_f: print >> pred_f, json.dumps(val_predictions)
def main(): config = configure() task = tasks.load_task(config) model = models.build_model(config.model, config.opt) for i_epoch in range(config.opt.iters): train_loss, train_acc, _ = do_iter(task.train, model, config, train=True) val_loss, val_acc, val_predictions = do_iter(task.val, model, config, vis=True) test_loss, test_acc, test_predictions = do_iter(task.test, model, config) logging.info( "%5d | %8.3f %8.3f %8.3f | %8.3f %8.3f %8.3f", i_epoch, train_loss, val_loss, test_loss, train_acc, val_acc, test_acc, ) with open("logs/val_predictions_%d.json" % i_epoch, "w") as pred_f: print >> pred_f, json.dumps(val_predictions)