Implement basic signs course
This commit is contained in:
@@ -6,11 +6,11 @@ using NatML.Internal;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.IO;
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
@@ -395,7 +395,7 @@ public class SignPredictor : MonoBehaviour
|
||||
{
|
||||
string jsonData = File.ReadAllText(filePath);
|
||||
|
||||
UnityEngine.Debug.Log(jsonData);
|
||||
//UnityEngine.Debug.Log(jsonData);
|
||||
|
||||
embeddingDataList = JsonUtility.FromJson<EmbeddingDataList>("{\"dataList\":" + jsonData + "}");
|
||||
}
|
||||
@@ -600,38 +600,43 @@ public class SignPredictor : MonoBehaviour
|
||||
{
|
||||
List<DistanceEmbedding> distances = GetDistances(result, 2);
|
||||
|
||||
learnableProbabilities = new Dictionary<string, float>();
|
||||
var probs = new Dictionary<string, float>();
|
||||
|
||||
for (int j = 0; j < distances.Count; j++)
|
||||
{
|
||||
DistanceEmbedding distanceEmbedding = distances[j];
|
||||
// check if already in dictionary
|
||||
if (learnableProbabilities.ContainsKey(distanceEmbedding.embeddingData.label_name))
|
||||
if (probs.ContainsKey(distanceEmbedding.embeddingData.label_name))
|
||||
{
|
||||
// if so, check if the distance is smaller
|
||||
if (learnableProbabilities[distanceEmbedding.embeddingData.label_name] > distanceEmbedding.distance)
|
||||
if (probs[distanceEmbedding.embeddingData.label_name] > distanceEmbedding.distance)
|
||||
{
|
||||
// if so, replace the distance
|
||||
learnableProbabilities[distanceEmbedding.embeddingData.label_name] = distanceEmbedding.distance;
|
||||
probs[distanceEmbedding.embeddingData.label_name] = distanceEmbedding.distance;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if not, add the distance to the dictionary
|
||||
learnableProbabilities.Add(distanceEmbedding.embeddingData.label_name, distanceEmbedding.distance);
|
||||
probs.Add(distanceEmbedding.embeddingData.label_name, distanceEmbedding.distance);
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<string, float> newLearnableProbabilities = new Dictionary<string, float>();
|
||||
|
||||
// convert distances to probabilities, the closer to 1.5 the better the prediction
|
||||
foreach (KeyValuePair<string, float> entry in learnableProbabilities)
|
||||
var newProbs = new Dictionary<string, float>();
|
||||
float sum = 0.0f;
|
||||
foreach (KeyValuePair<string, float> entry in probs)
|
||||
{
|
||||
float probability = 1 / (1 + Mathf.Pow(2.71828f, (entry.Value - 1.6f) * 2));
|
||||
newLearnableProbabilities.Add(entry.Key, probability);
|
||||
float probability = 1 / (1 + Mathf.Exp(2 * (entry.Value - 1.6f)));
|
||||
newProbs.Add(entry.Key, probability);
|
||||
sum += probability;
|
||||
}
|
||||
|
||||
learnableProbabilities = newLearnableProbabilities;
|
||||
learnableProbabilities = new Dictionary<string, float>();
|
||||
foreach (var kv in newProbs)
|
||||
learnableProbabilities.Add(kv.Key, kv.Value / sum);
|
||||
|
||||
//UnityEngine.Debug.Log($"{learnableProbabilities.Aggregate("", (t, e) => $"{t}{e.Key}={e.Value}, ")}");
|
||||
|
||||
foreach (Listener listener in listeners)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user