diff --git a/Assets/Common/Interfaces/ModelIndex.cs b/Assets/Common/Interfaces/ModelIndex.cs index ec15091..594fd39 100644 --- a/Assets/Common/Interfaces/ModelIndex.cs +++ b/Assets/Common/Interfaces/ModelIndex.cs @@ -1,7 +1,9 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; - +/// +/// This enum is used to identify each of the SignLanguage models +/// public enum ModelIndex { FINGERSPELLING, diff --git a/Assets/Common/Interfaces/ModelList.cs b/Assets/Common/Interfaces/ModelList.cs index 5f191a8..98ec086 100644 --- a/Assets/Common/Interfaces/ModelList.cs +++ b/Assets/Common/Interfaces/ModelList.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -8,6 +9,23 @@ using Unity.Barracuda; [CreateAssetMenu(menuName = "Create new Scriptable/ModelList")] public class ModelList : ScriptableObject { + /// + /// Small class to link a model to a courseIndex irrespective of its position in a list + /// + [Serializable] + public class ModelTuple + { + /// + /// ModelIndex to which the model corresponds + /// + public ModelIndex index; + /// + /// The model itself + /// + public NNModel model; + } + + /// /// Index of the currently active model /// @@ -23,9 +41,10 @@ public class ModelList : ScriptableObject /// /// ModelIndex of the model /// Model associated with this index, null if no model was found - public NNModel GetCurrentModel() + public ModelTuple GetCurrentModel() { - return models[currentModelIndex].model; + //if(currentModelIndex < models.Find) + return models.Find(x => x.model == models[currentModelIndex].model); } /// diff --git a/Assets/Common/Interfaces/ModelTuple.cs b/Assets/Common/Interfaces/ModelTuple.cs deleted file mode 100644 index 439e02e..0000000 --- a/Assets/Common/Interfaces/ModelTuple.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using UnityEngine; -using Unity.Barracuda; -/// -/// Small class to link a model to a courseIndex irrespective of its position in a list -/// -[Serializable] -public class ModelTuple -{ - /// - /// ModelIndex to which the model corresponds - /// - public ModelIndex index; - /// - /// The model itself - /// - public NNModel model; -} diff --git a/Assets/Common/Interfaces/ModelTuple.cs.meta b/Assets/Common/Interfaces/ModelTuple.cs.meta deleted file mode 100644 index ea41afa..0000000 --- a/Assets/Common/Interfaces/ModelTuple.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: bce8507dcb30db447b69708ad4f5f962 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Common/Tests/ModelListTest.cs b/Assets/Common/Tests/ModelListTest.cs index 2e975a9..a988913 100644 --- a/Assets/Common/Tests/ModelListTest.cs +++ b/Assets/Common/Tests/ModelListTest.cs @@ -26,7 +26,7 @@ public class ModelListTest { ModelIndex value = (ModelIndex)field.GetValue(null); string name = field.Name; - ModelTuple model = new ModelTuple(); + ModelList.ModelTuple model = new ModelList.ModelTuple(); // This is all we will need to distinguish model.index = value; @@ -36,11 +36,23 @@ public class ModelListTest } } + public void TestGetCurrentModel() + { + System.Random random = new System.Random(); + ModelIndex value = (ModelIndex)random.Next(modelList.models.Count); + modelList.SetCurrentModel(value); + + Assert.AreEqual(value, modelList.GetCurrentModel().index); + + // Check if empty model fails gracefully (returns null) + Assert.IsNull(ScriptableObject.CreateInstance().GetCurrentModel()); + } + /// - /// Check if all courses can be correctly gotten and set as current via SetCurrentCourse + /// Check if all models can be correctly set as current via SetCurrentModel /// [Test] - public void TestGetSetCurrentModel() + public void TestSetCurrentModel() { foreach (var field in typeof(ModelIndex).GetFields()) { @@ -50,12 +62,16 @@ public class ModelListTest string name = field.Name; modelList.SetCurrentModel(value); - // Fetch the current course and check if its name is the same as the one we made into the current one - ModelTuple m = modelList.models[modelList.currentModelIndex]; + // Fetch the current model and check if its name is the same as the one we made into the current one + ModelList.ModelTuple m = modelList.models[modelList.currentModelIndex]; Assert.AreEqual(m.index, value); Assert.IsTrue(m.model is NNModel || m.model is null); } } + ModelList emptyList = ScriptableObject.CreateInstance(); + emptyList.SetCurrentModel(ModelIndex.FINGERSPELLING); + + Assert.IsTrue(emptyList.currentModelIndex == -1); } } diff --git a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs index 2ec4263..8beb2dd 100644 --- a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs +++ b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs @@ -210,7 +210,7 @@ namespace Mediapipe.Unity.Tutorial // check if model exists at path //var model = ModelLoader.Load(Resources.Load("Models/Fingerspelling/model_A-L")); - worker = modelList.GetCurrentModel().CreateWorker(); + worker = modelList.GetCurrentModel().model.CreateWorker(); StartCoroutine(SignRecognitionCoroutine()); StartCoroutine(MediapipeCoroutine()); @@ -223,7 +223,7 @@ namespace Mediapipe.Unity.Tutorial worker?.Dispose(); // Add a new worker for the new model - worker = modelList.GetCurrentModel().CreateWorker(); + worker = modelList.GetCurrentModel().model.CreateWorker(); } ///