# create training folder
        model_id = 'model_fold' + str(config['fold']) + '_' + str(
            shared.get_epoch_time())
        model_folder = experiment_folder + model_id + '/'
        if not os.path.exists(model_folder):
            os.makedirs(model_folder)

        # listing all models trained for this experiment
        fall = open(experiment_folder + 'models.list', 'a')
        fall.write(str(model_id) + '\n')
        fall.close()

        # few-shot learning: data selection/preparation
        tmp_data = shared.few_shot_data_preparation(all_ids_train, all_ids_val,
                                                    config['classes_vector'],
                                                    label2ids_train,
                                                    label2ids_val, config)
        [ids_train, ids_val, _] = tmp_data

        # pescador train: define streamer
        train_pack = [
            config, config['train_sampling'], config['param_train_sampling']
        ]
        train_streams = [
            pescador.Streamer(data_gen, id, id2audio_repr_path[id],
                              id2gt_train[id], train_pack) for id in ids_train
        ]
        train_mux_stream = pescador.StochasticMux(
            train_streams,
            n_active=config['batch_size'] * 2,
            rate=None,
                'Update\tEpoch\tloss\tmean_distance_protos\tmean_gradients\taccuracy\talpha\tbeta\n'
            )
        else:
            fy.write(
                'Update\tEpoch\tloss\tmean_distance_protos\tmean_gradients\taccuracy\n'
            )
        fy.close()

        # saving a list of all the models trained for this experiment
        fall = open(experiment_folder + 'models.list', 'a')
        fall.write(str(model_id) + '\n')
        fall.close()

        # few-shot learning: ids selection
        tmp_ids = shared.few_shot_data_preparation(all_ids_train, all_ids_test,
                                                   classes_vector,
                                                   label2ids_train,
                                                   label2ids_test, config)
        [ids_train, ids_test, label2selectedIDs] = tmp_ids

        # few-shot learning: fetch data
        tmp_data = fetch_data(classes_vector, label2selectedIDs,
                              id2audio_repr_path, id2gt_train, config)
        [
            train_set_dic, train_gt_dic, train_id_dic,
            minimum_number_of_patches, total_number_of_patches
        ] = tmp_data

        # tensorflow: create a session to run the tensorflow graph
        sess.run(tf.global_variables_initializer())

        # training
Пример #3
0
        elif config[
                'num_classes_dataset'] == 10:  # dummy dictionary for US8k dataset (to easily share this function)
            dummy_dic = {
                0: [],
                1: [],
                2: [],
                3: [],
                4: [],
                5: [],
                6: [],
                7: [],
                8: [],
                9: []
            }
        tmp_data = shared.few_shot_data_preparation(all_ids_train, dummy_list,
                                                    config['classes_vector'],
                                                    label2ids_train, dummy_dic,
                                                    config)
        [ids_train, _, _] = tmp_data

        # pescador train: define streamer
        train_pack = [
            config, config['train_sampling'], config['param_train_sampling']
        ]
        train_streams = [
            pescador.Streamer(data_gen, id, id2audio_repr_path[id],
                              id2gt_train[id], train_pack) for id in ids_train
        ]
        train_mux_stream = pescador.StochasticMux(
            train_streams,
            n_active=config['batch_size'] * 2,
            rate=None,