Beispiel #1
0
/* Initialise: */
static void Initialise()
{
   char macroname[MAXSTRLEN];
   AdaptXForm *xform;

   /* load HMMs and init HMMSet related global variables */
   if (trace & T_TOP)
      printf("Loading HMM for updating ... ... \n");
   if (MakeHMMSet(&hset, hmmListFn) < SUCCESS)
      HError(2321, "Initialise: MakeHMMSet failed");
   if (LoadHMMSet(&hset, hmmDir, hmmExt) < SUCCESS)
      HError(2321, "Initialise: LoadHMMSet failed");
   SetParmHMMSet(&hset);
   /* variance inversion, MGE training only support INVDIAGC case */
   if (hset.ckind == DIAGC)
      ConvDiagC(&hset, TRUE);
   /* load transform */
   if (xformfn != NULL) {
      xform = LoadOneXForm(&hset, NameOf(xformfn, macroname), xformfn);
      SetXForm(&hset, &xfInfo, xform);
   }

   if (funcType == MGE_TRAIN)
      AttachAccToModel();

   /* reload the HMM for reference in training */
   if (mtInfo->bOrigHmmRef) {
      if (trace & T_TOP)
         printf("Loading HMM for reference ... ... \n");
      if (MakeHMMSet(&orighset, hmmListFn) < SUCCESS)
         HError(2321, "Initialise: MakeHMMSet failed");
      if (LoadHMMSet(&orighset, hmmDir, hmmExt) < SUCCESS)
         HError(2321, "Initialise: LoadHMMSet failed");
      SetParmHMMSet(&orighset);
      /* variance inversion, MGE training only support INVDIAGC case */
      if (hset.ckind == DIAGC)
         ConvDiagC(&orighset, TRUE);
      /* load transform */
      if (xformfn != NULL) {
         xform = LoadOneXForm(&orighset, NameOf(xformfn, macroname), xformfn);
         SetXForm(&orighset, &xfInfo, xform);
      }
   }

   if (trace & T_TOP) {
      printf("System is ");
      switch (hset.hsKind) {
      case PLAINHS:
         printf("PLAIN\n");
         break;
      case SHAREDHS:
         printf("SHARED\n");
         break;
      case TIEDHS:
         printf("TIED\n");
         break;
      case DISCRETEHS:
         printf("DISCRETE\n");
         break;
      }

      printf("%d Logical/%d Physical Models Loaded, VecSize=%d\n", hset.numLogHMM, hset.numPhyHMM, hset.vecSize);
      if (hset.numFiles > 0)
         printf("%d MMF input files\n", hset.numFiles);
      if (mmfFn != NULL)
         printf("Output to MMF file:  %s\n", mmfFn);
      fflush(stdout);
   }

   /* initialize a MgeTrnInfo for MGE training of HMM */
   InitMgeTrnInfo();
}
Beispiel #2
0
void Initialise(void)
{
   /* load HMM mmf */
   if (MakeHMMSet(&hmset, GetStrArg()) < SUCCESS)
      HError(9928, "Initialise: MakeHMMSet failed");
   if (LoadHMMSet(&hmset, hmmDir, hmmExt) < SUCCESS)
      HError(9928, "Initialise: LoadHMMSet failed");
   if (hmset.hsKind == DISCRETEHS)
      HError(9999, "Initialise: Only continuous model is surpported");
   ConvDiagC(&hmset, TRUE);

   if (trace & T_TOP) {
      PrintrFlags();
      printf("HMMSet is ");
      switch (hmset.hsKind) {
      case PLAINHS:
         printf("PLAIN\n");
         break;
      case SHAREDHS:
         printf("SHARED\n");
         break;
      case TIEDHS:
         printf("TIED\n");
         break;
      default:
         HError(9999, "Initialise: Only continuous model is supported");
      }

      printf("%d Logical/%d Physical Models Loaded, VecSize=%d\n", hmset.numLogHMM, hmset.numPhyHMM, hmset.vecSize);
      if (hmset.numFiles > 0)
         printf("%d MMF input files\n", hmset.numFiles);
      fflush(stdout);
   }

   /* load duration mmf */
   if (!stateAlign) {
      if (MakeHMMSet(&dmset, GetStrArg()) < SUCCESS)
         HError(9928, "Initialise: MakeHMMSet failed");
      if (LoadHMMSet(&dmset, dmDir, dmExt) < SUCCESS)
         HError(9928, "Initialise: LoadHMMSet failed");
      if (hmset.hsKind == DISCRETEHS)
         HError(9999, "Initialise: Only continuous duration model mmf is surpported");
      ConvDiagC(&dmset, TRUE);

      if (trace & T_TOP) {
         printf("DurationModelSet is ");
         switch (dmset.hsKind) {
         case PLAINHS:
            printf("PLAIN\n");
            break;
         case SHAREDHS:
            printf("SHARED\n");
            break;
         case TIEDHS:
            printf("TIED\n");
            break;
         default:
            HError(9999, "Initialise: Only continuous model is supported");
         }

         printf("%d Logical/%d Physical Models Loaded, VecSize=%d\n", dmset.numLogHMM, dmset.numPhyHMM, dmset.vecSize);
         if (dmset.numFiles > 0)
            printf("%d MMF input files\n", dmset.numFiles);
         fflush(stdout);
      }
   }

   /* setup GenInfo */
   genInfo->genMem = &genStack;
   genInfo->hset = &hmset;
   genInfo->dset = &dmset;
   genInfo->maxStates = MaxStatesInSet(&hmset);
   genInfo->maxMixes = MaxMixInSet(&hmset);
   genInfo->speakRate = speakRate;
   genInfo->MSDthresh = MSDthresh;
   genInfo->modelAlign = modelAlign;
   genInfo->stateAlign = stateAlign;
   genInfo->frameRate = frameRate;

   CheckGenSetUp();

   /* setup EM-based parameter generation */
   AttachAccs(&hmset, &gstack, (UPDSet) 0);
   ZeroAccs(&hmset, (UPDSet) 0);

   if (!stateAlign) {
      AttachAccs(&dmset, &gstack, (UPDSet) 0);
      ZeroAccs(&dmset, (UPDSet) 0);
   }

   if (type != CHOLESKY)
      InitialiseForBack(fbInfo, &fbInfoStack, &hmset, (UPDSet) 0, ((useHMMFB || stateAlign) ? NULL : &dmset), (UPDSet) 0, pruneInit, pruneInc, pruneLim, minFrwdP, useAlign, FALSE);

   /* handle input xform */
   xfInfo_hmm.inFullC = xfInfo_dur.inFullC = TRUE;

   /* semi-tied case */
   if (hmset.semiTied != NULL) {
      SetXForm(&hmset, NULL, hmset.semiTied);
      ApplyHMMSetXForm(&hmset, hmset.semiTied, TRUE);
   }

   /* linear weight -> log weight */
   ConvLogWt(&hmset);
}
Beispiel #3
0
/* DoRecognition:  use single network to recognise each input utterance */
void DoRecognition(void)
{
   FILE *nf;
   Network *net;
   Boolean isPipe;
   int n=0;
   AdaptXForm *incXForm;

   if ( (nf = FOpen(wdNetFn,NetFilter,&isPipe)) == NULL)
      HError(3210,"DoRecognition: Cannot open Word Net file %s",wdNetFn);
   if((wdNet = ReadLattice(nf,&ansHeap,&vocab,TRUE,FALSE))==NULL)
      HError(3210,"DoAlignment: ReadLattice failed");
   FClose(nf,isPipe);

   if (trace&T_TOP) {
      printf("Read lattice with %d nodes / %d arcs\n",wdNet->nn,wdNet->na);
      fflush(stdout);
   }
   CreateHeap(&netHeap,"Net heap",MSTAK,1,0,
              wdNet->na*sizeof(NetLink),wdNet->na*sizeof(NetLink));

   net = ExpandWordNet(&netHeap,wdNet,&vocab,&hset);
   ResetHeap(&ansHeap);
   if (trace&T_TOP) {
      printf("Created network with %d nodes / %d links\n",
             net->numNode,net->numLink);  fflush(stdout);
   }
   if (trace & T_MEM){
      printf("Memory State Before Recognition\n");
      PrintAllHeapStats();
   }

   if (NumArgs()==0) {      /* Process audio */
      while(TRUE){
         printf("\nREADY[%d]>\n",++n); fflush(stdout);
	 /* no input transform possible for audio input .... */
         ProcessFile(NULL,net,n,genBeam, FALSE);
         if (update > 0 && n%update == 0) {
            if (trace&T_TOP) {
               printf("Transforming model set\n");
               fflush(stdout);
            }
	    /* 
	       at every stage a new transform is created - fix?? 
	       Estimate transform and then set it up as the 
	       input XForm
	    */
	    incXForm = CreateAdaptXForm(&hset,"inc");
            TidyBaseAccs();
	    GenAdaptXForm(&hset,incXForm);
            xfInfo.inXForm = GetMLLRDiagCov(incXForm);;
            SetXForm(&hset,xfInfo.inXForm);
	    ApplyHMMSetXForm(&hset,xfInfo.inXForm);
         }
      }
   }
   else {                   /* Process files */
      while (NumArgs()>0) {
         if (NextArg()!=STRINGARG)
            HError(3219,"DoRecognition: Data file name expected");
         datFN = GetStrArg();
         if (trace&T_TOP) {
            printf("File: %s\n",datFN); fflush(stdout);
         }
	 /* This handles the initial input transform, parent transform setting
	    and output transform creation */
         if (UpdateSpkrStats(&hset, &xfInfo, datFN) && (!(xfInfo.useInXForm)) && (hset.semiTied == NULL)) {
            xfInfo.inXForm = NULL;
         }
         ProcessFile(datFN,net,n++,genBeam,FALSE);
         if (update > 0 && n%update == 0) {
            if (trace&T_TOP) {
               printf("Transforming model set\n");
               fflush(stdout);
            }
	    /* 
	       at every stage a new transform is created - fix?? 
	       Estimate transform and then set it up as the 
	       input XForm
	    */
	    incXForm = CreateAdaptXForm(&hset,"inc");
            TidyBaseAccs();
	    GenAdaptXForm(&hset,incXForm);
            xfInfo.inXForm = GetMLLRDiagCov(incXForm);;
            SetXForm(&hset,xfInfo.inXForm);
	    ApplyHMMSetXForm(&hset,xfInfo.inXForm);
         }
      }
   }
}
/**
 * @fn SetFullQuadXFrom()
 *
 * @brief Sets the transformation vector to be a full quad
 *
 * @note The transformation vector has two internal vectors. In this
 *       case, the first is (2.0,-2.0,-1.9, 1.0) and the second is
 *       (1.0, 1.0, 0.0, 0.0)
 */
void CDXQuad::XFormMaterial::SetFullQuadXFrom()
{
    static D3DXVECTOR4 xformFullQuad[2] = { D3DXVECTOR4(2.0f, -2.0f, -1.0f, 1.0f), D3DXVECTOR4(1.0f, 1.0f, 0.0f, 0.0f) };
    SetXForm(xformFullQuad);
}
Beispiel #5
0
/* DoAlignment: by creating network from transcriptions or lattices */
void DoAlignment(void)
{
   FILE *nf;
   char lfn[MAXSTRLEN], buf[MAXSTRLEN];
   Transcription *trans;
   Network *net;
   Boolean isPipe;
   int n=0;
   LogDouble currGenBeam;
   AdaptXForm *incXForm;

   if (trace&T_TOP) {
      if (loadNetworks) 
         printf("New network will be used for each file\n");
      else
         printf("Label file will be used to align each file\n");
      fflush(stdout);
   }
   CreateHeap(&netHeap,"Net heap",MSTAK,1,0,8000,80000);
   while (NumArgs()>0) {
      if (NextArg() != STRINGARG)
         HError(3219,"DoAlignment: Data file name expected");
      datFN = GetStrArg();
      if (trace&T_TOP) {
         printf("Aligning File: %s\n",datFN);  fflush(stdout);
      }
      if (labFileMask != NULL ) { /* support for rescoring lattice masks */
         if (!MaskMatch(labFileMask,buf,datFN))
            HError(2319,"DoAlignment: mask %s has no match with segemnt %s",labFileMask,datFN);
         MakeFN(buf,labInDir,labInExt,lfn);
      } else {
         MakeFN(datFN,labInDir,labInExt,lfn);
      }
      if (loadNetworks) {
         if ( (nf = FOpen(lfn,NetFilter,&isPipe)) == NULL)
            HError(3210,"DoAlignment: Cannot open Word Net file %s",lfn);
         if((wdNet = ReadLattice(nf,&netHeap,&vocab,TRUE,FALSE))==NULL)
            HError(3210,"DoAlignment: ReadLattice failed");
         FClose(nf,isPipe);
         if (trace&T_TOP) {
            printf("Read lattice with %d nodes / %d arcs\n",
                   wdNet->nn,wdNet->na);
            fflush(stdout);
         }
      }
      else {
         LabList *ll = NULL;

         trans=LOpen(&netHeap,lfn,ifmt);
         if (trans->numLists >= 1)
            ll = GetLabelList(trans,1);
         if (!ll && !bndId)
            HError(3233, "DoAlignment: cannot align empty transcription");

         wdNet=LatticeFromLabels(ll, bndId, &vocab,&netHeap);
         if (trace&T_TOP) {
            printf("Created lattice with %d nodes / %d arcs from label file\n",
                   wdNet->nn,wdNet->na);
            fflush(stdout);
         }
      }
      net=ExpandWordNet(&netHeap,wdNet,&vocab,&hset);

      ++n;
      currGenBeam = genBeam;
      /* This handles the initial input transform, parent transform setting
	 and output transform creation */
      if (UpdateSpkrStats(&hset, &xfInfo, datFN) && (!(xfInfo.useInXForm)) && (hset.semiTied == NULL)) {
         xfInfo.inXForm = NULL;
      }
      if (genBeamInc == 0.0)
         ProcessFile (datFN, net, n, currGenBeam, FALSE);
      else {
         Boolean completed;

         completed = ProcessFile (datFN, net, n, currGenBeam, TRUE);
         currGenBeam += genBeamInc;
         while (!completed && (currGenBeam <= genBeamLim - genBeamInc)) {
            completed = ProcessFile (datFN, net, n, currGenBeam, TRUE);
            currGenBeam += genBeamInc;
         }
         if (!completed)
            ProcessFile (datFN, net, n, currGenBeam, FALSE);
      }

      if (update > 0 && n%update == 0) {
         if (trace&T_TOP) {
            printf("Transforming model set\n");
            fflush(stdout);
         }
	 /* 
	    at every stage a new transform is created - fix?? 
	    Estimate transform and then set it up as the 
	    input XForm
	 */
	 incXForm = CreateAdaptXForm(&hset,"inc");
         TidyBaseAccs();
	 GenAdaptXForm(&hset,incXForm);
         xfInfo.inXForm = GetMLLRDiagCov(incXForm);;
	 SetXForm(&hset,xfInfo.inXForm);
	 ApplyHMMSetXForm(&hset,xfInfo.inXForm);
      }
      ResetHeap(&netHeap);
   }
}