示例#1
0
def _config(_path_wd, _datapath):

    path_wd = str(_path_wd)
    datapath = str(_datapath)
    filename_ann = 'mnist_cnn'
    configparser = import_configparser()
    config = configparser.ConfigParser()

    config.read_dict({
        'paths': {
            'path_wd': path_wd,
            'dataset_path': datapath,
            'filename_ann': filename_ann
        }
    })

    with open(os.path.join(path_wd, filename_ann + '.h5'), 'w'):
        pass

    config_filepath = os.path.join(path_wd, 'config')
    with open(config_filepath, 'w') as configfile:
        config.write(configfile)

    config = update_setup(config_filepath)

    return config
示例#2
0
def main(filepath=None):
    """Entry point for running the toolbox.

    Note
    ----

    There is no need to call this function directly, because python sets up an
    executable during :ref:`installation` that can be called from terminal.

    """
    from snntoolbox.bin.utils import update_setup, run_pipeline

    if filepath is not None:
        config = update_setup(filepath)
        run_pipeline(config)
        return

    parser = argparse.ArgumentParser(
        description='Run SNN toolbox to convert an analog neural network into '
        'a spiking neural network, and optionally simulate it.')
    parser.add_argument('config_filepath',
                        nargs='?',
                        help='Path to configuration file.')
    parser.add_argument('-t',
                        '--terminal',
                        action='store_true',
                        help='Set this flag to run the toolbox from terminal. '
                        'Omit this flag to open GUI.')
    args = parser.parse_args()

    _filepath = os.path.abspath(args.config_filepath)
    if _filepath is not None:
        config = update_setup(_filepath)

        if args.terminal:
            run_pipeline(config)
        else:
            from snntoolbox.bin.gui import gui
            gui.main()
    else:
        if args.terminal:
            parser.error("When using the SNN toolbox from terminal, a "
                         "config_filepath argument must be provided.")
            return
        else:
            from snntoolbox.bin.gui import gui
            gui.main()
示例#3
0
def test_updating_settings(params, expect_pass, _path_wd):
    configparser = import_configparser()
    config = configparser.ConfigParser()
    config.read_dict(params)
    configpath = os.path.join(str(_path_wd), 'config')
    with open(configpath, 'w') as file:
        config.write(file)
    if expect_pass:
        assert update_setup(configpath)
    else:
        pytest.raises(AssertionError, update_setup, configpath)
示例#4
0
def main():
    """Entry point for running the toolbox.

    Note
    ----

    There is no need to call this function directly, because python sets up an
    executable during :ref:`installation` that can be called from terminal.

    """
    import numpy as np
    np.random.seed(100)  #LQ: same random seed for every run

    parser = argparse.ArgumentParser(
        description='Run SNN toolbox to convert an analog neural network into '
        'a spiking neural network, and optionally simulate it.')
    parser.add_argument('config_filepath',
                        nargs='?',
                        help='Path to configuration file.')
    parser.add_argument('-t',
                        '--terminal',
                        action='store_true',
                        help='Set this flag to run the toolbox from terminal. '
                        'Omit this flag to open GUI.')
    args = parser.parse_args()

    filepath = os.path.abspath(args.config_filepath)
    #filepath = '/mnt/2646BAF446BAC3B9/Repositories/NPP/snn_toolbox/examples/models/lenet5/keras/config'
    #filepath = '/home/rbodo/.snntoolbox/data/mnist/cnn/lenet5/keras/32bit/log/gui/14/config'
    #args.terminal = True

    print(filepath)  #LQ: Print out the path of the configuration file

    if filepath is not None:
        assert os.path.isfile(filepath), \
            "Configuration file not found at {}.".format(filepath)
        from snntoolbox.bin.utils import update_setup
        config = update_setup(filepath)

        if args.terminal:
            from snntoolbox.bin.utils import test_full
            test_full(config)
        else:
            from snntoolbox.bin.gui import gui
            gui.main()
    else:
        if args.terminal:
            parser.error("When using the SNN toolbox from terminal, a "
                         "config_filepath argument must be provided.")
            return
        else:
            from snntoolbox.bin.gui import gui
            gui.main()
示例#5
0
def test_updating_settings(params, expect_pass, _path_wd):
    from snntoolbox.bin.utils import update_setup
    try:
        import configparser
    except ImportError:
        import ConfigParser as configparser
    config = configparser.ConfigParser()
    config.read_dict(params)
    configpath = os.path.join(str(_path_wd), 'config')
    with open(configpath, 'w') as f:
        config.write(f)
    if expect_pass:
        assert update_setup(configpath)
    else:
        pytest.raises(AssertionError, update_setup, configpath)
示例#6
0
def _config():
    from snntoolbox.bin.utils import update_setup
    return update_setup(
        os.path.join(os.path.dirname(__file__), 'configurations', 'config0'))
示例#7
0
    def test_examples(self, _example_filepath):
        from snntoolbox.bin.utils import update_setup, test_full

        config = update_setup(_example_filepath)
        assert test_full(config)[0] >= 0.5
示例#8
0
            np.array(copy.deepcopy(weights[i]), dtype="int32").flatten())

    return weights


model_lib = import_module("snntoolbox.parsing.model_libs.keras_input_lib")
input_model = model_lib.load(os.path.dirname(model_path),
                             os.path.basename(model_path))

acc = model_lib.evaluate(input_model['val_fn'],
                         batch_size=1,
                         num_to_test=50,
                         x_test=testX[:50],
                         y_test=testY[:50])

config = update_setup(config_path)
config.set("paths", "path_wd", os.path.dirname(model_path))
config.set("paths", "dataset_path", os.path.dirname(model_path))
config.set("paths", "filename_ann", os.path.basename(model_path))
model_parser = model_lib.ModelParser(input_model['model'], config)
model_parser.parse()
parsed_model = model_parser.build_parsed_model()

# Normalize
norm_data = {'x_norm': testX}
normalize_parameters(parsed_model, config, **norm_data)

score_norm = model_parser.evaluate(batch_size=1,
                                   num_to_test=50,
                                   x_test=testX[:50],
                                   y_test=testY[:50])