| 718 | } |
| 719 | |
| 720 | TitaNetClassifyResult classify_runtime_audio( |
| 721 | TitaNetRuntime & runtime, |
| 722 | const TitaNetWeights & weights, |
| 723 | const std::vector<float> & normalized_classifier_weight, |
| 724 | const std::vector<std::string> & labels, |
| 725 | const runtime::AudioBuffer & audio) { |
| 726 | const auto start = Clock::now(); |
| 727 | if (labels.size() != static_cast<size_t>(weights.num_classes)) { |
| 728 | throw std::runtime_error("label count mismatch"); |
| 729 | } |
| 730 | auto embedding = embed_runtime_audio(runtime, weights, audio); |
| 731 | auto logits = classify_embedding(weights, normalized_classifier_weight, embedding); |
| 732 | const auto best = std::max_element(logits.begin(), logits.end()); |
| 733 | const int index = static_cast<int>(std::distance(logits.begin(), best)); |
| 734 | TitaNetClassifyResult out; |
| 735 | out.label = labels[static_cast<size_t>(index)]; |
| 736 | out.index = index; |
| 737 | out.score = *best; |
| 738 | out.embedding = std::move(embedding); |
| 739 | out.logits = std::move(logits); |
| 740 | debug::timing_log_scalar("titanet.classify_audio_ms", engine::debug::elapsed_ms(start, Clock::now())); |
| 741 | return out; |
| 742 | } |
| 743 | |
| 744 | TitaNetRuntime::TitaNetRuntime( |
| 745 | std::shared_ptr<const TitaNetWeights> weights, |
no test coverage detected