def test_save_load(self):
        dir_out = self._get_test_dir()

        theta_start = 0.01
        theta_stop = 0.055
        theta_step = 0.005
        thetas = np.arange(theta_start, theta_stop, theta_step)
        k = 6
        frame_size_ms = 5

        atom_gen = AtomVUVDistPosLabelGen(self.dir_wcad_root, dir_out,
            dir_out, thetas, frame_size_ms)

        label_dict = atom_gen.gen_data(self.dir_wav, None,
                                       id_list=self.id_list, return_dict=True)

        # Call this once before starting the pre-processing.
        atom_gen.get_normalisation_params(dir_out)

        test_label = label_dict[self.id_list[1]]
        test_label_pre = atom_gen.preprocess_sample(test_label)

        # TODO: Figure out what to test here.

        # self.assertTrue(np.isclose(test_label_pre,
        #                            atom_gen[self.id_list[1]]).all())

        test_label_post = atom_gen.postprocess_sample(test_label_pre)
        # self.assertTrue(np.isclose(test_label, test_label_post).all())

        self.assertTrue(np.isclose(-3.4898, test_label_post.sum(),
                                   atol=0.0001))

        os.remove(os.path.join(self.dir_database, "wcad_.txt"))
        shutil.rmtree(dir_out)
Beispiel #2
0
                                        sp_type="mcep")
    world_generator.gen_data(dir_wav, dir_world, id_list=id_list)
    world_generator = WorldFeatLabelGen(dir_world,
                                        add_deltas=True,
                                        num_coded_sps=20,
                                        sp_type="mcep")
    world_generator.gen_data(dir_wav, dir_world, id_list=id_list)

    # Generate atoms.
    logging.info("Create atom files.")
    shutil.rmtree(dir_atoms)
    makedirs_safe(dir_atoms)
    atom_generator = AtomVUVDistPosLabelGen(
        os.path.join(os.path.dirname(os.environ["IDIAPTTS_ROOT"]), "tools",
                     "wcad"), dir_atoms, dir_world, thetas)
    atom_generator.gen_data(dir_wav, dir_atoms, id_list=id_list)

if retrain_models:
    raise NotImplementedError("Did not yet implemented retraining of models.")
elif save_models:
    from idiaptts.src.neural_networks.pytorch.ModelHandlerPyTorch import ModelHandlerPyTorch

    from idiaptts.src.model_trainers.wcad.AtomVUVDistPosModelTrainer import AtomVUVDistPosModelTrainer
    hparams = AtomVUVDistPosModelTrainer.create_hparams()
    hparams.model_name = "test_model_in409_out7.nn"
    model_handler = ModelHandlerPyTorch()
    # The following code uses the load_model method and saves it back as a checkpoint.
    # model, model_type, dim_in, dim_out = model_handler.load_model(hparams.model_name, hparams)
    # model_handler.model_type = "RNNDYN-1_RELU_32-1_FC_7"
    # model_handler.dim_in = model.dim_in
    # model_handler.dim_out = model.dim_out