Ejemplo n.º 1
0
    def run(self):
        if self.prepare_data:
            prepare_data_conf = read_json(self.const).get("prepare_data")
            with pushd(self.working_dir):
                opt, value = prepare_data(prepare_data_conf)
            self.add_options[opt_to_str(opt)] = value
        evals = []
        for self.current_epoch in xrange(self.current_epoch, self.current_epoch+self.epochs):
            logging.info("Running epoch {}:".format(self.current_epoch))
            run_proc(**self.construct_cmd())
            if self.inspection:
                if self.evaluation_data:
                    logging.info("running on evaluation data ...")
                    run_proc(**self.construct_eval_run_cmd())
                logging.info("inspecting ... ")
                with pushd(self.working_dir):
                    o = run_proc(**self.construct_inspect_cmd())
                    if self.evaluation:
                        evals.append(float(o.strip()))
                        logging.info("Evaluation score: {}".format(evals[-1]))

        if len(evals)>0:
            final_score = sum(evals)/len(evals)
            logging.info("Final evaluation score: {}".format(final_score))
            if self.slave:
                print final_score
        logging.info("Done")
Ejemplo n.º 2
0
    def run(self):
        if self.prepare_data:
            prepare_data_conf = read_json(self.const).get("prepare_data")
            with pushd(self.working_dir):
                opt, value = prepare_data(prepare_data_conf)
            self.add_options[opt_to_str(opt)] = value
        evals = []
        for self.current_epoch in xrange(self.current_epoch,
                                         self.current_epoch + self.epochs):
            logging.info("Running epoch {}:".format(self.current_epoch))
            run_proc(**self.construct_cmd())
            if self.inspection:
                if self.evaluation_data:
                    logging.info("running on evaluation data ...")
                    run_proc(**self.construct_eval_run_cmd())
                logging.info("inspecting ... ")
                with pushd(self.working_dir):
                    o = run_proc(**self.construct_inspect_cmd())
                    if self.evaluation:
                        evals.append(float(o.strip()))
                        logging.info("Evaluation score: {}".format(evals[-1]))

        if len(evals) > 0:
            final_score = sum(evals) / len(evals)
            logging.info("Final evaluation score: {}".format(final_score))
            if self.slave:
                print final_score
        logging.info("Done")
Ejemplo n.º 3
0
def main(argv):
    parser = argparse.ArgumentParser(description='Tool for simulating dnn')
    parser.add_argument('-e', 
                        '--epochs', 
                        required=False,
                        help='Number of epochs to run', default=DnnSim.EPOCHS,type=int)
    parser.add_argument('-j', 
                        '--jobs', 
                        required=False,
                        help='Number of parallell jobs (default: %(default)s)', default=DnnSim.JOBS, type=int)
    parser.add_argument('-T', 
                        '--T-max', 
                        required=False,
                        help='Run only specific amount of simulation time (ms)')
    parser.add_argument('-o', 
                        '--old-dir', 
                        action='store_true',
                        help='Do not create new dir for that simulation')
    parser.add_argument('-s', 
                        '--stat',
                        action='store_true',
                        help='Save statistics')
    parser.add_argument('-ni', 
                        '--no-insp',
                        action='store_true',
                        help='No inspection after every epoch')
    parser.add_argument('-nl', 
                        '--no-learning',
                        action='store_true',
                        help='Turn off learning')
    parser.add_argument('-nev', 
                        '--no-evaluation',
                        action='store_true',
                        help='Turning on evaluation mode, where program writing score on each epoch')
    parser.add_argument('--slave',
                        action='store_true',
                        help='Run script as slave and print only evaluation score')
    parser.add_argument('-r', 
                        '--runs-dir', 
                        required=False,
                        help='Runs dir (default: %(default)s)', default=DnnSim.RUNS_DIR)
    parser.add_argument('-w', 
                        '--working-dir',
                        required=False,
                        help='Working dir (default: %%runs_dir%%/%%md5_of_const%%_%%number_of_experiment%%)')
    parser.add_argument('-c', 
                        '--const', 
                        required=False,
                        help='Path to const.json file (default: $SCRIPT_DIR/../dnn_project/%s)' % DnnSim.CONST_JSON)
    parser.add_argument('--dnn-sim-bin', 
                        required=False,
                        help='Path to snn sim bin (default: $SCRIPT_DIR/../build/bin/%s)' % DnnSim.DNN_SIM_BIN)
    parser.add_argument('-pd', 
                        '--prepare-data',
                        action='store_true',
                        help='Run prepare data procedure')
    parser.add_argument('-evd', 
                        '--evaluation-data',
                        required=False,
                        help='Run evaluation on special testing data. If not pointed evaluation will be runned on train data')
    args, other = parser.parse_known_args(argv)

    if len(argv) == 0:
        parser.print_help()
        sys.exit(1)
    args = {
        "working_dir" : args.working_dir,
        "T_max" : args.T_max,
        "stat" : args.stat,
        "runs_dir" : args.runs_dir,
        "const" : args.const,
        "dnn_sim_bin" : args.dnn_sim_bin,
        "add_options" : {},
        "epochs" : args.epochs,
        "jobs" : args.jobs,
        "old_dir" : args.old_dir,
        "inspection" : not args.no_insp,
        "evaluation" : not args.no_evaluation,
        "slave" : args.slave,
        "prepare_data" : args.prepare_data,
        "evaluation_data" : args.evaluation_data,
        "no_learning" : args.no_learning,
    }
    if len(other) % 2 != 0:
        raise Exception("Got not paired add options: {}".format(" ".join(other)))
    for i in range(0, len(other), 2):
        args['add_options'].update( { opt_to_str(other[i]) : other[i+1] })


    s = DnnSim(**args)
    s.run()
Ejemplo n.º 4
0
def main(argv):
    parser = argparse.ArgumentParser(description='Tool for simulating dnn')
    parser.add_argument('-e',
                        '--epochs',
                        required=False,
                        help='Number of epochs to run',
                        default=DnnSim.EPOCHS,
                        type=int)
    parser.add_argument('-j',
                        '--jobs',
                        required=False,
                        help='Number of parallell jobs (default: %(default)s)',
                        default=DnnSim.JOBS,
                        type=int)
    parser.add_argument(
        '-T',
        '--T-max',
        required=False,
        help='Run only specific amount of simulation time (ms)')
    parser.add_argument('-o',
                        '--old-dir',
                        action='store_true',
                        help='Do not create new dir for that simulation')
    parser.add_argument('-s',
                        '--stat',
                        action='store_true',
                        help='Save statistics')
    parser.add_argument('-ni',
                        '--no-insp',
                        action='store_true',
                        help='No inspection after every epoch')
    parser.add_argument('-nl',
                        '--no-learning',
                        action='store_true',
                        help='Turn off learning')
    parser.add_argument(
        '-nev',
        '--no-evaluation',
        action='store_true',
        help=
        'Turning on evaluation mode, where program writing score on each epoch'
    )
    parser.add_argument(
        '--slave',
        action='store_true',
        help='Run script as slave and print only evaluation score')
    parser.add_argument('-r',
                        '--runs-dir',
                        required=False,
                        help='Runs dir (default: %(default)s)',
                        default=DnnSim.RUNS_DIR)
    parser.add_argument(
        '-w',
        '--working-dir',
        required=False,
        help=
        'Working dir (default: %%runs_dir%%/%%md5_of_const%%_%%number_of_experiment%%)'
    )
    parser.add_argument(
        '-c',
        '--const',
        required=False,
        help='Path to const.json file (default: $SCRIPT_DIR/../dnn_project/%s)'
        % DnnSim.CONST_JSON)
    parser.add_argument(
        '--dnn-sim-bin',
        required=False,
        help='Path to snn sim bin (default: $SCRIPT_DIR/../build/bin/%s)' %
        DnnSim.DNN_SIM_BIN)
    parser.add_argument('-pd',
                        '--prepare-data',
                        action='store_true',
                        help='Run prepare data procedure')
    parser.add_argument(
        '-evd',
        '--evaluation-data',
        required=False,
        help=
        'Run evaluation on special testing data. If not pointed evaluation will be runned on train data'
    )
    args, other = parser.parse_known_args(argv)

    if len(argv) == 0:
        parser.print_help()
        sys.exit(1)
    args = {
        "working_dir": args.working_dir,
        "T_max": args.T_max,
        "stat": args.stat,
        "runs_dir": args.runs_dir,
        "const": args.const,
        "dnn_sim_bin": args.dnn_sim_bin,
        "add_options": {},
        "epochs": args.epochs,
        "jobs": args.jobs,
        "old_dir": args.old_dir,
        "inspection": not args.no_insp,
        "evaluation": not args.no_evaluation,
        "slave": args.slave,
        "prepare_data": args.prepare_data,
        "evaluation_data": args.evaluation_data,
        "no_learning": args.no_learning,
    }
    if len(other) % 2 != 0:
        raise Exception("Got not paired add options: {}".format(
            " ".join(other)))
    for i in range(0, len(other), 2):
        args['add_options'].update({opt_to_str(other[i]): other[i + 1]})

    s = DnnSim(**args)
    s.run()