comparison transform/FeatureExtractionModelTransformer.cpp @ 890:4cbf8c6a462d tony_integration

Merge from branch tonioni
author Chris Cannam
date Tue, 11 Mar 2014 17:30:35 +0000
parents 862fe7b20df7 b109b88bfa85
children 8962f80f5d8e
comparison
equal deleted inserted replaced
874:862fe7b20df7 890:4cbf8c6a462d
211 return false; 211 return false;
212 } 212 }
213 } 213 }
214 214
215 for (int j = 0; j < (int)m_transforms.size(); ++j) { 215 for (int j = 0; j < (int)m_transforms.size(); ++j) {
216 createOutputModel(j); 216 createOutputModels(j);
217 } 217 }
218 218
219 return true; 219 return true;
220 } 220 }
221 221
222 void 222 void
223 FeatureExtractionModelTransformer::createOutputModel(int n) 223 FeatureExtractionModelTransformer::createOutputModels(int n)
224 { 224 {
225 DenseTimeValueModel *input = getConformingInput(); 225 DenseTimeValueModel *input = getConformingInput();
226 226
227 // cerr << "FeatureExtractionModelTransformer::createOutputModel: sample type " << m_descriptor->sampleType << ", rate " << m_descriptor->sampleRate << endl; 227 // cerr << "FeatureExtractionModelTransformer::createOutputModel: sample type " << m_descriptor->sampleType << ", rate " << m_descriptor->sampleRate << endl;
228 228
230 QString outputId = m_transforms[n].getOutput(); 230 QString outputId = m_transforms[n].getOutput();
231 231
232 int binCount = 1; 232 int binCount = 1;
233 float minValue = 0.0, maxValue = 0.0; 233 float minValue = 0.0, maxValue = 0.0;
234 bool haveExtents = false; 234 bool haveExtents = false;
235 235 bool haveBinCount = m_descriptors[n]->hasFixedBinCount;
236 if (m_descriptors[n]->hasFixedBinCount) { 236
237 if (haveBinCount) {
237 binCount = m_descriptors[n]->binCount; 238 binCount = m_descriptors[n]->binCount;
238 } 239 }
240
241 m_needAdditionalModels[n] = false;
239 242
240 // cerr << "FeatureExtractionModelTransformer: output bin count " 243 // cerr << "FeatureExtractionModelTransformer: output bin count "
241 // << binCount << endl; 244 // << binCount << endl;
242 245
243 if (binCount > 0 && m_descriptors[n]->hasKnownExtents) { 246 if (binCount > 0 && m_descriptors[n]->hasKnownExtents) {
399 // Anything that is not a 1D, note, or interval model and that 402 // Anything that is not a 1D, note, or interval model and that
400 // has only one value per result must be a sparse time value 403 // has only one value per result must be a sparse time value
401 // model. 404 // model.
402 405
403 // Anything that is not a 1D, note, or interval model and that 406 // Anything that is not a 1D, note, or interval model and that
404 // has a variable sample rate is also treated as a sparse time 407 // has a variable sample rate is treated as a set of sparse
405 // value model regardless of its bin count, because we lack a 408 // time value models, one per output bin, because we lack a
406 // sparse 3D model. 409 // sparse 3D model.
410
411 // Anything that is not a 1D, note, or interval model and that
412 // has a fixed sample rate but an unknown number of values per
413 // result is also treated as a set of sparse time value models.
414
415 // For sets of sparse time value models, we create a single
416 // model first as the "standard" output and then create models
417 // for bins 1+ in the additional model map (mapping the output
418 // descriptor to a list of models indexed by bin-1). But we
419 // don't create the additional models yet, as this case has to
420 // work even if the number of bins is unknown at this point --
421 // we create an additional model (copying its parameters from
422 // the default one) each time a new bin is encountered.
423
424 if (!haveBinCount || binCount > 1) {
425 m_needAdditionalModels[n] = true;
426 }
407 427
408 SparseTimeValueModel *model; 428 SparseTimeValueModel *model;
409 if (haveExtents) { 429 if (haveExtents) {
410 model = new SparseTimeValueModel 430 model = new SparseTimeValueModel
411 (modelRate, modelResolution, minValue, maxValue, false); 431 (modelRate, modelResolution, minValue, maxValue, false);
461 for (int j = 0; j < m_descriptors.size(); ++j) { 481 for (int j = 0; j < m_descriptors.size(); ++j) {
462 delete m_descriptors[j]; 482 delete m_descriptors[j];
463 } 483 }
464 } 484 }
465 485
486 FeatureExtractionModelTransformer::Models
487 FeatureExtractionModelTransformer::getAdditionalOutputModels()
488 {
489 Models mm;
490 for (AdditionalModelMap::iterator i = m_additionalModels.begin();
491 i != m_additionalModels.end(); ++i) {
492 for (std::map<int, SparseTimeValueModel *>::iterator j =
493 i->second.begin();
494 j != i->second.end(); ++j) {
495 SparseTimeValueModel *m = j->second;
496 if (m) mm.push_back(m);
497 }
498 }
499 return mm;
500 }
501
502 bool
503 FeatureExtractionModelTransformer::willHaveAdditionalOutputModels()
504 {
505 for (std::map<int, bool>::const_iterator i =
506 m_needAdditionalModels.begin();
507 i != m_needAdditionalModels.end(); ++i) {
508 if (i->second) return true;
509 }
510 return false;
511 }
512
513 SparseTimeValueModel *
514 FeatureExtractionModelTransformer::getAdditionalModel(int n, int binNo)
515 {
516 std::cerr << "getAdditionalModel(" << n << ", " << binNo << ")" << std::endl;
517
518 if (binNo == 0) {
519 std::cerr << "Internal error: binNo == 0 in getAdditionalModel (should be using primary model)" << std::endl;
520 return 0;
521 }
522
523 if (!m_needAdditionalModels[n]) return 0;
524 if (!isOutput<SparseTimeValueModel>(n)) return 0;
525 if (m_additionalModels[n][binNo]) return m_additionalModels[n][binNo];
526
527 std::cerr << "getAdditionalModel(" << n << ", " << binNo << "): creating" << std::endl;
528
529 SparseTimeValueModel *baseModel = getConformingOutput<SparseTimeValueModel>(n);
530 if (!baseModel) return 0;
531
532 std::cerr << "getAdditionalModel(" << n << ", " << binNo << "): (from " << baseModel << ")" << std::endl;
533
534 SparseTimeValueModel *additional =
535 new SparseTimeValueModel(baseModel->getSampleRate(),
536 baseModel->getResolution(),
537 baseModel->getValueMinimum(),
538 baseModel->getValueMaximum(),
539 false);
540
541 additional->setScaleUnits(baseModel->getScaleUnits());
542 additional->setRDFTypeURI(baseModel->getRDFTypeURI());
543
544 m_additionalModels[n][binNo] = additional;
545 return additional;
546 }
547
466 DenseTimeValueModel * 548 DenseTimeValueModel *
467 FeatureExtractionModelTransformer::getConformingInput() 549 FeatureExtractionModelTransformer::getConformingInput()
468 { 550 {
469 // SVDEBUG << "FeatureExtractionModelTransformer::getConformingInput: input model is " << getInputModel() << endl; 551 // SVDEBUG << "FeatureExtractionModelTransformer::getConformingInput: input model is " << getInputModel() << endl;
470 552
485 if (m_outputs.empty()) return; 567 if (m_outputs.empty()) return;
486 568
487 Transform primaryTransform = m_transforms[0]; 569 Transform primaryTransform = m_transforms[0];
488 570
489 while (!input->isReady() && !m_abandoned) { 571 while (!input->isReady() && !m_abandoned) {
490 SVDEBUG << "FeatureExtractionModelTransformer::run: Waiting for input model to be ready..." << endl; 572 cerr << "FeatureExtractionModelTransformer::run: Waiting for input model to be ready..." << endl;
491 usleep(500000); 573 usleep(500000);
492 } 574 }
493 if (m_abandoned) return; 575 if (m_abandoned) return;
494 576
495 size_t sampleRate = input->getSampleRate(); 577 size_t sampleRate = input->getSampleRate();
812 QString label = feature.label.c_str(); 894 QString label = feature.label.c_str();
813 if (feature.values.size() > 1) { 895 if (feature.values.size() > 1) {
814 label = QString("[%1] %2").arg(i+1).arg(label); 896 label = QString("[%1] %2").arg(i+1).arg(label);
815 } 897 }
816 898
817 model->addPoint(SparseTimeValueModel::Point(frame, value, label)); 899 SparseTimeValueModel *targetModel = model;
900
901 if (m_needAdditionalModels[n] && i > 0) {
902 targetModel = getAdditionalModel(n, i);
903 if (!targetModel) targetModel = model;
904 std::cerr << "adding point to model " << targetModel
905 << " for output " << n << " bin " << i << std::endl;
906 }
907
908 targetModel->addPoint
909 (SparseTimeValueModel::Point(frame, value, label));
818 } 910 }
819 911
820 } else if (isOutput<FlexiNoteModel>(n) || isOutput<NoteModel>(n) || isOutput<RegionModel>(n)) { //GF: Added Note Model 912 } else if (isOutput<FlexiNoteModel>(n) || isOutput<NoteModel>(n) || isOutput<RegionModel>(n)) { //GF: Added Note Model
821 913
822 int index = 0; 914 int index = 0;
911 } 1003 }
912 1004
913 void 1005 void
914 FeatureExtractionModelTransformer::setCompletion(int n, int completion) 1006 FeatureExtractionModelTransformer::setCompletion(int n, int completion)
915 { 1007 {
916 int binCount = 1;
917 if (m_descriptors[n]->hasFixedBinCount) {
918 binCount = m_descriptors[n]->binCount;
919 }
920
921 // SVDEBUG << "FeatureExtractionModelTransformer::setCompletion(" 1008 // SVDEBUG << "FeatureExtractionModelTransformer::setCompletion("
922 // << completion << ")" << endl; 1009 // << completion << ")" << endl;
923 1010
924 if (isOutput<SparseOneDimensionalModel>(n)) { 1011 if (isOutput<SparseOneDimensionalModel>(n)) {
925 1012