void cTumkwsjSink::fillKresult(Kresult *k, WORD_ID *seq, int n, WORD_INFO *winfo, LOGPROB *cmscore, int numOfFrames, SentenceAlign *alignment) { int i; int kwcount = 0; if (seq != NULL) { for (i=0;i<n;i++) { if (strcmp("garbage",winfo->woutput[seq[i]])!=0 && strcmp("<s>",winfo->woutput[seq[i]])!=0 && strcmp("</s>",winfo->woutput[seq[i]])!=0) { //keywords: k->keyword[kwcount]=winfo->woutput[seq[i]]; if (alignment == NULL) { k->kwStartTime[kwcount]= 0.0; } else { k->kwStartTime[kwcount]= (period * (double)(alignment->begin_frame[i])); // ?? n != ?? } k->kwConf[kwcount]=cmscore[i]; kwcount++; if (kwcount >= MAXNUMKW) { SMILE_IWRN(2,"keywords were discarded, more than MAXNUMKW=%i (tumkwsjSink.hpp!) keywords detected!",MAXNUMKW); i=n; break; } } } } k->numOfKw=kwcount; k->turnDuration=numOfFrames; }
int cLibsvmLiveSink::myFinaliseInstance() { int ap=0; int ret = cDataSink::myFinaliseInstance(); if (ret==0) return 0; // TODO: binary model files... // load model SMILE_MSG(2,"loading LibSVM model for instance '%s' ...",getInstName()); if((model=svm_load_model(modelfile))==0) { COMP_ERR("can't open libSVM model file '%s'",modelfile); } nClasses = svm_get_nr_class(model); svmType = svm_get_svm_type(model); if(predictProbability) { if ((svmType==NU_SVR) || (svmType==EPSILON_SVR)) { nClasses = 0; SMILE_MSG(2,"LibSVM prob. model (regression) for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma=%g",svm_get_svr_probability(model)); } else { labels=(int *) malloc(nClasses*sizeof(int)); svm_get_labels(model,labels); SMILE_MSG(3,"LibSVM %i labels in model '%s':",nClasses,modelfile); int j; for(j=0;j<nClasses;j++) SMILE_MSG(3," Label[%i] : '%d'",j,labels[j]); } } //?? move this in front of above if() block ? if ((predictProbability)&&(nClasses>0)) probEstimates = (double *) malloc(nClasses*sizeof(double)); // load scale if((scale=svm_load_scale(scalefile))==0) { COMP_ERR("can't open libSVM scale file '%s'",scalefile); } // load selection loadSelection(fselection); //TODO: check compatibility of getLevelN() (possibly after selection), number of features in model, and scale if (nClasses>0) { // load class mapping loadClasses(classes); } else { if (classes != NULL) SMILE_IWRN(2,"not loading given class mapping file for regression SVR model (there are no classes...)!"); } return ret; }
// get smileTime from _msg, convert to semaine time by getting current time from smile and semaine and observing the difference long long cSemaineEmmaSender::smileTimeToSemaineTime( double smileTime ) { smileTime *= 1000.0; if (meta != NULL) { long long smit = (long long)round(getSmileTime()*1000.0); return (long long)round(smileTime) + (meta->getTime() - smit); } else { SMILE_IWRN(3,"warning, no meta component found, times sent are SMILE times and NOT semaine times!"); return (long long)round(smileTime); } return 0; }
int cFullinputMean::myTick(long long t) { long i; if (isEOI()) { if (means == NULL) { SMILE_IWRN(1,"sequence too short, cannot compute mean value!"); long N = reader->getLevelN(); means = new cVector( N, DMEM_FLOAT ); for (i=0; i<N; i++) { means->dataF[i] = 0; } nMeans = 1; } if (flag==0) { reader->setCurR(0); flag = 1; FLOAT_DMEM nM = (FLOAT_DMEM)nMeans; if (nM <= 0.0) nM = 1.0; for (i=0; i<means->N; i++) { means->dataF[i] /= nM; } } cVector *vec = reader->getNextFrame(); if (vec!= NULL) { /*if ((htkcompatible)&&(idx0>0)) { for (i=0; i<means->N; i++) { if ((i==0)||(i%idx0!=0)) { vec->dataF[i] -= means->dataF[i]; } } } else {*/ for (i=0; i<means->N; i++) { vec->dataF[i] -= means->dataF[i]; //printf("means[%i] = %f\n",i,means->dataF[i]); } //} writer->setNextFrame(vec); return 1; } } else { // compute means, do not write data cVector *vec = reader->getNextFrame(); if (vec != NULL) { if (vec->type != DMEM_FLOAT) { COMP_ERR("only float data-type is supported by cFullinputMean!"); } if (means == NULL) { means = new cVector( vec->N, vec->type ); for (i=0; i<vec->N; i++) { means->dataF[i] = vec->dataF[i]; } nMeans = 1; } else { for (i=0; i<vec->N; i++) { means->dataF[i] += vec->dataF[i]; } nMeans++; } return 1; } } return 0; }
// this is called from julius decoder thread... int cTumkwsjSink::getFv(float *vec, int n) { int ret=0; smileMutexLock(dataFlgMtx); if (terminated) { smileMutexUnlock(dataFlgMtx); recog->process_want_terminate = TRUE; return -1; } // we should wait for main thread to provide data, then set a flag that data was read.. SMILE_IDBG(4,"yes... julius requests features from us (n=%i)!",n); int end=0; do { lockMessageMemory(); turnStartSmileTimeCur = turnStartSmileTime; // handle pre/post silence and turn detector interface if (turnStart) { // process old turnEnd message first... if ((turnEnd)&&(vIdxEnd < vIdxStart)) { turnEnd = 0; isTurn = 0; ret=-3; end=1; turnStartSmileTimeCur = turnStartSmileTimeLast; SMILE_IDBG(2,"processed turn end message!"); } turnStart = 0; curVidx = vIdxStart-preSil; isTurn = 1; SMILE_IDBG(2,"received turn start message!"); } if (turnEnd) { SMILE_IDBG(4,"received turn end message!"); if (curVidx >= vIdxEnd+postSil) { turnEnd = 0; isTurn = 0; ret=-3; end=1; SMILE_IDBG(2,"processed turn end message!"); turnStartSmileTimeCur = turnStartSmileTimeLast; } // if no frames have been written... if (curVidx == vIdxStart) { SMILE_IWRN(2,"turn (vIdx %i - vIdx %i) has 0 frames (curVidx = %i)!",vIdxStart,vIdxEnd,curVidx); turnEnd=0; isTurn=0; } } unlockMessageMemory(); if (!isTurn) { smileCondWaitWMtx( tickCond, dataFlgMtx ); // wait one smile tick for things to change } if (terminated) { smileMutexUnlock(dataFlgMtx); recog->process_want_terminate = TRUE; return -1; } } while ((!isTurn)&&(!end)); //printf("turn getFv\n"); if (isTurn) { int result=0; curVec = NULL; while (curVec == NULL) { curVec = reader->getFrame(curVidx, -1, 0, &result); // TODO: check if curVidx is behind ringbuffer storage space!! if (result & DMRES_OORleft) { long tmp = reader->getMinR()+10; if (tmp > curVidx) { SMILE_IWRN(2,"ASR processing tried to get feature data behind beginning of ringbuffer, which is no more available! Skipping a few frames to catch up... (%i) : %i -> %i",tmp-curVidx, curVidx, tmp); curVidx = tmp; } } if (curVec == NULL) { smileCondWaitWMtx( tickCond, dataFlgMtx ); if (terminated) { smileMutexUnlock(dataFlgMtx); recog->process_want_terminate = TRUE; return -1; } } } curVidx++; } //printf("turn: %f n=%i\n",curVec->dataF[curVec->N-1],curVec->N); smileMutexUnlock(dataFlgMtx); int i; if (curVec != NULL) { for (i=0; i<MIN( curVec->N, n ); i++) { vec[i] = (float)(curVec->dataF[i]); } } else { for (i=0; i<n; i++) { vec[i] = 0.0; } } // TODO: input segmentation (via smile ComponentMessages...??) return ret; }