-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAIFramework.cs
108 lines (76 loc) · 2.47 KB
/
AIFramework.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace nyxeka.ai
{
public enum AIStep{
addWeights,sumWeights,createOutput
}
public class AIFramework : MonoBehaviour
{
/// <summary>
/// 32x32 visual input.
/// </summary>
public RenderTexture visionInput;
/// <summary>
/// visual processing results to be used with activation function.
/// </summary>
private Texture2D visionOutput;
/// <summary>
/// input weights for our processing.
/// </summary>
public Texture2D weights;
/// <summary>
/// weighted value processor.
/// </summary>
protected Texture2D weightedValues;
//protected Color32[,] texture;
public ComputeShader NNProcessor;
Color32[] pixels;
Color32 activatedStepA;
// Use this for initialization
void Start()
{
visionInput.enableRandomWrite = true;
visionOutput = new Texture2D (AITexSizes.INPUT_TEX_WIDTH, AITexSizes.INPUT_TEX_WIDTH);
weightedValues = new Texture2D (AITexSizes.WEIGHTED_VALUE_HOLDER_WIDTH, AITexSizes.WEIGHTED_VALUE_HOLDER_HEIGHT);
}
// Update is called once per frame
void Update()
{
}
void RunProcess()
{
}
void StopProcess() { }
IEnumerator VisualProcessing()
{
// "weight" as a verb.
int kernelWeightValues = NNProcessor.FindKernel (KernelNames.WeightValues);
int kernelSumValues = NNProcessor.FindKernel (KernelNames.SumWeights);
int kernelCreateOutput = NNProcessor.FindKernel (KernelNames.CreateOutput);
int kernelVisProcess = NNProcessor.FindKernel ("NNProcessVisuals");
ComputeBuffer buffer = new ComputeBuffer (1024, 16);
pixels = visionOutput.GetPixels32();
buffer.SetData (pixels);
Color32[] output = new Color32[1024];
/*
while (true) {
// */
//start by doing a dispatch
NNProcessor.SetTexture(kernelWeightValues,KernelNames.VISION_IO_BUFFER,visionInput);
NNProcessor.SetBuffer(kernelVisProcess, "output", buffer);
NNProcessor.Dispatch (kernelWeightValues, KernelNames.stepA_X, KernelNames.stepA_Y, KernelNames.stepA_Z);
//------
yield return null;
//grab the information:
buffer.GetData (output);
visionOutput.SetPixels32 (output);
visionOutput.Apply ();
activatedStepA = visionOutput.GetPixels32 (5) [0];
/*
}
// */
}
}
}