Example #1
0
 def test_save_hmm(self):
     hmm = HMM()
     hmm.load( os.path.join(HERE,"N-hmm") )
     hmm.save(os.path.join(HERE,"N-hmm-copy"))
     newhmm = HMM()
     newhmm.load(os.path.join(HERE,"N-hmm-copy"))
     os.remove(os.path.join(HERE,'N-hmm-copy'))
     self.assertEqual(hmm.name,newhmm.name)
     self.assertTrue(compare(hmm.definition,newhmm.definition))
Example #2
0
    def test_initializer_without_corpus(self):
        corpus  = TrainingCorpus()
        workdir = os.path.join(HERE,"working")

        os.mkdir( workdir )
        shutil.copy( os.path.join(HERE, "protos","vFloors"), workdir )

        initial = HTKModelInitializer( corpus, workdir )

        corpus.datatrainer.protodir = os.path.join(HERE, "protos")
        initial.create_model()

        hmm1 = HMM()
        hmm2 = HMM()

        hmm1.load( os.path.join( workdir, "@@.hmm") )
        hmm2.load( os.path.join(HERE, "protos", "@@.hmm") )
        self.assertTrue(compare(hmm1.definition,hmm2.definition))

        hmm1.load( os.path.join( workdir, "sil.hmm") )
        hmm2.load( os.path.join(HERE, "protos", "sil.hmm") )

        corpus.datatrainer.fix_proto(protofilename=os.path.join(HERE, "protos", "proto.hmm"))
        hmm2.load( os.path.join(HERE, "protos", "proto.hmm") )

        hmm1.load( os.path.join(workdir, "gb.hmm") )
        self.assertTrue(compare(hmm1.definition,hmm2.definition))

        hmm1.load( os.path.join(workdir, "dummy.hmm") )
        self.assertTrue(compare(hmm1.definition,hmm2.definition))

        acmodel = AcModel()
        acmodel.load_htk( os.path.join( workdir,"hmmdefs") )

        shutil.rmtree( workdir )
        os.remove( os.path.join(HERE, "protos", "proto.hmm") )
Example #3
0
    def test_proto(self):
        h1 = HtkIO()
        h1.write_hmm_proto( 25, os.path.join(HERE,"proto_from_htkio") )

        h2 = HMM()
        h2.create_proto( 25 )
        h2.save( os.path.join(HERE,"proto_from_hmm") )

        m1 = HMM()
        m1.load( os.path.join(HERE,"proto_from_htkio") )

        m2 = HMM()
        m2.load( os.path.join(HERE,"proto_from_hmm") )

        self.assertTrue(compare(m1.definition['transition'],m2.definition['transition']))
        self.assertTrue(compare(m1.definition['states'],m2.definition['states']))

        os.remove( os.path.join(HERE,"proto_from_hmm") )
        os.remove( os.path.join(HERE,"proto_from_htkio") )
Example #4
0
 def test_load_hmm(self):
     hmm = HMM()
     hmm.load( os.path.join(HERE,"N-hmm") )
     self.__test_states( hmm.definition['states'] )
     self.__test_transition( hmm.definition['transition'] )
Example #5
0
    def testMix(self):
        acmodel1 = AcModel()
        hmm1 = HMM()
        hmm1.create_proto( 25 )
        hmm1.name = "y"
        acmodel1.append_hmm( hmm1 )
        acmodel1.repllist.add("y","j")

        acmodel2 = AcModel()
        hmm2 = HMM()
        hmm2.create_proto( 25 )
        hmm2.name = "j"
        hmm3 = HMM()
        hmm3.create_proto( 25 )
        hmm3.name = "y"
        acmodel2.hmms.append( hmm2 )
        acmodel2.hmms.append( hmm3 )
        acmodel2.repllist.add("y","y")
        acmodel2.repllist.add("j","j")

        modelmixer = ModelMixer()
        modelmixer.set_models( acmodel1,acmodel2 )

        outputdir = os.path.join(MODELDIR, "models-test")
        modelmixer.mix( outputdir, gamma=1. )
        mixedh1 = AcModel()
        mixedh1.load( outputdir )
        shutil.rmtree( outputdir )