diff --git a/Assets/Courses/Scripts/TemplateCourse.cs b/Assets/Courses/Scripts/TemplateCourse.cs index 8bc2ad9..19b417a 100644 --- a/Assets/Courses/Scripts/TemplateCourse.cs +++ b/Assets/Courses/Scripts/TemplateCourse.cs @@ -128,9 +128,7 @@ public class TemplateCourse : MonoBehaviour { // Setting up course course = courselist.courses[courselist.currentCourseIndex]; - //feedback.signPredictor.model = course.theme.model; - feedback.signPredictor.modelList.SetCurrentModel(course.theme.modelIndex); - //feedback.signPredictor.model = feedback.signPredictor.modelList.models[feedback.signPredictor.modelList.currentModelIndex].model; + feedback.signPredictor.ChangeModel(course.theme.modelIndex); maxWords = course.theme.learnables.Count; // vvv TEMPORARY STUFF vvv diff --git a/Assets/Hangman/Scripts/HangmanGameController.cs b/Assets/Hangman/Scripts/HangmanGameController.cs index 3b83c67..9771fc6 100644 --- a/Assets/Hangman/Scripts/HangmanGameController.cs +++ b/Assets/Hangman/Scripts/HangmanGameController.cs @@ -242,7 +242,7 @@ public class HangmanGameController : MonoBehaviour userList.Save(); // Hangman always uses fingerspelling - feedback.signPredictor.model = feedback.signPredictor.modelList.GetModelByIndex(ModelIndex.FINGERSPELLING); + feedback.signPredictor.ChangeModel(ModelIndex.FINGERSPELLING); // Set calllbacks feedback.getSignCallback = () => diff --git a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs index 6815ae3..fb02a82 100644 --- a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs +++ b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs @@ -18,13 +18,10 @@ namespace Mediapipe.Unity.Tutorial { public class SignPredictor : MonoBehaviour { - - public ModelList modelList; - /// - /// Reference to the model used in the SignPredictor + /// ModelList, used to change model using ModelIndex /// - public NNModel model; + public ModelList modelList; /// /// Reference to the model info file @@ -213,12 +210,22 @@ namespace Mediapipe.Unity.Tutorial // check if model exists at path //var model = ModelLoader.Load(Resources.Load("Models/Fingerspelling/model_A-L")); - worker = model.CreateWorker(); + worker = modelList.models[modelList.currentModelIndex].model.CreateWorker(); StartCoroutine(SignRecognitionCoroutine()); StartCoroutine(MediapipeCoroutine()); } + public void ChangeModel(ModelIndex index) + { + this.modelList.SetCurrentModel(index); + // If a worker already existed, we throw it out + worker?.Dispose(); + + // Add a new worker for the new model + worker = modelList.models[modelList.currentModelIndex].model.CreateWorker(); + } + /// /// Coroutine which executes the mediapipe pipeline /// diff --git a/Assets/SpellingBee/Scripts/GameController.cs b/Assets/SpellingBee/Scripts/GameController.cs index 6e22e68..d0605fc 100644 --- a/Assets/SpellingBee/Scripts/GameController.cs +++ b/Assets/SpellingBee/Scripts/GameController.cs @@ -182,8 +182,7 @@ public partial class GameController : MonoBehaviour userList.Save(); currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex]; - //feedback.signPredictor.model = currentTheme.model; - feedback.signPredictor.model = feedback.signPredictor.modelList.GetModelByIndex(currentTheme.modelIndex); + feedback.signPredictor.ChangeModel(currentTheme.modelIndex); words.AddRange(currentTheme.learnables); ShuffleWords(); NextWord();