From 79bb73eb268300df2d1cd1b7c1bc9cc1974ee735 Mon Sep 17 00:00:00 2001 From: dscripka Date: Sun, 5 Mar 2023 00:12:14 -0500 Subject: [PATCH] Improved error handling and tests for custom verifier model --- openwakeword/custom_verifier_model.py | 4 ++++ tests/test_custom_verifier_model.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/openwakeword/custom_verifier_model.py b/openwakeword/custom_verifier_model.py index 1616528..d2c0211 100644 --- a/openwakeword/custom_verifier_model.py +++ b/openwakeword/custom_verifier_model.py @@ -151,6 +151,10 @@ def train_custom_verifier( [get_reference_clip_features(i, oww, model_name, N=5) for i in tqdm(positive_reference_clips, desc="Processing positive reference clips")] ) + if positive_features.shape[0] == 0: + raise ValueError("The positive features were created! Make sure that" + " the positive reference clips contain the appropriate audio" + " for the desired model") # Get features from negative reference clips negative_features = np.vstack( diff --git a/tests/test_custom_verifier_model.py b/tests/test_custom_verifier_model.py index d9576b2..0e043f5 100644 --- a/tests/test_custom_verifier_model.py +++ b/tests/test_custom_verifier_model.py @@ -32,6 +32,7 @@ import os import numpy as np import scipy.io.wavfile import tempfile +import pytest # Tests @@ -46,6 +47,15 @@ class TestModels: reference_clips = [os.path.join("tests", "data", "hey_mycroft_test.wav")] negative_clips = [os.path.join(tmp_dir, "negative_reference.wav")] + # Check for error message when no positive examples are found + with pytest.raises(ValueError): + openwakeword.train_custom_verifier( + positive_reference_clips=reference_clips, + negative_reference_clips=negative_clips, + output_path=os.path.join(tmp_dir, 'verifier_model.pkl'), + model_name="alexa" + ) + # Train verifier model on the reference clips openwakeword.train_custom_verifier( positive_reference_clips=reference_clips, @@ -54,6 +64,14 @@ class TestModels: model_name="hey_mycroft" ) + # Train verifier model on the reference clips, using full path of model file + openwakeword.train_custom_verifier( + positive_reference_clips=reference_clips, + negative_reference_clips=negative_clips, + output_path=os.path.join(tmp_dir, 'verifier_model.pkl'), + model_name=os.path.join("openwakeword", "resources", "models", "hey_mycroft_v0.1.onnx") + ) + # Load model with verifier model owwModel = openwakeword.Model( wakeword_model_paths=[os.path.join("openwakeword", "resources", "models", "hey_mycroft_v0.1.onnx")],