Implemented MR feedback

This commit is contained in:
CoudronJerome
2023-03-28 15:37:17 +02:00
parent dfdb2ab10b
commit be8885a508
6 changed files with 47 additions and 39 deletions

View File

@@ -1,7 +1,9 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
/// <summary>
/// This enum is used to identify each of the SignLanguage models
/// </summary>
public enum ModelIndex public enum ModelIndex
{ {
FINGERSPELLING, FINGERSPELLING,

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@@ -8,6 +9,23 @@ using Unity.Barracuda;
[CreateAssetMenu(menuName = "Create new Scriptable/ModelList")] [CreateAssetMenu(menuName = "Create new Scriptable/ModelList")]
public class ModelList : ScriptableObject public class ModelList : ScriptableObject
{ {
/// <summary>
/// Small class to link a model to a courseIndex irrespective of its position in a list
/// </summary>
[Serializable]
public class ModelTuple
{
/// <summary>
/// ModelIndex to which the model corresponds
/// </summary>
public ModelIndex index;
/// <summary>
/// The model itself
/// </summary>
public NNModel model;
}
/// <summary> /// <summary>
/// Index of the currently active model /// Index of the currently active model
/// </summary> /// </summary>
@@ -23,9 +41,10 @@ public class ModelList : ScriptableObject
/// </summary> /// </summary>
/// <param name="modelIndex">ModelIndex of the model</param> /// <param name="modelIndex">ModelIndex of the model</param>
/// <returns>Model associated with this index, null if no model was found</returns> /// <returns>Model associated with this index, null if no model was found</returns>
public NNModel GetCurrentModel() public ModelTuple GetCurrentModel()
{ {
return models[currentModelIndex].model; //if(currentModelIndex < models.Find)
return models.Find(x => x.model == models[currentModelIndex].model);
} }
/// <summary> /// <summary>

View File

@@ -1,18 +0,0 @@
using System;
using UnityEngine;
using Unity.Barracuda;
/// <summary>
/// Small class to link a model to a courseIndex irrespective of its position in a list
/// </summary>
[Serializable]
public class ModelTuple
{
/// <summary>
/// ModelIndex to which the model corresponds
/// </summary>
public ModelIndex index;
/// <summary>
/// The model itself
/// </summary>
public NNModel model;
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: bce8507dcb30db447b69708ad4f5f962
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -26,7 +26,7 @@ public class ModelListTest
{ {
ModelIndex value = (ModelIndex)field.GetValue(null); ModelIndex value = (ModelIndex)field.GetValue(null);
string name = field.Name; string name = field.Name;
ModelTuple model = new ModelTuple(); ModelList.ModelTuple model = new ModelList.ModelTuple();
// This is all we will need to distinguish // This is all we will need to distinguish
model.index = value; 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<ModelList>().GetCurrentModel());
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
[Test] [Test]
public void TestGetSetCurrentModel() public void TestSetCurrentModel()
{ {
foreach (var field in typeof(ModelIndex).GetFields()) foreach (var field in typeof(ModelIndex).GetFields())
{ {
@@ -50,12 +62,16 @@ public class ModelListTest
string name = field.Name; string name = field.Name;
modelList.SetCurrentModel(value); modelList.SetCurrentModel(value);
// Fetch the current course and check if its name is the same as the one we made into the current one // Fetch the current model and check if its name is the same as the one we made into the current one
ModelTuple m = modelList.models[modelList.currentModelIndex]; ModelList.ModelTuple m = modelList.models[modelList.currentModelIndex];
Assert.AreEqual(m.index, value); Assert.AreEqual(m.index, value);
Assert.IsTrue(m.model is NNModel || m.model is null); Assert.IsTrue(m.model is NNModel || m.model is null);
} }
} }
ModelList emptyList = ScriptableObject.CreateInstance<ModelList>();
emptyList.SetCurrentModel(ModelIndex.FINGERSPELLING);
Assert.IsTrue(emptyList.currentModelIndex == -1);
} }
} }

View File

@@ -210,7 +210,7 @@ namespace Mediapipe.Unity.Tutorial
// check if model exists at path // check if model exists at path
//var model = ModelLoader.Load(Resources.Load<NNModel>("Models/Fingerspelling/model_A-L")); //var model = ModelLoader.Load(Resources.Load<NNModel>("Models/Fingerspelling/model_A-L"));
worker = modelList.GetCurrentModel().CreateWorker(); worker = modelList.GetCurrentModel().model.CreateWorker();
StartCoroutine(SignRecognitionCoroutine()); StartCoroutine(SignRecognitionCoroutine());
StartCoroutine(MediapipeCoroutine()); StartCoroutine(MediapipeCoroutine());
@@ -223,7 +223,7 @@ namespace Mediapipe.Unity.Tutorial
worker?.Dispose(); worker?.Dispose();
// Add a new worker for the new model // Add a new worker for the new model
worker = modelList.GetCurrentModel().CreateWorker(); worker = modelList.GetCurrentModel().model.CreateWorker();
} }
/// <summary> /// <summary>