Пример #1
0
def build_acoustic_training_rnn(is_mpi,is_chief, hyper_params, prog_params, train_set, test_set):
    model = AcousticModel(hyper_params["num_layers"], hyper_params["hidden_size"], hyper_params["batch_size"],
                          hyper_params["max_input_seq_length"], hyper_params["max_target_seq_length"],
                          hyper_params["input_dim"], hyper_params["batch_normalization"],
                          hyper_params["char_map_length"])

    # Create a Dataset from the train_set and the test_set
    train_dataset = model.build_dataset(train_set, hyper_params["batch_size"], hyper_params["max_input_seq_length"],
                                        hyper_params["max_target_seq_length"], hyper_params["signal_processing"],
                                        hyper_params["char_map"])
    #train_dataset = train_dataset.shuffle(10,reshuffle_each_iteration=True)
    v_iterator = None
    if test_set is []:
        t_iterator = model.add_dataset_input(train_dataset)
    else:
        test_dataset = model.build_dataset(test_set, hyper_params["batch_size"], hyper_params["max_input_seq_length"],
                                           hyper_params["max_target_seq_length"], hyper_params["signal_processing"],
                                           hyper_params["char_map"])
        # Build the input stream from the different datasets
        t_iterator, v_iterator = model.add_datasets_input(train_dataset, test_dataset)

    # Create the model
    #tensorboard_dir

    model.create_training_rnn(is_mpi, hyper_params["dropout_input_keep_prob"], hyper_params["dropout_output_keep_prob"],
                              hyper_params["grad_clip"], hyper_params["learning_rate"],
                              hyper_params["lr_decay_factor"], use_iterator=True,is_sync=prog_params['is_sync'],is_chief=is_chief)

    if is_chief:
        model.add_tensorboard(prog_params["train_dir"], prog_params["timeline"])
    return model, t_iterator, v_iterator
Пример #2
0
def build_acoustic_training_rnn(is_chief, is_ditributed, sess, hyper_params,
                                prog_params, train_set, test_set):
    model = AcousticModel(
        hyper_params["num_layers"], hyper_params["hidden_size"],
        hyper_params["batch_size"], hyper_params["max_input_seq_length"],
        hyper_params["max_target_seq_length"], hyper_params["input_dim"],
        hyper_params["batch_normalization"], hyper_params["char_map_length"])

    # Create a Dataset from the train_set and the test_set
    train_dataset = model.build_dataset(train_set, hyper_params["batch_size"],
                                        hyper_params["max_input_seq_length"],
                                        hyper_params["max_target_seq_length"],
                                        hyper_params["signal_processing"],
                                        hyper_params["char_map"])
    train_dataset = train_dataset.shuffle(10, reshuffle_each_iteration=True)
    v_iterator = None
    if test_set is []:
        t_iterator = model.add_dataset_input(train_dataset)
    else:
        test_dataset = model.build_dataset(
            test_set, hyper_params["batch_size"],
            hyper_params["max_input_seq_length"],
            hyper_params["max_target_seq_length"],
            hyper_params["signal_processing"], hyper_params["char_map"])
        # Build the input stream from the different datasets
        t_iterator, v_iterator = model.add_datasets_input(
            train_dataset, test_dataset)

    # Create the model
    #tensorboard_dir
    model.create_training_rnn(is_chief,
                              is_ditributed,
                              hyper_params["dropout_input_keep_prob"],
                              hyper_params["dropout_output_keep_prob"],
                              hyper_params["grad_clip"],
                              hyper_params["learning_rate"],
                              hyper_params["lr_decay_factor"],
                              use_iterator=True)
    model.add_tensorboard(sess, prog_params["train_dir"],
                          prog_params["timeline"])
    sv = None
    if is_ditributed:
        init_op = tf.global_variables_initializer()
        sv = tf.train.Supervisor(is_chief=is_chief,
                                 logdir=prog_params["train_dir"],
                                 init_op=init_op,
                                 recovery_wait_secs=1,
                                 summary_op=None,
                                 global_step=model.global_step)
        model.supervisor = sv
    else:
        model.initialize(sess)
        model.restore(sess, prog_params["train_dir"])

    # Override the learning rate if given on the command line
    if prog_params["learn_rate"] is not None:
        model.set_learning_rate(sess, prog_params["learn_rate"])

    return sv, model, t_iterator, v_iterator
Пример #3
0
def build_acoustic_training_rnn(sess, hyper_params, prog_params, train_set,
                                test_set):
    model = AcousticModel(
        hyper_params["num_layers"], hyper_params["hidden_size"],
        hyper_params["batch_size"], hyper_params["max_input_seq_length"],
        hyper_params["max_target_seq_length"], hyper_params["input_dim"],
        hyper_params["batch_normalization"], hyper_params["char_map_length"])

    # Create a Dataset from the train_set and the test_set
    train_dataset = model.build_dataset(train_set, hyper_params["batch_size"],
                                        hyper_params["max_input_seq_length"],
                                        hyper_params["max_target_seq_length"],
                                        hyper_params["signal_processing"],
                                        hyper_params["char_map"])

    v_iterator = None
    if test_set is []:
        t_iterator = model.add_dataset_input(train_dataset)
        sess.run(t_iterator.initializer)
    else:
        test_dataset = model.build_dataset(
            test_set, hyper_params["batch_size"],
            hyper_params["max_input_seq_length"],
            hyper_params["max_target_seq_length"],
            hyper_params["signal_processing"], hyper_params["char_map"])

        # Build the input stream from the different datasets
        t_iterator, v_iterator = model.add_datasets_input(
            train_dataset, test_dataset)
        sess.run(t_iterator.initializer)
        sess.run(v_iterator.initializer)

    # Create the model
    model.create_training_rnn(hyper_params["dropout_input_keep_prob"],
                              hyper_params["dropout_output_keep_prob"],
                              hyper_params["grad_clip"],
                              hyper_params["learning_rate"],
                              hyper_params["lr_decay_factor"],
                              use_iterator=True)
    model.add_tensorboard(sess, hyper_params["tensorboard_dir"],
                          prog_params["tb_name"], prog_params["timeline"])
    model.initialize(sess)
    model.restore(sess, hyper_params["checkpoint_dir"] + "/acoustic/")

    # Override the learning rate if given on the command line
    if prog_params["learn_rate"] is not None:
        model.set_learning_rate(sess, prog_params["learn_rate"])

    return model, t_iterator, v_iterator
Пример #4
0
def build_acoustic_training_rnn(sess, hyper_params, prog_params, train_set, test_set):
    model = AcousticModel(hyper_params["num_layers"], hyper_params["hidden_size"], hyper_params["batch_size"],
                          hyper_params["max_input_seq_length"], hyper_params["max_target_seq_length"],
                          hyper_params["input_dim"], hyper_params["batch_normalization"],
                          hyper_params["char_map_length"])

    # Create a Dataset from the train_set and the test_set
    train_dataset = model.build_dataset(train_set, hyper_params["batch_size"], hyper_params["max_input_seq_length"],
                                        hyper_params["max_target_seq_length"], hyper_params["signal_processing"],
                                        hyper_params["char_map"])

    v_iterator = None
    if test_set is []:
        t_iterator = model.add_dataset_input(train_dataset)
        sess.run(t_iterator.initializer)
    else:
        test_dataset = model.build_dataset(test_set, hyper_params["batch_size"], hyper_params["max_input_seq_length"],
                                           hyper_params["max_target_seq_length"], hyper_params["signal_processing"],
                                           hyper_params["char_map"])

        # Build the input stream from the different datasets
        t_iterator, v_iterator = model.add_datasets_input(train_dataset, test_dataset)
        sess.run(t_iterator.initializer)
        sess.run(v_iterator.initializer)

    # Create the model
    model.create_training_rnn(hyper_params["dropout_input_keep_prob"], hyper_params["dropout_output_keep_prob"],
                              hyper_params["grad_clip"], hyper_params["learning_rate"],
                              hyper_params["lr_decay_factor"], use_iterator=True)
    model.add_tensorboard(sess, hyper_params["tensorboard_dir"], prog_params["tb_name"], prog_params["timeline"])
    model.initialize(sess)
    model.restore(sess, hyper_params["checkpoint_dir"] + "/acoustic/")

    # Override the learning rate if given on the command line
    if prog_params["learn_rate"] is not None:
        model.set_learning_rate(sess, prog_params["learn_rate"])

    return model, t_iterator, v_iterator
Пример #5
0
    def test_create_training_rnn_with_iterators(self):
        tf.reset_default_graph()

        with tf.Session():
            model = AcousticModel(self.num_layers, self.hidden_size, self.batch_size, self.max_input_seq_length,
                                  self.max_target_seq_length, self.input_dim, self.normalization, self.num_labels)

            # Create a Dataset from the train_set and the test_set
            train_dataset = model.build_dataset([["/file/path", "Test", 10]], self.batch_size,
                                                self.max_input_seq_length, self.max_target_seq_length,
                                                self.signal_processing, ENGLISH_CHAR_MAP)
            model.add_dataset_input(train_dataset)
            model.create_training_rnn(self.input_keep_prob, self.output_keep_prob, self.grad_clip,
                                      self.learning_rate, self.lr_decay_factor, use_iterator=True)
Пример #6
0
    def test_create_training_rnn_with_iterators(self):
        tf.reset_default_graph()

        with tf.Session():
            model = AcousticModel(self.num_layers, self.hidden_size,
                                  self.batch_size, self.max_input_seq_length,
                                  self.max_target_seq_length, self.input_dim,
                                  self.normalization, self.num_labels)

            # Create a Dataset from the train_set and the test_set
            train_dataset = model.build_dataset([["/file/path", "Test", 10]],
                                                self.batch_size,
                                                self.max_input_seq_length,
                                                self.max_target_seq_length,
                                                self.signal_processing,
                                                ENGLISH_CHAR_MAP)
            model.add_dataset_input(train_dataset)
            model.create_training_rnn(self.input_keep_prob,
                                      self.output_keep_prob,
                                      self.grad_clip,
                                      self.learning_rate,
                                      self.lr_decay_factor,
                                      use_iterator=True)