-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpellAI.cs
57 lines (52 loc) · 1.58 KB
/
SpellAI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using OpenCvSharp;
namespace Microsoft.Samples.Kinect.InfraredBasics
{
public enum Spell
{
Dud = 0,
Lumos = 1,
//Balloonius_Raisus,
Shootify = 2,
Disneyosa = 3,
Wingardium_Leviosa = 4,
Smallo_Munchio = 5,
Funsizarth = 6,
Bigcandius = 7,
Obtainit = 8,
Reparo = 9,
}
public class SpellAI
{
private const string MODEL_LOCATION = "C:\\Source\\HarryPotterMagic\\SpellNet\\model.onnx";
public const int TRACE_AI_SIZE = 50;
//private MLContext mlContext;
private InferenceSession session;
public SpellAI()
{
session = new InferenceSession(MODEL_LOCATION);
//mlContext = new MLContext();
}
public Spell Identify(float[] sample)
{
int[] dims = new int[] { 1, TRACE_AI_SIZE, TRACE_AI_SIZE, 1 };
Tensor<float> t1 = new DenseTensor<float>(sample, dims);
var xs = new List<NamedOnnxValue>()
{
NamedOnnxValue.CreateFromTensor<float>("conv2d_input", t1),
};
using (var results = session.Run(xs))
{
var one_hot = ((DenseTensor<float>)results.ElementAt(0).Value).Buffer.ToArray();
return (Spell)Array.IndexOf(one_hot, one_hot.Max());
// manipulate the results
}
}
}
}