if init:
            os.system('rm -rf inputs/{directory}/train/'.format(**context))
            os.system('mkdir -p inputs/{directory}/train/'.format(**context))
            elib.create_rbp_init(
                base_filename='inputs/{directory}/train/fwmat'.format(
                    **context),
                **context)

        if new_test_data:
            os.system('rm -rf inputs/{directory}/test/'.format(**context))
            os.system('mkdir -p inputs/{directory}/test/'.format(**context))
            sample_duration_test, labels_test = gras.create_ras_from_aedat(
                n_samples_test,
                context['directory'],
                "test",
                randomize=False,
                pause_duration=context['sample_pause_test'],
                event_polarity=context['event_polarity'],
                cache=True,
                max_neuron_id=context['nv'] - context['nc'],
                clean_h5file=True)
            context['simtime_test'] = sample_duration_test[-1]
            print(context['simtime_test'])
            with open('inputs/{directory}/test/simtime.json'.format(**context),
                      'w+') as simtime_file:
                json.dump(
                    {
                        'context': context,
                        'labels_test': labels_test,
                        'sample_duration_test': sample_duration_test
                    }, simtime_file)
                print('New test data : {}\n{}\n{}'.format(
        test_every = context['test_every']
        nv = context['nv']
        nh = context['nh']
        nc = context['nc']

        if init:
            os.system('rm -rf inputs/{directory}/train/'.format(**context))
            os.system('mkdir -p inputs/{directory}/train/'.format(**context))
            elib.create_rbp_init(base_filename='inputs/{directory}/train/fwmat'.format(**context), **context)

        if new_test_data:
            os.system('rm -rf inputs/{directory}/test/'.format(**context))
            os.system('mkdir -p inputs/{directory}/test/'.format(**context))
            sample_duration_test, labels_test = gras.create_ras_from_aedat(n_samples_test,
                                                                           context['directory'], "test",
                                                                           randomize=False,
                                                                           pause_duration=context['sample_pause_test'],
                                                                           event_polarity=context['event_polarity'],
                                                                           cache=True)
            context['simtime_test'] = sample_duration_test[-1]
            print(context['simtime_test'])
            with open('inputs/{directory}/test/simtime.txt'.format(**context), 'w+') as simtime_file:
                simtime_file.write('{}\n{}\n{}'.format(n_samples_test, labels_test, sample_duration_test))
                print('New test data : {}\n{}\n{}'.format(n_samples_test, labels_test, sample_duration_test))
        else:
            with open('inputs/{directory}/test/simtime.txt'.format(**context), 'r') as simtime_file:
                file_string_list = simtime_file.read().splitlines()
                read_n_samples = file_string_list[0]
                if int(read_n_samples) != n_samples_test:
                    print("Current test ras file does not fit the number of test samples.")
                    sys.exit()
                labels_test = np.array(file_string_list[1][1:-1].split(','), dtype=int)
        if new_test_data or not os.path.exists(
                'inputs/{directory}/test/simtime.json'.format(**context)):
            print("Generating new test data")
            os.system('rm -rf inputs/{directory}/test/'.format(**context))
            os.system('mkdir -p inputs/{directory}/test/'.format(**context))

            sample_duration_test, labels_test = gras.create_ras_from_aedat(
                n_samples_test,
                context['directory'],
                "test",
                randomize=False,
                pause_duration=context['sample_pause_test'],
                event_polarity=context['polarity'],
                cache=True,
                max_neuron_id=max_neuron_id,
                delay=context['delay'],
                attention_event_amount=context['attention_event_amount'],
                attention_window_size=context['attention_window_size'],
                input_window_position=context['input_window_position'],
                only_input_position=context['only_input_position'],
                new_pos_weight=context['new_pos_weight'],
                recurrent=context['recurrent'],
                label_frequency=context['label_frequency'],
                clean_h5file=True)
            context['simtime_test'] = sample_duration_test[-1]
            print(context['simtime_test'])
            with open('inputs/{directory}/test/simtime.json'.format(**context),
                      'w+') as simtime_file:
                json.dump(
                    {
                        'context': context,
Пример #4
0
            os.system('rm -rf inputs/{directory}/train/'.format(**context))
            os.system('mkdir -p inputs/{directory}/train/'.format(**context))
            elib.create_rbp_init(
                base_filename='inputs/{directory}/train/fwmat'.format(
                    **context),
                **context)

        if new_test_data:
            os.system('rm -rf inputs/{directory}/test/'.format(**context))
            os.system('mkdir -p inputs/{directory}/test/'.format(**context))
            sample_duration_test, labels_test = gras.create_ras_from_aedat(
                n_samples_test,
                context['directory'],
                "test",
                test_labels_name,
                randomize=False,
                pause_duration=context['sample_pause_test'],
                cache=True,
                event_polarity=context['polarity'],
                max_neuron_id=max_neuron_id,
                label_frequency=context['label_frequency'],
                no_noise=context['no_noise'])
            context['simtime_test'] = sample_duration_test[-1]
            print(context['simtime_test'])
            with open('inputs/{directory}/test/simtime.json'.format(**context),
                      'w+') as simtime_file:
                json.dump(
                    {
                        'context': context,
                        'labels_test': labels_test,
                        'sample_duration_test': sample_duration_test
                    }, simtime_file)