├── .gitignore ├── Assets ├── StreamingAssets.meta ├── StreamingAssets │ ├── MNIST.meta │ └── MNIST │ │ ├── t10k-images.idx3-ubyte │ │ ├── t10k-images.idx3-ubyte.meta │ │ ├── t10k-labels.idx1-ubyte │ │ ├── t10k-labels.idx1-ubyte.meta │ │ ├── train-images.idx3-ubyte │ │ ├── train-images.idx3-ubyte.meta │ │ ├── train-labels.idx1-ubyte │ │ └── train-labels.idx1-ubyte.meta ├── UNN.meta └── UNN │ ├── GUI.meta │ ├── GUI │ ├── Roboto-Regular.ttf │ └── Roboto-Regular.ttf.meta │ ├── Scripts.meta │ ├── Scripts │ ├── Accuracy.cs │ ├── Accuracy.cs.meta │ ├── Activation.cs │ ├── Activation.cs.meta │ ├── CrossEntropyError.cs │ ├── CrossEntropyError.cs.meta │ ├── Gaussian.cs │ ├── Gaussian.cs.meta │ ├── Layers.meta │ ├── Layers │ │ ├── AffineLayer.cs │ │ ├── AffineLayer.cs.meta │ │ ├── BatchNormalizationLayer.cs │ │ ├── BatchNormalizationLayer.cs.meta │ │ ├── Layer.cs │ │ ├── Layer.cs.meta │ │ ├── OutputLayer.cs │ │ ├── OutputLayer.cs.meta │ │ ├── ReLULayer.cs │ │ ├── ReLULayer.cs.meta │ │ ├── SoftmaxLayer.cs │ │ ├── SoftmaxLayer.cs.meta │ │ ├── TrainLayer.cs │ │ └── TrainLayer.cs.meta │ ├── MatOperations.cs │ ├── MatOperations.cs.meta │ ├── Matrix.cs │ ├── Matrix.cs.meta │ ├── Network.cs │ ├── Network.cs.meta │ ├── Optimizers.meta │ ├── Optimizers │ │ ├── MomentumOptimizer.cs │ │ ├── MomentumOptimizer.cs.meta │ │ ├── Optimizer.cs │ │ ├── Optimizer.cs.meta │ │ ├── SGDOptimizer.cs │ │ └── SGDOptimizer.cs.meta │ ├── Signal.cs │ └── Signal.cs.meta │ ├── Shaders.meta │ ├── Shaders │ ├── Common.meta │ ├── Compute.meta │ └── Compute │ │ ├── UNN.compute │ │ └── UNN.compute.meta │ ├── Test.meta │ └── Test │ ├── MNIST.meta │ └── MNIST │ ├── MNISTBatchNormalizationTest.unity │ ├── MNISTBatchNormalizationTest.unity.meta │ ├── MNISTTest.unity │ ├── MNISTTest.unity.meta │ ├── Materials.meta │ ├── Materials │ ├── DigitProb.mat │ ├── DigitProb.mat.meta │ ├── MNISTDraw.mat │ ├── MNISTDraw.mat.meta │ ├── MNISTInput.mat │ └── MNISTInput.mat.meta │ ├── Scripts.meta │ ├── Scripts │ ├── Digit.cs │ ├── Digit.cs.meta │ ├── DigitDataset.cs │ ├── DigitDataset.cs.meta │ ├── DigitProb.cs │ ├── DigitProb.cs.meta │ ├── MNISTBatchNormalizationNetwork.cs │ ├── MNISTBatchNormalizationNetwork.cs.meta │ ├── MNISTBatchNormalizationTest.cs │ ├── MNISTBatchNormalizationTest.cs.meta │ ├── MNISTInput.cs │ ├── MNISTInput.cs.meta │ ├── MNISTNetwork.cs │ ├── MNISTNetwork.cs.meta │ ├── MNISTTest.cs │ └── MNISTTest.cs.meta │ ├── Shaders.meta │ └── Shaders │ ├── DigitProb.shader │ ├── DigitProb.shader.meta │ ├── MNISTDraw.shader │ ├── MNISTDraw.shader.meta │ ├── MNISTInput.compute │ ├── MNISTInput.compute.meta │ ├── MNISTInput.shader │ └── MNISTInput.shader.meta ├── Captures └── MNIST.gif ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset └── UnityConnectSettings.asset ├── README.md └── UnityPackageManager └── manifest.json /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | Papers/ 6 | .vs/ 7 | 8 | # Autogenerated VS/MD solution and project files 9 | *.csproj 10 | *.unityproj 11 | *.sln 12 | *.suo 13 | *.user 14 | *.userprefs 15 | *.pidb 16 | *.booproj 17 | 18 | # Unity3D Generated File On Crash Reports 19 | sysinfo.txt 20 | -------------------------------------------------------------------------------- /Assets/StreamingAssets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3b089f99f18c36d449f58553b7c6f0aa 3 | folderAsset: yes 4 | timeCreated: 1531375052 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/MNIST.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 98e82817cef70e84db9e6c266fe3c0eb 3 | folderAsset: yes 4 | timeCreated: 1531375068 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/MNIST/t10k-images.idx3-ubyte: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattatz/UNN/676e1d4f313f1079baa57389ad1dea0eb0d75b57/Assets/StreamingAssets/MNIST/t10k-images.idx3-ubyte -------------------------------------------------------------------------------- /Assets/StreamingAssets/MNIST/t10k-images.idx3-ubyte.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d0c5a088607e0694b831fec4b0adbad1 3 | timeCreated: 1531375537 4 | licenseType: Pro 5 | DefaultImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/MNIST/t10k-labels.idx1-ubyte: -------------------------------------------------------------------------------- 1 | '                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             -------------------------------------------------------------------------------- /Assets/StreamingAssets/MNIST/t10k-labels.idx1-ubyte.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1500ef2fcec0afd41b5a9cae0d400f5f 3 | timeCreated: 1531375577 4 | licenseType: Pro 5 | DefaultImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/MNIST/train-images.idx3-ubyte: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattatz/UNN/676e1d4f313f1079baa57389ad1dea0eb0d75b57/Assets/StreamingAssets/MNIST/train-images.idx3-ubyte -------------------------------------------------------------------------------- /Assets/StreamingAssets/MNIST/train-images.idx3-ubyte.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a6085762dc82ce64aae19ead4922666e 3 | timeCreated: 1531375090 4 | licenseType: Pro 5 | DefaultImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/MNIST/train-labels.idx1-ubyte: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattatz/UNN/676e1d4f313f1079baa57389ad1dea0eb0d75b57/Assets/StreamingAssets/MNIST/train-labels.idx1-ubyte -------------------------------------------------------------------------------- /Assets/StreamingAssets/MNIST/train-labels.idx1-ubyte.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f231d4e05f56d746b2f4ecd5c9268de 3 | timeCreated: 1531375074 4 | licenseType: Pro 5 | DefaultImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/UNN.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b4438e3bd13e1d4cb0b8a8610bf075d 3 | folderAsset: yes 4 | timeCreated: 1531128094 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/GUI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e7f3cd1dfccb40c428dacb5d97376cd8 3 | folderAsset: yes 4 | timeCreated: 1532586008 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/GUI/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattatz/UNN/676e1d4f313f1079baa57389ad1dea0eb0d75b57/Assets/UNN/GUI/Roboto-Regular.ttf -------------------------------------------------------------------------------- /Assets/UNN/GUI/Roboto-Regular.ttf.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ef7400de42ccc344922cae4be4d899e 3 | timeCreated: 1532585999 4 | licenseType: Pro 5 | TrueTypeFontImporter: 6 | externalObjects: {} 7 | serializedVersion: 4 8 | fontSize: 16 9 | forceTextureCase: -2 10 | characterSpacing: 0 11 | characterPadding: 1 12 | includeFontData: 1 13 | fontName: Roboto 14 | fontNames: 15 | - Roboto 16 | fallbackFontReferences: [] 17 | customCharacters: 18 | fontRenderingMode: 0 19 | ascentCalculationMode: 1 20 | useLegacyBoundsCalculation: 0 21 | userData: 22 | assetBundleName: 23 | assetBundleVariant: 24 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92dc0fac708e11347b5eef2919411870 3 | folderAsset: yes 4 | timeCreated: 1531128101 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Accuracy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN 6 | { 7 | 8 | public class Accuracy { 9 | 10 | 11 | public static float Calculate(ComputeShader compute, Signal input, Signal output, Signal answer) 12 | { 13 | var batchSize = input.Rows; 14 | 15 | var tmp = new Signal(batchSize, 1); 16 | 17 | var kernel = compute.FindKernel("Accuracy"); 18 | compute.SetBuffer(kernel, "_X", output.Buffer); 19 | compute.SetBuffer(kernel, "_T", answer.Buffer); 20 | compute.SetBuffer(kernel, "_Y", tmp.Buffer); 21 | compute.SetInt("_Rows", batchSize); 22 | compute.SetInt("_Cols", answer.Columns); 23 | 24 | uint tx, ty, tz; 25 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 26 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)batchSize - 1) / tx) + 1, (int)ty, (int)tz); 27 | 28 | var data = tmp.GetData(); 29 | float acc = 0f; 30 | for(int x = 0; x < batchSize; x++) 31 | { 32 | acc += data[x, 0]; 33 | } 34 | 35 | // tmp.Log(); 36 | // Debug.Log(acc); 37 | 38 | tmp.Dispose(); 39 | 40 | return acc / batchSize; 41 | } 42 | 43 | } 44 | 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Accuracy.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 61b230b3cfc271445a603dd15686e41b 3 | timeCreated: 1531464822 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Activation.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN 6 | { 7 | 8 | public enum ActivationMethod 9 | { 10 | Relu = 0, 11 | Sigmoid = 1 12 | }; 13 | 14 | 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Activation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84b38341f96c1b54e8edb104e72bd152 3 | timeCreated: 1531128407 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/CrossEntropyError.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN 6 | { 7 | 8 | public class CrossEntropyError { 9 | 10 | public static float Loss(ComputeShader compute, Signal input, Signal answer) 11 | { 12 | int batchSize = input.Rows; 13 | 14 | Signal temp = new Signal(answer.Rows, answer.Columns); 15 | 16 | var kernel = compute.FindKernel("Log"); 17 | int rows = temp.Rows, columns = temp.Columns; 18 | 19 | uint tx, ty, tz; 20 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 21 | compute.SetInt("_Rows", rows); 22 | compute.SetInt("_Cols", columns); 23 | compute.SetBuffer(kernel, "_X", input.Buffer); 24 | compute.SetBuffer(kernel, "_T", answer.Buffer); 25 | compute.SetBuffer(kernel, "_Y", temp.Buffer); 26 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)columns - 1) / tx) + 1, Mathf.FloorToInt(((int)rows - 1) / ty) + 1, (int)tz); 27 | 28 | float[,] log = temp.GetData(); 29 | 30 | float sum = 0f; 31 | for(int y = 0; y < rows; y++) 32 | { 33 | for(int x = 0; x < columns; x++) 34 | { 35 | sum += log[y, x]; 36 | } 37 | } 38 | 39 | temp.Dispose(); 40 | 41 | return - sum / batchSize; 42 | } 43 | 44 | } 45 | 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/CrossEntropyError.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c0c9ebace6a225429e261c181b40fd9 3 | timeCreated: 1531462888 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Gaussian.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | using UnityEngine; 5 | using Random = UnityEngine.Random; 6 | 7 | namespace UNN 8 | { 9 | 10 | public class Gaussian { 11 | 12 | public static float SampleRandom(float mean = 0f, float stddev = 1f) 13 | { 14 | var x1 = Random.value; 15 | var x2 = Random.value; 16 | var y1 = Mathf.Sqrt(-2.0f * Mathf.Log(x1)) * Mathf.Cos(2.0f * Mathf.PI * x2); 17 | return y1 * stddev + mean; 18 | } 19 | 20 | } 21 | 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Gaussian.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f51f1685802a9c42b77b0fee1e73426 3 | timeCreated: 1531381359 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 46e3099e724292c418738a7594e0fbad 3 | folderAsset: yes 4 | timeCreated: 1531459982 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/AffineLayer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | 5 | using UnityEngine; 6 | 7 | namespace UNN 8 | { 9 | 10 | [System.Serializable] 11 | public class AffineLayer : TrainLayer 12 | { 13 | public Signal Weights { get { return weights; } } 14 | public Signal Biases { get { return biases; } } 15 | 16 | [SerializeField] protected Signal weights, biases; 17 | 18 | protected Signal x; 19 | protected Signal dW, dB; 20 | 21 | public AffineLayer(int rows, int columns, float weight_std = 0.01f) : base(rows, columns) 22 | { 23 | var weights = new float[rows, columns]; 24 | var biases = new float[columns]; 25 | 26 | // Debug.Log(weight_std); 27 | 28 | for(int y = 0; y < rows; y++) 29 | { 30 | for(int x = 0; x < columns; x++) 31 | { 32 | weights[y, x] = weight_std * Gaussian.SampleRandom(); 33 | } 34 | } 35 | 36 | for (int x = 0; x < columns; x++) 37 | { 38 | biases[x] = 0f; 39 | } 40 | 41 | this.weights = new Signal(weights); 42 | this.biases = new Signal(biases); 43 | } 44 | 45 | public override Signal Forward(ComputeShader compute, Signal x, bool train) 46 | { 47 | this.x = Refresh(x, this.x); 48 | MatOperations.CopyMM(compute, x, this.x); 49 | 50 | var output = new Signal(x.Rows, weights.Columns); 51 | 52 | // matmul M = input * weights 53 | MatOperations.Multiply(compute, x, weights, output); 54 | 55 | // matplus M´ = M + biases 56 | MatOperations.AddVM(compute, biases, output); 57 | 58 | // output.Log(); 59 | 60 | return output; 61 | } 62 | 63 | public override Signal Backward(ComputeShader compute, Signal dout) 64 | { 65 | var dx = new Signal(dout.Rows, weights.Rows); 66 | MatOperations.MultiplyMT(compute, dout, weights, dx); 67 | // dx.Log(); 68 | 69 | dW = Refresh(x.Columns, dout.Columns, dW); 70 | MatOperations.MultiplyTM(compute, x, dout, dW); 71 | 72 | dB = Refresh(1, dout.Columns, dB); 73 | MatOperations.SumMV(compute, dout, dB); 74 | 75 | // dx.Log(); 76 | // dw.Log(); 77 | // db.Log(); 78 | 79 | return dx; 80 | } 81 | 82 | public override void Learn(Optimizer optimizer, ComputeShader compute, float rate) 83 | { 84 | optimizer.Update(compute, rate, weights, dW); 85 | optimizer.Update(compute, rate, biases, dB); 86 | } 87 | 88 | public override void Dispose() 89 | { 90 | if(weights != null) 91 | { 92 | weights.Dispose(); 93 | biases.Dispose(); 94 | weights = biases = null; 95 | } 96 | 97 | if(x != null) 98 | { 99 | x.Dispose(); 100 | x = null; 101 | } 102 | 103 | if(dW != null) 104 | { 105 | dW.Dispose(); 106 | dB.Dispose(); 107 | } 108 | 109 | } 110 | 111 | } 112 | 113 | } 114 | 115 | 116 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/AffineLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cbdffbcd81408464aa2ef718ade91ee0 3 | timeCreated: 1531129833 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/BatchNormalizationLayer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN 6 | { 7 | 8 | [System.Serializable] 9 | public class BatchNormalizationLayer : TrainLayer 10 | { 11 | 12 | [SerializeField] protected Signal gamma, beta; 13 | protected Signal dgamma, dbeta; 14 | 15 | [SerializeField] protected float momentum; 16 | 17 | [SerializeField] protected int batchSize; 18 | 19 | protected Signal xc, xn, std; 20 | [SerializeField] protected Signal runningMean, runningVar; 21 | 22 | public BatchNormalizationLayer(int rows, int columns, float momentum = 0.9f) : base(rows, columns) 23 | { 24 | this.momentum = momentum; 25 | 26 | gamma = new Signal(1, columns); 27 | gamma.Init(1f); 28 | 29 | beta = new Signal(1, columns); 30 | beta.Init(0f); 31 | 32 | runningMean = new Signal(1, columns); 33 | runningMean.Init(0f); 34 | 35 | runningVar = new Signal(1, columns); 36 | runningVar.Init(0f); 37 | } 38 | 39 | public override Signal Forward(ComputeShader compute, Signal x, bool train) 40 | { 41 | if(train) 42 | { 43 | var mu = new Signal(1, x.Columns); 44 | MatOperations.MeanMV(compute, x, mu); 45 | // x.Log("x"); 46 | // mu.Log("mu"); 47 | 48 | xc = Refresh(x, xc); // xc = x - mu 49 | MatOperations.SubMVM(compute, x, mu, xc); 50 | // xc.Log("xc"); 51 | 52 | var variance = new Signal(1, xc.Columns); 53 | MatOperations.VarianceMV(compute, xc, variance); 54 | // variance.Log("variance"); 55 | 56 | std = Refresh(variance, std); 57 | MatOperations.SqrtMM(compute, variance, std); 58 | // std.Log("std"); 59 | 60 | xn = Refresh(xc, xn); // xn = xc / std 61 | MatOperations.DivMVM(compute, xc, std, xn); 62 | 63 | batchSize = x.Rows; 64 | 65 | Momentum(compute, mu, runningMean); 66 | Momentum(compute, variance, runningVar); 67 | 68 | mu.Dispose(); 69 | variance.Dispose(); 70 | } else 71 | { 72 | xc = Refresh(x, xc); // xc = x - runningMean 73 | MatOperations.SubMVM(compute, x, runningMean, xc); 74 | // x.Log("x"); 75 | // runningMean.Log("runningMean"); 76 | // xn.Log("xn"); 77 | 78 | xn = Refresh(xc, xn); // xn = xc / sqrt(runningVar + epsilon) 79 | Xn(compute, xc, runningVar, xn); 80 | } 81 | 82 | var output = new Signal(xn); 83 | 84 | var kernel = compute.FindKernel("BNForward"); 85 | compute.SetBuffer(kernel, "_X", xn.Buffer); 86 | compute.SetBuffer(kernel, "_Gamma", gamma.Buffer); 87 | compute.SetBuffer(kernel, "_Beta", beta.Buffer); 88 | compute.SetBuffer(kernel, "_Y", output.Buffer); 89 | Dispatch(compute, kernel, output.Rows, output.Columns); 90 | 91 | return output; 92 | } 93 | 94 | public override Signal Backward(ComputeShader compute, Signal dout) 95 | { 96 | dbeta = Refresh(1, dout.Columns, dbeta); 97 | MatOperations.SumMV(compute, dout, dbeta); 98 | 99 | dgamma = Refresh(1, dout.Columns, dgamma); 100 | MatOperations.MulMM(compute, dout, xn); 101 | MatOperations.SumMV(compute, xn, dgamma); 102 | 103 | var dxn = new Signal(dout); 104 | MatOperations.MulMVM(compute, dout, gamma, dxn); 105 | 106 | var dxc = new Signal(dxn); 107 | MatOperations.DivMVM(compute, dxn, std, dxc); 108 | 109 | var dxn_x_xc = new Signal(dxn); 110 | MatOperations.MulMMM(compute, dxn, xc, dxn_x_xc); 111 | dxn.Dispose(); 112 | 113 | var std_x_std = new Signal(std); 114 | MatOperations.MulMMM(compute, std, std, std_x_std); 115 | 116 | var dxn_x_xc_div_std_x_std = new Signal(dxn_x_xc); 117 | MatOperations.DivMVM(compute, dxn_x_xc, std_x_std, dxn_x_xc_div_std_x_std); 118 | dxn_x_xc.Dispose(); 119 | std_x_std.Dispose(); 120 | 121 | var dstd = new Signal(std); 122 | MatOperations.SumMV(compute, dxn_x_xc_div_std_x_std, dstd); 123 | dxn_x_xc_div_std_x_std.Dispose(); 124 | 125 | var dvar = new Signal(dstd); 126 | DVar(compute, dstd, std, dvar); 127 | dstd.Dispose(); 128 | 129 | DXc(compute, xc, dvar, dxc, 2f / batchSize); 130 | dvar.Dispose(); 131 | 132 | var dmu = new Signal(1, dxc.Columns); 133 | MatOperations.SumMV(compute, dxc, dmu); 134 | 135 | var dx = new Signal(dout); 136 | DX(compute, dxc, dmu, dx, 1f / batchSize); 137 | dxc.Dispose(); 138 | dmu.Dispose(); 139 | 140 | return dx; 141 | } 142 | 143 | public override void Learn(Optimizer optimizer, ComputeShader compute, float rate) 144 | { 145 | optimizer.Update(compute, rate, gamma, dgamma); 146 | optimizer.Update(compute, rate, beta, dbeta); 147 | } 148 | 149 | protected void Momentum(ComputeShader compute, Signal X, Signal Y) 150 | { 151 | var kernel = compute.FindKernel("BNMomentum"); 152 | compute.SetBuffer(kernel, "_X", X.Buffer); 153 | compute.SetBuffer(kernel, "_Y", Y.Buffer); 154 | compute.SetFloat("_Momentum", momentum); 155 | Dispatch(compute, kernel, Y.Rows, Y.Columns); 156 | } 157 | 158 | protected void Xn(ComputeShader compute, Signal X, Signal T, Signal Y) 159 | { 160 | var kernel = compute.FindKernel("BNXn"); 161 | compute.SetBuffer(kernel, "_X", X.Buffer); 162 | compute.SetBuffer(kernel, "_T", T.Buffer); 163 | compute.SetBuffer(kernel, "_Y", Y.Buffer); 164 | Dispatch(compute, kernel, Y.Rows, Y.Columns); 165 | } 166 | 167 | protected void DVar(ComputeShader compute, Signal X, Signal T, Signal Y) 168 | { 169 | var kernel = compute.FindKernel("BNDVar"); 170 | compute.SetBuffer(kernel, "_X", X.Buffer); 171 | compute.SetBuffer(kernel, "_T", T.Buffer); 172 | compute.SetBuffer(kernel, "_Y", Y.Buffer); 173 | Dispatch(compute, kernel, Y.Rows, Y.Columns); 174 | } 175 | 176 | protected void DXc(ComputeShader compute, Signal X, Signal T, Signal Y, float sigma) 177 | { 178 | var kernel = compute.FindKernel("BNDXc"); 179 | compute.SetBuffer(kernel, "_X", X.Buffer); 180 | compute.SetBuffer(kernel, "_T", T.Buffer); 181 | compute.SetBuffer(kernel, "_Y", Y.Buffer); 182 | compute.SetFloat("_Sigma", sigma); 183 | Dispatch(compute, kernel, Y.Rows, Y.Columns); 184 | } 185 | 186 | protected void DX(ComputeShader compute, Signal X, Signal T, Signal Y, float sigma) 187 | { 188 | var kernel = compute.FindKernel("BNDX"); 189 | compute.SetBuffer(kernel, "_X", X.Buffer); 190 | compute.SetBuffer(kernel, "_T", T.Buffer); 191 | compute.SetBuffer(kernel, "_Y", Y.Buffer); 192 | compute.SetFloat("_Sigma", sigma); 193 | Dispatch(compute, kernel, Y.Rows, Y.Columns); 194 | } 195 | 196 | public override void Dispose() 197 | { 198 | if(gamma != null) 199 | { 200 | gamma.Dispose(); 201 | beta.Dispose(); 202 | } 203 | 204 | if (dgamma != null) 205 | { 206 | dgamma.Dispose(); 207 | dbeta.Dispose(); 208 | } 209 | 210 | if(xc != null) { 211 | xc.Dispose(); 212 | xn.Dispose(); 213 | } 214 | 215 | if(std != null) 216 | { 217 | std.Dispose(); 218 | } 219 | 220 | if(runningMean != null) 221 | { 222 | runningMean.Dispose(); 223 | runningVar.Dispose(); 224 | } 225 | 226 | dgamma = dbeta = null; 227 | gamma = beta = null; 228 | xc = xn = std = runningMean = runningVar = null; 229 | } 230 | 231 | } 232 | 233 | } 234 | 235 | 236 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/BatchNormalizationLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7601e71aa2f6ccb4b90d4537fc79f61e 3 | timeCreated: 1531885665 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/Layer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | using UnityEngine; 6 | 7 | namespace UNN 8 | { 9 | 10 | 11 | [System.Serializable] 12 | public abstract class Layer : IDisposable { 13 | 14 | public Layer() 15 | { 16 | } 17 | 18 | public abstract Signal Forward(ComputeShader compute, Signal x, bool train); 19 | public abstract Signal Backward(ComputeShader compute, Signal dout); 20 | 21 | protected Signal Refresh(Signal src, Signal dst) 22 | { 23 | return Refresh(src.Rows, src.Columns, dst); 24 | } 25 | 26 | protected Signal Refresh(int rows, int cols, Signal dst) 27 | { 28 | if(dst == null) 29 | { 30 | dst = new Signal(rows, cols); 31 | } else if(dst.Rows != rows || dst.Columns != cols) 32 | { 33 | dst.Dispose(); 34 | dst = new Signal(rows, cols); 35 | } 36 | return dst; 37 | } 38 | 39 | protected void Dispatch(ComputeShader compute, int kernel, int rows, int columns) 40 | { 41 | uint tx, ty, tz; 42 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 43 | compute.SetInt("_Rows", rows); 44 | compute.SetInt("_Cols", columns); 45 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)columns - 1) / tx) + 1, Mathf.FloorToInt(((int)rows - 1) / ty) + 1, (int)tz); 46 | } 47 | 48 | public abstract void Dispose(); 49 | 50 | } 51 | 52 | 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/Layer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5dd8ab8ab14d48d4a825b2e397a8b8a3 3 | timeCreated: 1531129081 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/OutputLayer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN 6 | { 7 | 8 | public abstract class OutputLayer : Layer { 9 | 10 | // public abstract void Backward(ComputeShader compute, Signal answer); 11 | 12 | } 13 | 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/OutputLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9010f21b66ed6154bac6e1ab075911d9 3 | timeCreated: 1531466006 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/ReLULayer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | 5 | using UnityEngine; 6 | 7 | namespace UNN 8 | { 9 | 10 | 11 | [System.Serializable] 12 | public class ReLULayer : Layer 13 | { 14 | 15 | protected Signal mask; 16 | 17 | public ReLULayer() : base() 18 | { 19 | } 20 | 21 | public override Signal Forward(ComputeShader compute, Signal x, bool train) 22 | { 23 | mask = Refresh(x, mask); 24 | 25 | var kernel = compute.FindKernel("ReLU"); 26 | compute.SetBuffer(kernel, "_X", x.Buffer); 27 | compute.SetBuffer(kernel, "_Y", mask.Buffer); 28 | Dispatch(compute, kernel, mask.Rows, mask.Columns); 29 | 30 | var output = new Signal(mask); 31 | MatOperations.CopyMM(compute, mask, output); 32 | return output; 33 | } 34 | 35 | public override Signal Backward(ComputeShader compute, Signal dout) 36 | { 37 | var output = new Signal(dout); 38 | 39 | var kernel = compute.FindKernel("ReLUBackward"); 40 | compute.SetBuffer(kernel, "_X", dout.Buffer); 41 | compute.SetBuffer(kernel, "_T", mask.Buffer); 42 | compute.SetBuffer(kernel, "_Y", output.Buffer); 43 | Dispatch(compute, kernel, output.Rows, output.Columns); 44 | 45 | // mask.Log(); 46 | // dout.Log(); 47 | 48 | return output; 49 | } 50 | 51 | public override void Dispose() 52 | { 53 | if(mask != null) 54 | { 55 | mask.Dispose(); 56 | mask = null; 57 | } 58 | } 59 | 60 | } 61 | 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/ReLULayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 628bde72abf0a1f4a912eb527042b4ac 3 | timeCreated: 1531389361 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/SoftmaxLayer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN 6 | { 7 | 8 | [System.Serializable] 9 | public class SoftmaxLayer : OutputLayer { 10 | 11 | protected Signal y; 12 | 13 | public SoftmaxLayer() : base() 14 | { 15 | } 16 | 17 | public override Signal Forward(ComputeShader compute, Signal x, bool train) 18 | { 19 | var temp = new Signal(x.Rows, x.Columns); 20 | 21 | var kernel = compute.FindKernel("Exp"); 22 | compute.SetBuffer(kernel, "_X", x.Buffer); 23 | compute.SetBuffer(kernel, "_Y", temp.Buffer); 24 | Dispatch(compute, kernel, temp.Rows, temp.Columns); 25 | 26 | y = Refresh(x, y); 27 | kernel = compute.FindKernel("Softmax"); 28 | compute.SetBuffer(kernel, "_X", temp.Buffer); 29 | compute.SetBuffer(kernel, "_Y", y.Buffer); 30 | Dispatch(compute, kernel, y.Rows, y.Columns); 31 | 32 | temp.Dispose(); 33 | 34 | return y; 35 | } 36 | 37 | public override Signal Backward(ComputeShader compute, Signal answer) 38 | { 39 | int batchSize = answer.Rows; 40 | var output = new Signal(answer.Rows, answer.Columns); 41 | var kernel = compute.FindKernel("SoftmaxBackward"); 42 | compute.SetBuffer(kernel, "_X", y.Buffer); 43 | compute.SetBuffer(kernel, "_T", answer.Buffer); 44 | compute.SetBuffer(kernel, "_Y", output.Buffer); 45 | compute.SetInt("_BatchSize", batchSize); 46 | Dispatch(compute, kernel, output.Rows, output.Columns); 47 | 48 | return output; 49 | } 50 | 51 | public override void Dispose() 52 | { 53 | if(y != null) 54 | { 55 | y.Dispose(); 56 | y = null; 57 | } 58 | } 59 | 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/SoftmaxLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 39b2b60140ca59b4482f0c89f52b5ceb 3 | timeCreated: 1531460015 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/TrainLayer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN 6 | { 7 | 8 | public abstract class TrainLayer : Layer 9 | { 10 | 11 | [SerializeField] protected int rows, columns; 12 | 13 | public TrainLayer(int rows, int columns) : base() 14 | { 15 | this.rows = rows; 16 | this.columns = columns; 17 | } 18 | 19 | public abstract void Learn(Optimizer optimizer, ComputeShader compute, float rate); 20 | 21 | } 22 | 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Layers/TrainLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 238f6f6fedeab5a4a8bc0a029b78a9ad 3 | timeCreated: 1531817400 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/MatOperations.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN 6 | { 7 | 8 | public class MatOperations { 9 | 10 | public static void CopyMM(ComputeShader compute, Signal B, Signal C) 11 | { 12 | OpMM(compute, compute.FindKernel("CopyMM"), B, C); 13 | } 14 | 15 | public static void SqrtMM(ComputeShader compute, Signal B, Signal C) 16 | { 17 | OpMM(compute, compute.FindKernel("SqrtMM"), B, C); 18 | } 19 | 20 | public static void AddMM(ComputeShader compute, Signal B, Signal C) 21 | { 22 | OpMM(compute, compute.FindKernel("AddMM"), B, C); 23 | } 24 | 25 | public static void SubMM(ComputeShader compute, Signal B, Signal C) 26 | { 27 | OpMM(compute, compute.FindKernel("SubMM"), B, C); 28 | } 29 | 30 | public static void MulMM(ComputeShader compute, Signal B, Signal C) 31 | { 32 | OpMM(compute, compute.FindKernel("MulMM"), B, C); 33 | } 34 | 35 | public static void DivMM(ComputeShader compute, Signal B, Signal C) 36 | { 37 | OpMM(compute, compute.FindKernel("DivMM"), B, C); 38 | } 39 | 40 | public static void MulMMM(ComputeShader compute, Signal A, Signal B, Signal C) 41 | { 42 | OpMMM(compute, compute.FindKernel("MulMMM"), A, B, C); 43 | } 44 | 45 | public static void DivMMM(ComputeShader compute, Signal A, Signal B, Signal C) 46 | { 47 | OpMMM(compute, compute.FindKernel("DivMMM"), A, B, C); 48 | } 49 | 50 | 51 | public static void SubMVM(ComputeShader compute, Signal A, Signal B, Signal C) 52 | { 53 | OpMVM(compute, compute.FindKernel("SubMVM"), A, B, C); 54 | } 55 | 56 | public static void MulMVM(ComputeShader compute, Signal A, Signal B, Signal C) 57 | { 58 | OpMVM(compute, compute.FindKernel("MulMVM"), A, B, C); 59 | } 60 | 61 | public static void DivMVM(ComputeShader compute, Signal A, Signal B, Signal C) 62 | { 63 | OpMVM(compute, compute.FindKernel("DivMVM"), A, B, C); 64 | } 65 | 66 | 67 | 68 | public static void AddVM(ComputeShader compute, Signal B, Signal C) 69 | { 70 | OpVM(compute, compute.FindKernel("AddVM"), B, C); 71 | } 72 | 73 | public static void SubVM(ComputeShader compute, Signal B, Signal C) 74 | { 75 | OpVM(compute, compute.FindKernel("SubVM"), B, C); 76 | } 77 | 78 | public static void DivVM(ComputeShader compute, Signal B, Signal C) 79 | { 80 | OpVM(compute, compute.FindKernel("DivVM"), B, C); 81 | } 82 | 83 | public static void SumMV(ComputeShader compute, Signal B, Signal C) 84 | { 85 | OpMV(compute, compute.FindKernel("SumMV"), B, C); 86 | } 87 | 88 | public static void MeanMV(ComputeShader compute, Signal B, Signal C) 89 | { 90 | OpMV(compute, compute.FindKernel("MeanMV"), B, C); 91 | } 92 | 93 | public static void VarianceMV(ComputeShader compute, Signal B, Signal C) 94 | { 95 | OpMV(compute, compute.FindKernel("VarianceMV"), B, C); 96 | } 97 | 98 | public static void Multiply(ComputeShader compute, Signal A, Signal B, Signal C) 99 | { 100 | Multiply( 101 | compute, 102 | A.Buffer, B.Buffer, C.Buffer, 103 | A.Rows, A.Columns, 104 | B.Rows, B.Columns, 105 | C.Rows, C.Columns 106 | ); 107 | } 108 | 109 | public static void MultiplyTM(ComputeShader compute, Signal A, Signal B, Signal C) 110 | { 111 | MultiplyTM(compute, A.Buffer, B.Buffer, C.Buffer, A.Rows, A.Columns, B.Rows, B.Columns, C.Rows, C.Columns); 112 | } 113 | 114 | public static void MultiplyMT(ComputeShader compute, Signal A, Signal B, Signal C) 115 | { 116 | MultiplyMT(compute, A.Buffer, B.Buffer, C.Buffer, A.Rows, A.Columns, B.Rows, B.Columns, C.Rows, C.Columns); 117 | } 118 | 119 | public static void Multiply(ComputeShader compute, ComputeBuffer A, ComputeBuffer B, ComputeBuffer C, int aRows, int aCols, int bRows, int bCols, int cRows, int cCols) 120 | { 121 | if(aCols != bRows) 122 | { 123 | Debug.LogWarning("A cols != B rows"); 124 | } 125 | 126 | compute.SetInt("_ARows", aRows); compute.SetInt("_ACols", aCols); 127 | compute.SetInt("_BRows", bRows); compute.SetInt("_BCols", bCols); 128 | compute.SetInt("_CRows", cRows); compute.SetInt("_CCols", cCols); 129 | 130 | var kernel = compute.FindKernel("MatMul"); 131 | compute.SetBuffer(kernel, "_A", A); 132 | compute.SetBuffer(kernel, "_B", B); 133 | compute.SetBuffer(kernel, "_C", C); 134 | 135 | uint tx, ty, tz; 136 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 137 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)cCols - 1) / tx) + 1, Mathf.FloorToInt(((int)cRows - 1) / ty) + 1, (int)tz); 138 | } 139 | 140 | public static void MultiplyTM(ComputeShader compute, ComputeBuffer A, ComputeBuffer B, ComputeBuffer C, int aRows, int aCols, int bRows, int bCols, int cRows, int cCols) 141 | { 142 | if(aRows != bRows) 143 | { 144 | Debug.LogWarning("A cols != B rows"); 145 | } 146 | 147 | compute.SetInt("_ARows", aRows); compute.SetInt("_ACols", aCols); 148 | compute.SetInt("_BRows", bRows); compute.SetInt("_BCols", bCols); 149 | compute.SetInt("_CRows", cRows); compute.SetInt("_CCols", cCols); 150 | 151 | var kernel = compute.FindKernel("MatMulTM"); 152 | compute.SetBuffer(kernel, "_A", A); 153 | compute.SetBuffer(kernel, "_B", B); 154 | compute.SetBuffer(kernel, "_C", C); 155 | 156 | uint tx, ty, tz; 157 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 158 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)cCols - 1) / tx) + 1, Mathf.FloorToInt(((int)cRows - 1) / ty) + 1, (int)tz); 159 | } 160 | 161 | public static void MultiplyMT(ComputeShader compute, ComputeBuffer A, ComputeBuffer B, ComputeBuffer C, int aRows, int aCols, int bRows, int bCols, int cRows, int cCols) 162 | { 163 | if(aCols != bCols) 164 | { 165 | Debug.LogWarning("A cols != B cols"); 166 | } 167 | 168 | compute.SetInt("_ARows", aRows); compute.SetInt("_ACols", aCols); 169 | compute.SetInt("_BRows", bRows); compute.SetInt("_BCols", bCols); 170 | compute.SetInt("_CRows", cRows); compute.SetInt("_CCols", cCols); 171 | 172 | var kernel = compute.FindKernel("MatMulMT"); 173 | compute.SetBuffer(kernel, "_A", A); 174 | compute.SetBuffer(kernel, "_B", B); 175 | compute.SetBuffer(kernel, "_C", C); 176 | 177 | uint tx, ty, tz; 178 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 179 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)cCols - 1) / tx) + 1, Mathf.FloorToInt(((int)cRows - 1) / ty) + 1, (int)tz); 180 | } 181 | 182 | protected static void OpMM(ComputeShader compute, int kernel, Signal B, Signal C) 183 | { 184 | int bRows = B.Rows, bCols = B.Columns; 185 | int cRows = C.Rows, cCols = C.Columns; 186 | 187 | if(cRows != bRows || cCols != bCols) 188 | { 189 | Debug.LogWarning("B & C does not have same dimensions."); 190 | } 191 | 192 | compute.SetInt("_BRows", bRows); compute.SetInt("_BCols", bCols); 193 | compute.SetInt("_CRows", cRows); compute.SetInt("_CCols", cCols); 194 | 195 | compute.SetBuffer(kernel, "_B", B.Buffer); 196 | compute.SetBuffer(kernel, "_C", C.Buffer); 197 | 198 | uint tx, ty, tz; 199 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 200 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)cCols - 1) / tx) + 1, Mathf.FloorToInt(((int)cRows - 1) / ty) + 1, (int)tz); 201 | } 202 | 203 | protected static void OpMMM(ComputeShader compute, int kernel, Signal A, Signal B, Signal C) 204 | { 205 | int aRows = A.Rows, aCols = A.Columns; 206 | int bRows = B.Rows, bCols = B.Columns; 207 | int cRows = C.Rows, cCols = C.Columns; 208 | 209 | if(aRows != cRows || aCols != cCols) 210 | { 211 | Debug.LogWarning("A & C does not have same dimensions."); 212 | } 213 | 214 | if(cRows != bRows || cCols != bCols) 215 | { 216 | Debug.LogWarning("B & C does not have same dimensions."); 217 | } 218 | 219 | compute.SetInt("_ARows", aRows); compute.SetInt("_ACols", aCols); 220 | compute.SetInt("_BRows", bRows); compute.SetInt("_BCols", bCols); 221 | compute.SetInt("_CRows", cRows); compute.SetInt("_CCols", cCols); 222 | 223 | compute.SetBuffer(kernel, "_A", A.Buffer); 224 | compute.SetBuffer(kernel, "_B", B.Buffer); 225 | compute.SetBuffer(kernel, "_C", C.Buffer); 226 | 227 | uint tx, ty, tz; 228 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 229 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)cCols - 1) / tx) + 1, Mathf.FloorToInt(((int)cRows - 1) / ty) + 1, (int)tz); 230 | } 231 | 232 | protected static void OpMVM(ComputeShader compute, int kernel, Signal A, Signal B, Signal C) 233 | { 234 | int aRows = A.Rows, aCols = A.Columns; 235 | int bRows = B.Rows, bCols = B.Columns; 236 | int cRows = C.Rows, cCols = C.Columns; 237 | 238 | if(aCols != bCols) 239 | { 240 | Debug.LogWarning("A & B does not have same columns."); 241 | } 242 | 243 | if(bRows != 1) 244 | { 245 | Debug.LogWarning("B rows must be 1."); 246 | } 247 | 248 | if(aRows != cRows || aCols != cCols) 249 | { 250 | Debug.LogWarning("A & C does not have same dimensions."); 251 | } 252 | 253 | compute.SetInt("_ARows", aRows); compute.SetInt("_ACols", aCols); 254 | compute.SetInt("_BRows", bRows); compute.SetInt("_BCols", bCols); 255 | compute.SetInt("_CRows", cRows); compute.SetInt("_CCols", cCols); 256 | 257 | compute.SetBuffer(kernel, "_A", A.Buffer); 258 | compute.SetBuffer(kernel, "_B", B.Buffer); 259 | compute.SetBuffer(kernel, "_C", C.Buffer); 260 | 261 | uint tx, ty, tz; 262 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 263 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)cCols - 1) / tx) + 1, Mathf.FloorToInt(((int)cRows - 1) / ty) + 1, (int)tz); 264 | } 265 | 266 | 267 | protected static void OpVM(ComputeShader compute, int kernel, Signal B, Signal C) 268 | { 269 | int bRows = B.Rows, bCols = B.Columns; 270 | int cRows = C.Rows, cCols = C.Columns; 271 | 272 | if(bRows != 1) 273 | { 274 | Debug.LogWarning("B rows must be 1. (B must be vector)"); 275 | } 276 | 277 | if(cCols != bCols) 278 | { 279 | Debug.LogWarning("B & C does not same columns."); 280 | } 281 | 282 | compute.SetInt("_BRows", bRows); compute.SetInt("_BCols", bCols); 283 | compute.SetInt("_CRows", cRows); compute.SetInt("_CCols", cCols); 284 | 285 | compute.SetBuffer(kernel, "_B", B.Buffer); 286 | compute.SetBuffer(kernel, "_C", C.Buffer); 287 | 288 | uint tx, ty, tz; 289 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 290 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)cCols - 1) / tx) + 1, Mathf.FloorToInt(((int)cRows - 1) / ty) + 1, (int)tz); 291 | } 292 | 293 | protected static void OpMV(ComputeShader compute, int kernel, Signal B, Signal C) 294 | { 295 | int bRows = B.Rows, bCols = B.Columns; 296 | int cRows = C.Rows, cCols = C.Columns; 297 | 298 | if(cRows != 1) 299 | { 300 | Debug.LogWarning("C rows must be 1."); 301 | } 302 | 303 | if(bCols != cCols) 304 | { 305 | Debug.LogWarning("B & C does not same columns."); 306 | } 307 | 308 | compute.SetInt("_BRows", bRows); compute.SetInt("_BCols", bCols); 309 | compute.SetInt("_CRows", cRows); compute.SetInt("_CCols", cCols); 310 | 311 | compute.SetBuffer(kernel, "_B", B.Buffer); 312 | compute.SetBuffer(kernel, "_C", C.Buffer); 313 | 314 | uint tx, ty, tz; 315 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 316 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)cCols - 1) / tx) + 1, Mathf.FloorToInt(((int)cRows - 1) / ty) + 1, (int)tz); 317 | } 318 | 319 | 320 | 321 | } 322 | 323 | } 324 | 325 | 326 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/MatOperations.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1408e3d488856524c89ec3ab47ff715a 3 | timeCreated: 1531387658 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Matrix.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN 6 | { 7 | 8 | [System.Serializable] 9 | public class Matrix { 10 | 11 | [SerializeField] protected float[] column; 12 | 13 | public Matrix(int count) 14 | { 15 | column = new float[count]; 16 | } 17 | 18 | public float GetValue(int index) 19 | { 20 | return column[index]; 21 | } 22 | 23 | public void SetValue(int index, float v) 24 | { 25 | column[index] = v; 26 | } 27 | 28 | } 29 | 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Matrix.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 48141f12792b9a94bafdd6116982f7a7 3 | timeCreated: 1531815771 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Network.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | using UnityEngine; 7 | 8 | namespace UNN 9 | { 10 | 11 | public abstract class Network : IDisposable 12 | { 13 | public abstract Signal Predict(ComputeShader compute, Signal input, bool train); 14 | 15 | public abstract float Loss(ComputeShader compute, Signal signal, Signal answer, bool train); 16 | 17 | public abstract float Accuracy(ComputeShader compute, Signal input, Signal answer); 18 | 19 | public abstract void Gradient(ComputeShader compute, Signal input, Signal answer); 20 | 21 | public abstract void Learn(ComputeShader compute, float rate = 0.1f); 22 | 23 | public abstract void Dispose(); 24 | 25 | } 26 | 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Network.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e451cc8eeca77f44acd5a74ad176537 3 | timeCreated: 1531128276 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Optimizers.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a02471e95fa3e054b8994d0830fc952a 3 | folderAsset: yes 4 | timeCreated: 1531794038 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Optimizers/MomentumOptimizer.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | namespace UNN 7 | { 8 | 9 | [System.Serializable] 10 | public class MomentumOptimizer : Optimizer 11 | { 12 | 13 | protected Dictionary velocity; 14 | [SerializeField] protected float momentum; 15 | 16 | public MomentumOptimizer(float m = 0.9f) : base() 17 | { 18 | momentum = m; 19 | } 20 | 21 | public override void Update(ComputeShader compute, float rate, Signal gamma, Signal dGamma) 22 | { 23 | var kernel = compute.FindKernel("Momentum"); 24 | 25 | compute.SetFloat("_LearningRate", rate); 26 | compute.SetFloat("_Momentum", momentum); 27 | 28 | Signal vGamma; 29 | if(velocity == null) velocity = new Dictionary(); 30 | if(!velocity.ContainsKey(gamma)) 31 | { 32 | vGamma = new Signal(gamma); 33 | vGamma.Init(0f); 34 | velocity.Add(gamma, vGamma); 35 | } else 36 | { 37 | vGamma = velocity[gamma]; 38 | } 39 | compute.SetBuffer(kernel, "_X", vGamma.Buffer); 40 | compute.SetBuffer(kernel, "_T", dGamma.Buffer); 41 | compute.SetBuffer(kernel, "_Y", gamma.Buffer); 42 | Dispatch(compute, kernel, gamma.Rows, gamma.Columns); 43 | } 44 | 45 | public override void Dispose() 46 | { 47 | if(velocity != null) 48 | { 49 | velocity.Values.ToList().ForEach(v => v.Dispose()); 50 | velocity.Clear(); 51 | velocity = null; 52 | } 53 | } 54 | 55 | } 56 | 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Optimizers/MomentumOptimizer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f75d6bf5c9f9e44d96cfd7e144c6cef 3 | timeCreated: 1531796511 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Optimizers/Optimizer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | using UnityEngine; 6 | 7 | namespace UNN 8 | { 9 | 10 | [System.Serializable] 11 | public abstract class Optimizer : IDisposable { 12 | 13 | public Optimizer() { } 14 | 15 | public abstract void Update(ComputeShader compute, float rate, Signal gamma, Signal dGamma); 16 | 17 | protected void Dispatch(ComputeShader compute, int kernel, int rows, int columns) 18 | { 19 | uint tx, ty, tz; 20 | compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 21 | compute.SetInt("_Rows", rows); 22 | compute.SetInt("_Cols", columns); 23 | compute.Dispatch(kernel, Mathf.FloorToInt(((int)columns - 1) / tx) + 1, Mathf.FloorToInt(((int)rows - 1) / ty) + 1, (int)tz); 24 | } 25 | 26 | public abstract void Dispose(); 27 | 28 | } 29 | 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Optimizers/Optimizer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 86585d33e06f2c34d92812a863f94643 3 | timeCreated: 1531794045 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Optimizers/SGDOptimizer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN 6 | { 7 | 8 | [System.Serializable] 9 | public class SGDOptimizer : Optimizer { 10 | 11 | public SGDOptimizer() : base() 12 | { 13 | } 14 | 15 | public override void Update(ComputeShader compute, float rate, Signal gamma, Signal dGamma) 16 | { 17 | var kernel = compute.FindKernel("SGD"); 18 | 19 | compute.SetFloat("_LearningRate", rate); 20 | compute.SetBuffer(kernel, "_X", dGamma.Buffer); 21 | compute.SetBuffer(kernel, "_Y", gamma.Buffer); 22 | Dispatch(compute, kernel, gamma.Rows, gamma.Columns); 23 | } 24 | 25 | public override void Dispose() 26 | { 27 | // do nothing 28 | } 29 | 30 | 31 | } 32 | 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Optimizers/SGDOptimizer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6be5237f484a5349bc44f48834e5015 3 | timeCreated: 1531794111 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Signal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | using UnityEngine; 5 | 6 | namespace UNN 7 | { 8 | 9 | [System.Serializable] 10 | public class Signal : IDisposable, ISerializationCallbackReceiver 11 | { 12 | 13 | public ComputeBuffer Buffer { get { return buffer; } } 14 | public int Rows { get { return rows; } } 15 | public int Columns { get { return columns; } } 16 | 17 | protected ComputeBuffer buffer; 18 | [SerializeField] protected int rows, columns; 19 | 20 | [SerializeField] protected Matrix[] data = null; 21 | 22 | public Signal(float[] v) 23 | { 24 | this.rows = 1; 25 | this.columns = v.Length; 26 | 27 | buffer = new ComputeBuffer(this.rows * this.columns, Marshal.SizeOf(typeof(float))); 28 | buffer.SetData(v); 29 | } 30 | 31 | public Signal(float[,] mat) 32 | { 33 | this.rows = mat.GetLength(0); 34 | this.columns = mat.GetLength(1); 35 | buffer = new ComputeBuffer(this.rows * this.columns, Marshal.SizeOf(typeof(float))); 36 | buffer.SetData(mat); 37 | } 38 | 39 | public Signal(int rows, int cols) 40 | { 41 | this.rows = rows; 42 | this.columns = cols; 43 | buffer = new ComputeBuffer(this.rows * this.columns, Marshal.SizeOf(typeof(float))); 44 | } 45 | 46 | public Signal(int rows, int cols, ComputeBuffer buf) 47 | { 48 | this.rows = rows; 49 | this.columns = cols; 50 | this.buffer = buf; 51 | } 52 | 53 | public Signal(Signal sig) : this(sig.rows, sig.Columns) 54 | { 55 | } 56 | 57 | public void Init(float v = 0f) 58 | { 59 | float[,] value = new float[rows, columns]; 60 | for(int y = 0; y < rows; y++) 61 | { 62 | for(int x = 0; x < columns; x++) 63 | { 64 | value[y, x] = v; 65 | } 66 | } 67 | buffer.SetData(value); 68 | } 69 | 70 | public float[,] GetData() 71 | { 72 | float[,] value = new float[rows, columns]; 73 | buffer.GetData(value); 74 | return value; 75 | } 76 | 77 | public bool IsNaN() 78 | { 79 | float[,] value = GetData(); 80 | 81 | for(int y = 0; y < rows; y++) 82 | { 83 | for(int x = 0; x < columns; x++) 84 | { 85 | float v = value[y, x]; 86 | if(float.IsNaN(v)) 87 | { 88 | return true; 89 | } 90 | } 91 | } 92 | 93 | return false; 94 | } 95 | 96 | public void Log(string header = "") 97 | { 98 | float[,] value = GetData(); 99 | 100 | var output = new string[rows + 1]; 101 | output[0] = header + (header.Length > 0 ? " " : "") + " [" + rows + ", " + columns + "]"; 102 | 103 | bool isNaN = false; 104 | for(int y = 0; y < rows; y++) 105 | { 106 | string[] row = new string[columns]; 107 | for(int x = 0; x < columns; x++) 108 | { 109 | float v = value[y, x]; 110 | isNaN |= float.IsNaN(v); 111 | row[x] = v.ToString("0.00000"); 112 | } 113 | output[y + 1] = string.Join(",", row); 114 | } 115 | 116 | if(isNaN) 117 | { 118 | Debug.LogWarning(string.Join("\n", output)); 119 | } else 120 | { 121 | Debug.Log(string.Join("\n", output)); 122 | } 123 | } 124 | 125 | public void LogMNIST(float threshold = 0.5f) 126 | { 127 | float[,] value = GetData(); 128 | 129 | var output = new string[28]; 130 | for(int y = 0; y < 28; y++) 131 | { 132 | int offset = (28 - y - 1) * 28; 133 | string[] row = new string[28]; 134 | for (int x = 0; x < 28; x++) 135 | { 136 | row[x] = (threshold > value[0, offset + x]) ? "." : " "; 137 | } 138 | output[y] = string.Join("", row); 139 | } 140 | 141 | Debug.Log(string.Join("\n", output)); 142 | } 143 | 144 | public void Dispose() 145 | { 146 | if(buffer != null) 147 | { 148 | buffer.Release(); 149 | } 150 | buffer = null; 151 | } 152 | 153 | public void OnBeforeSerialize() 154 | { 155 | if (buffer == null) return; 156 | 157 | // Debug.Log("OnBeforeSerialize " + rows + " x " + columns); 158 | 159 | float[,] m = GetData(); 160 | data = new Matrix[rows]; 161 | for(int y = 0; y < rows; y++) 162 | { 163 | var v = new Matrix(columns); 164 | for(int x = 0; x < columns; x++) 165 | { 166 | v.SetValue(x, m[y, x]); 167 | } 168 | data[y] = v; 169 | } 170 | 171 | } 172 | 173 | public void OnAfterDeserialize() 174 | { 175 | if (data == null || rows <= 0 || columns <= 0) return; 176 | 177 | var m = new float[rows, columns]; 178 | for(int y = 0; y < rows; y++) 179 | { 180 | var v = data[y]; 181 | for(int x = 0; x < columns; x++) 182 | { 183 | m[y, x] = v.GetValue(x); 184 | } 185 | } 186 | 187 | if(buffer != null) 188 | { 189 | Debug.LogWarning("buffer is not null"); 190 | buffer.Dispose(); 191 | } 192 | 193 | buffer = new ComputeBuffer(rows * columns, Marshal.SizeOf(typeof(float))); 194 | buffer.SetData(m); 195 | } 196 | 197 | } 198 | 199 | } 200 | 201 | 202 | -------------------------------------------------------------------------------- /Assets/UNN/Scripts/Signal.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c6d686a1dd441643989ab6952a06089 3 | timeCreated: 1531383597 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f87c2198c18b3c444adbf16b091c6455 3 | folderAsset: yes 4 | timeCreated: 1531128101 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Shaders/Common.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eb2a9773b4973db4abab0968b6daf02c 3 | folderAsset: yes 4 | timeCreated: 1531128114 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Shaders/Compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec9e47772ad5d3340b08ee0f46af0e25 3 | folderAsset: yes 4 | timeCreated: 1531128114 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Shaders/Compute/UNN.compute: -------------------------------------------------------------------------------- 1 |  2 | #pragma kernel CopyMM 3 | #pragma kernel AddMM 4 | #pragma kernel SubMM 5 | #pragma kernel MulMM 6 | #pragma kernel DivMM 7 | #pragma kernel SqrtMM 8 | 9 | #pragma kernel MulMMM 10 | #pragma kernel DivMMM 11 | 12 | #pragma kernel AddVM 13 | #pragma kernel SubVM 14 | #pragma kernel DivVM 15 | 16 | #pragma kernel SubMVM 17 | #pragma kernel MulMVM 18 | #pragma kernel DivMVM 19 | 20 | #pragma kernel SumMV 21 | #pragma kernel MeanMV 22 | #pragma kernel VarianceMV 23 | 24 | #pragma kernel MatMul 25 | #pragma kernel MatMulTM 26 | #pragma kernel MatMulMT 27 | 28 | #pragma kernel ReLU 29 | #pragma kernel ReLUBackward 30 | 31 | #pragma kernel Exp 32 | #pragma kernel Softmax 33 | #pragma kernel SoftmaxBackward 34 | 35 | #pragma kernel Log 36 | #pragma kernel Accuracy 37 | 38 | #pragma kernel SGD 39 | #pragma kernel Momentum 40 | 41 | #pragma kernel BNMomentum 42 | #pragma kernel BNXn 43 | #pragma kernel BNForward 44 | #pragma kernel BNDVar 45 | #pragma kernel BNDXc 46 | #pragma kernel BNDX 47 | 48 | #define BLOCK_SIZE 16 49 | #define THREAD [numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] 50 | #define THREAD_VM [numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] 51 | #define THREAD_MV [numthreads(128, 1, 1)] 52 | 53 | #define EPSILON 1e-16 54 | 55 | StructuredBuffer _A, _B; 56 | RWStructuredBuffer _C; 57 | int _ARows, _ACols, _BRows, _BCols, _CRows, _CCols; 58 | 59 | RWStructuredBuffer _X, _Y; 60 | StructuredBuffer _T; 61 | int _Rows, _Cols; 62 | 63 | int _BatchSize; 64 | float _LearningRate, _Momentum; 65 | 66 | StructuredBuffer _Gamma, _Beta; 67 | float _Sigma, _Rho, _Iota; 68 | 69 | THREAD 70 | void CopyMM( 71 | uint3 Tid : SV_DispatchThreadID, 72 | uint3 Gid : SV_GroupID, 73 | uint3 GTid : SV_GroupThreadID 74 | ) 75 | { 76 | int x = Tid.x; 77 | int y = Tid.y; 78 | if (y < _CRows && x < _CCols) 79 | { 80 | int index = y * _CCols + x; 81 | _C[index] = _B[index]; 82 | } 83 | } 84 | 85 | 86 | THREAD 87 | void SqrtMM( 88 | uint3 Tid : SV_DispatchThreadID, 89 | uint3 Gid : SV_GroupID, 90 | uint3 GTid : SV_GroupThreadID 91 | ) 92 | { 93 | int x = Tid.x; 94 | int y = Tid.y; 95 | if (y < _CRows && x < _CCols) 96 | { 97 | int index = y * _CCols + x; 98 | _C[index] = sqrt(_B[index] + EPSILON); 99 | } 100 | } 101 | 102 | 103 | THREAD 104 | void AddMM( 105 | uint3 Tid : SV_DispatchThreadID, 106 | uint3 Gid : SV_GroupID, 107 | uint3 GTid : SV_GroupThreadID 108 | ) 109 | { 110 | int x = Tid.x; 111 | int y = Tid.y; 112 | if (y < _CRows && x < _CCols) 113 | { 114 | int index = y * _CCols + x; 115 | _C[index] = _C[index] + _B[index]; 116 | } 117 | } 118 | 119 | THREAD 120 | void SubMM( 121 | uint3 Tid : SV_DispatchThreadID, 122 | uint3 Gid : SV_GroupID, 123 | uint3 GTid : SV_GroupThreadID 124 | ) 125 | { 126 | int x = Tid.x; 127 | int y = Tid.y; 128 | if (y < _CRows && x < _CCols) 129 | { 130 | int index = y * _CCols + x; 131 | _C[index] = _C[index] - _B[index]; 132 | } 133 | } 134 | 135 | THREAD 136 | void MulMM( 137 | uint3 Tid : SV_DispatchThreadID, 138 | uint3 Gid : SV_GroupID, 139 | uint3 GTid : SV_GroupThreadID 140 | ) 141 | { 142 | int x = Tid.x; 143 | int y = Tid.y; 144 | if (y < _CRows && x < _CCols) 145 | { 146 | int index = y * _CCols + x; 147 | _C[index] = _C[index] * _B[index]; 148 | } 149 | } 150 | 151 | THREAD 152 | void DivMM( 153 | uint3 Tid : SV_DispatchThreadID, 154 | uint3 Gid : SV_GroupID, 155 | uint3 GTid : SV_GroupThreadID 156 | ) 157 | { 158 | int x = Tid.x; 159 | int y = Tid.y; 160 | if (y < _CRows && x < _CCols) 161 | { 162 | int index = y * _CCols + x; 163 | _C[index] = _C[index] / _B[index]; 164 | } 165 | } 166 | 167 | THREAD 168 | void MulMMM( 169 | uint3 Tid : SV_DispatchThreadID, 170 | uint3 Gid : SV_GroupID, 171 | uint3 GTid : SV_GroupThreadID 172 | ) 173 | { 174 | int x = Tid.x; 175 | int y = Tid.y; 176 | if (y < _CRows && x < _CCols) 177 | { 178 | int index = y * _CCols + x; 179 | _C[index] = _A[index] * _B[index]; 180 | } 181 | } 182 | 183 | THREAD 184 | void DivMMM( 185 | uint3 Tid : SV_DispatchThreadID, 186 | uint3 Gid : SV_GroupID, 187 | uint3 GTid : SV_GroupThreadID 188 | ) 189 | { 190 | int x = Tid.x; 191 | int y = Tid.y; 192 | if (y < _CRows && x < _CCols) 193 | { 194 | int index = y * _CCols + x; 195 | _C[index] = _A[index] / _B[index]; 196 | } 197 | } 198 | 199 | 200 | THREAD_VM 201 | void AddVM( 202 | uint3 Tid : SV_DispatchThreadID, 203 | uint3 Gid : SV_GroupID, 204 | uint3 GTid : SV_GroupThreadID 205 | ) 206 | { 207 | int x = Tid.x; 208 | int y = Tid.y; 209 | if (y < _CRows && x < _CCols) 210 | { 211 | int index = y * _CCols + x; 212 | _C[index] = _C[index] + _B[x]; 213 | } 214 | } 215 | 216 | THREAD_VM 217 | void SubVM( 218 | uint3 Tid : SV_DispatchThreadID, 219 | uint3 Gid : SV_GroupID, 220 | uint3 GTid : SV_GroupThreadID 221 | ) 222 | { 223 | int x = Tid.x; 224 | int y = Tid.y; 225 | if (y < _CRows && x < _CCols) 226 | { 227 | int index = y * _CCols + x; 228 | _C[index] = _C[index] - _B[x]; 229 | } 230 | } 231 | 232 | THREAD_VM 233 | void DivVM( 234 | uint3 Tid : SV_DispatchThreadID, 235 | uint3 Gid : SV_GroupID, 236 | uint3 GTid : SV_GroupThreadID 237 | ) 238 | { 239 | int x = Tid.x; 240 | int y = Tid.y; 241 | if (y < _CRows && x < _CCols) 242 | { 243 | int index = y * _CCols + x; 244 | _C[index] = _C[index] / _B[x]; 245 | } 246 | } 247 | 248 | 249 | THREAD 250 | void SubMVM( 251 | uint3 Tid : SV_DispatchThreadID, 252 | uint3 Gid : SV_GroupID, 253 | uint3 GTid : SV_GroupThreadID 254 | ) 255 | { 256 | int x = Tid.x; 257 | int y = Tid.y; 258 | if (y < _CRows && x < _CCols) 259 | { 260 | int index = y * _CCols + x; 261 | _C[index] = _A[index] - _B[x]; 262 | } 263 | } 264 | 265 | THREAD 266 | void MulMVM( 267 | uint3 Tid : SV_DispatchThreadID, 268 | uint3 Gid : SV_GroupID, 269 | uint3 GTid : SV_GroupThreadID 270 | ) 271 | { 272 | int x = Tid.x; 273 | int y = Tid.y; 274 | if (y < _CRows && x < _CCols) 275 | { 276 | int index = y * _CCols + x; 277 | _C[index] = _A[index] * _B[x]; 278 | } 279 | } 280 | 281 | 282 | THREAD 283 | void DivMVM( 284 | uint3 Tid : SV_DispatchThreadID, 285 | uint3 Gid : SV_GroupID, 286 | uint3 GTid : SV_GroupThreadID 287 | ) 288 | { 289 | int x = Tid.x; 290 | int y = Tid.y; 291 | if (y < _CRows && x < _CCols) 292 | { 293 | int index = y * _CCols + x; 294 | _C[index] = _A[index] / _B[x]; 295 | } 296 | } 297 | 298 | 299 | THREAD_MV 300 | void SumMV( 301 | uint3 Tid : SV_DispatchThreadID, 302 | uint3 Gid : SV_GroupID, 303 | uint3 GTid : SV_GroupThreadID 304 | ) 305 | { 306 | int x = Tid.x; 307 | int y = Tid.y; 308 | if (x >= _CCols || y >= _CRows) 309 | return; 310 | 311 | float acc = 0; 312 | for (y = 0; y < _BRows; y++) 313 | { 314 | acc += _B[y * _CCols + x]; 315 | } 316 | _C[x] = acc; 317 | } 318 | 319 | 320 | THREAD_MV 321 | void MeanMV( 322 | uint3 Tid : SV_DispatchThreadID, 323 | uint3 Gid : SV_GroupID, 324 | uint3 GTid : SV_GroupThreadID 325 | ) 326 | { 327 | int x = Tid.x; 328 | int y = Tid.y; 329 | if (x >= _CCols || y >= _CRows) 330 | return; 331 | 332 | float acc = 0; 333 | for (y = 0; y < _BRows; y++) 334 | { 335 | acc += _B[y * _BCols + x]; 336 | } 337 | _C[x] = acc / _BRows; 338 | } 339 | 340 | 341 | THREAD_MV 342 | void VarianceMV( 343 | uint3 Tid : SV_DispatchThreadID, 344 | uint3 Gid : SV_GroupID, 345 | uint3 GTid : SV_GroupThreadID 346 | ) 347 | { 348 | int x = Tid.x; 349 | int y = Tid.y; 350 | if (x >= _CCols || y >= _CRows) 351 | return; 352 | 353 | float acc = 0; 354 | for (y = 0; y < _BRows; y++) 355 | { 356 | float v = _B[y * _BCols + x]; 357 | acc += v * v; 358 | } 359 | _C[x] = acc / _BRows; 360 | } 361 | 362 | 363 | groupshared float As[BLOCK_SIZE][BLOCK_SIZE]; 364 | groupshared float Bs[BLOCK_SIZE][BLOCK_SIZE]; 365 | 366 | THREAD 367 | void MatMul( 368 | uint3 Tid : SV_DispatchThreadID, 369 | uint3 Gid : SV_GroupID, 370 | uint3 GTid : SV_GroupThreadID 371 | ) 372 | { 373 | int tx = GTid.x; 374 | int ty = GTid.y; 375 | int bx = Gid.x; 376 | int by = Gid.y; 377 | 378 | int x = bx * BLOCK_SIZE + tx; 379 | int y = by * BLOCK_SIZE + ty; 380 | 381 | float acc = 0; 382 | 383 | int n = (uint(_ACols - 1) / BLOCK_SIZE) + 1; 384 | for (int m = 0; m < n; m++) 385 | { 386 | int ox = (m * BLOCK_SIZE + tx); 387 | if (ox < _ACols && y < _ARows) 388 | { 389 | As[ty][tx] = _A[y * _ACols + ox]; 390 | } 391 | else 392 | { 393 | As[ty][tx] = 0; 394 | } 395 | 396 | int oy = (m * BLOCK_SIZE + ty); 397 | if (oy < _BRows && x < _BCols) 398 | { 399 | Bs[ty][tx] = _B[oy * _BCols + x]; 400 | } 401 | else 402 | { 403 | Bs[ty][tx] = 0; 404 | } 405 | 406 | GroupMemoryBarrierWithGroupSync(); 407 | 408 | for (int k = 0; k < BLOCK_SIZE; k++) 409 | { 410 | acc += As[ty][k] * Bs[k][tx]; 411 | } 412 | 413 | GroupMemoryBarrierWithGroupSync(); 414 | } 415 | 416 | if (y < _CRows && x < _CCols) 417 | { 418 | _C[y * _CCols + x] = acc; 419 | } 420 | } 421 | 422 | THREAD 423 | void MatMulTM( 424 | uint3 Tid : SV_DispatchThreadID, 425 | uint3 Gid : SV_GroupID, 426 | uint3 GTid : SV_GroupThreadID 427 | ) 428 | { 429 | int tx = GTid.x; 430 | int ty = GTid.y; 431 | int bx = Gid.x; 432 | int by = Gid.y; 433 | 434 | int x = bx * BLOCK_SIZE + tx; 435 | int y = by * BLOCK_SIZE + ty; 436 | 437 | float acc = 0; 438 | 439 | int n = (uint(_ARows - 1) / BLOCK_SIZE) + 1; 440 | for (int m = 0; m < n; m++) 441 | { 442 | int ox = (m * BLOCK_SIZE + tx); 443 | if (y < _ACols && ox < _ARows) 444 | { 445 | As[ty][tx] = _A[ox * _ACols + y]; 446 | } 447 | else 448 | { 449 | As[ty][tx] = 0; 450 | } 451 | 452 | int oy = (m * BLOCK_SIZE + ty); 453 | if (oy < _BRows && x < _BCols) 454 | { 455 | Bs[ty][tx] = _B[oy * _BCols + x]; 456 | } 457 | else 458 | { 459 | Bs[ty][tx] = 0; 460 | } 461 | 462 | GroupMemoryBarrierWithGroupSync(); 463 | 464 | for (int k = 0; k < BLOCK_SIZE; k++) 465 | { 466 | acc += As[ty][k] * Bs[k][tx]; 467 | } 468 | 469 | GroupMemoryBarrierWithGroupSync(); 470 | } 471 | 472 | if (y < _CRows && x < _CCols) 473 | { 474 | _C[y * _CCols + x] = acc; 475 | } 476 | } 477 | 478 | THREAD 479 | void MatMulMT( 480 | uint3 Tid : SV_DispatchThreadID, 481 | uint3 Gid : SV_GroupID, 482 | uint3 GTid : SV_GroupThreadID 483 | ) 484 | { 485 | int tx = GTid.x; 486 | int ty = GTid.y; 487 | int bx = Gid.x; 488 | int by = Gid.y; 489 | 490 | int x = bx * BLOCK_SIZE + tx; 491 | int y = by * BLOCK_SIZE + ty; 492 | 493 | float acc = 0; 494 | 495 | int n = (uint(_ACols - 1) / BLOCK_SIZE) + 1; 496 | for (int m = 0; m < n; m++) 497 | { 498 | int ox = (m * BLOCK_SIZE + tx); 499 | if (ox < _ACols && y < _ARows) 500 | { 501 | As[ty][tx] = _A[y * _ACols + ox]; 502 | } 503 | else 504 | { 505 | As[ty][tx] = 0; 506 | } 507 | 508 | int oy = (m * BLOCK_SIZE + ty); 509 | if (oy < _BCols && x < _BRows) 510 | { 511 | Bs[ty][tx] = _B[x * _BCols + oy]; 512 | } 513 | else 514 | { 515 | Bs[ty][tx] = 0; 516 | } 517 | 518 | GroupMemoryBarrierWithGroupSync(); 519 | 520 | for (int k = 0; k < BLOCK_SIZE; k++) 521 | { 522 | acc += As[ty][k] * Bs[k][tx]; 523 | } 524 | 525 | GroupMemoryBarrierWithGroupSync(); 526 | } 527 | 528 | if (y < _CRows && x < _CCols) 529 | { 530 | _C[y * _CCols + x] = acc; 531 | } 532 | } 533 | 534 | 535 | THREAD 536 | void ReLU( 537 | uint3 Tid : SV_DispatchThreadID, 538 | uint3 Gid : SV_GroupID, 539 | uint3 GTid : SV_GroupThreadID 540 | ) 541 | { 542 | int tx = GTid.x; 543 | int ty = GTid.y; 544 | int bx = Gid.x; 545 | int by = Gid.y; 546 | 547 | int x = bx * BLOCK_SIZE + tx; 548 | int y = by * BLOCK_SIZE + ty; 549 | 550 | if (y < _Rows && x < _Cols) 551 | { 552 | int idx = y * _Cols + x; 553 | _Y[idx] = max(0, _X[idx]); 554 | } 555 | } 556 | 557 | THREAD 558 | void ReLUBackward( 559 | uint3 Tid : SV_DispatchThreadID, 560 | uint3 Gid : SV_GroupID, 561 | uint3 GTid : SV_GroupThreadID 562 | ) 563 | { 564 | int tx = GTid.x; 565 | int ty = GTid.y; 566 | int bx = Gid.x; 567 | int by = Gid.y; 568 | 569 | int x = bx * BLOCK_SIZE + tx; 570 | int y = by * BLOCK_SIZE + ty; 571 | 572 | if (y < _Rows && x < _Cols) 573 | { 574 | int idx = y * _Cols + x; 575 | _Y[idx] = _X[idx] * step(EPSILON, _T[idx]); 576 | } 577 | } 578 | 579 | 580 | 581 | THREAD 582 | void Exp( 583 | uint3 Tid : SV_DispatchThreadID, 584 | uint3 Gid : SV_GroupID, 585 | uint3 GTid : SV_GroupThreadID 586 | ) 587 | { 588 | int tx = GTid.x; 589 | int ty = GTid.y; 590 | int bx = Gid.x; 591 | int by = Gid.y; 592 | 593 | int x = bx * BLOCK_SIZE + tx; 594 | int y = by * BLOCK_SIZE + ty; 595 | 596 | if (y < _Rows && x < _Cols) 597 | { 598 | float m = 0; 599 | for (int i = 0; i < _Cols; i++) 600 | { 601 | m = max(m, _X[y * _Cols + i]); 602 | } 603 | 604 | _Y[y * _Cols + x] = exp(_X[y * _Cols + x] - m); 605 | } 606 | } 607 | 608 | 609 | THREAD 610 | void Softmax( 611 | uint3 Tid : SV_DispatchThreadID, 612 | uint3 Gid : SV_GroupID, 613 | uint3 GTid : SV_GroupThreadID 614 | ) 615 | { 616 | // CAUTION: called after Exp kernel 617 | 618 | int tx = GTid.x; 619 | int ty = GTid.y; 620 | int bx = Gid.x; 621 | int by = Gid.y; 622 | 623 | int x = bx * BLOCK_SIZE + tx; 624 | int y = by * BLOCK_SIZE + ty; 625 | 626 | if (y < _Rows && x < _Cols) 627 | { 628 | float sum = 0; 629 | for (int i = 0; i < _Cols; i++) 630 | { 631 | sum += _X[y * _Cols + i]; 632 | } 633 | _Y[y * _Cols + x] = _X[y * _Cols + x] / sum; 634 | } 635 | } 636 | 637 | 638 | THREAD 639 | void SoftmaxBackward( 640 | uint3 Tid : SV_DispatchThreadID, 641 | uint3 Gid : SV_GroupID, 642 | uint3 GTid : SV_GroupThreadID 643 | ) 644 | { 645 | int tx = GTid.x; 646 | int ty = GTid.y; 647 | int bx = Gid.x; 648 | int by = Gid.y; 649 | 650 | int x = bx * BLOCK_SIZE + tx; 651 | int y = by * BLOCK_SIZE + ty; 652 | 653 | if (y < _Rows && x < _Cols) 654 | { 655 | int idx = y * _Cols + x; 656 | _Y[idx] = (_X[idx] - _T[idx]) / _BatchSize; 657 | } 658 | } 659 | 660 | 661 | THREAD 662 | void Log( 663 | uint3 Tid : SV_DispatchThreadID, 664 | uint3 Gid : SV_GroupID, 665 | uint3 GTid : SV_GroupThreadID 666 | ) 667 | { 668 | int tx = GTid.x; 669 | int ty = GTid.y; 670 | int bx = Gid.x; 671 | int by = Gid.y; 672 | 673 | int x = bx * BLOCK_SIZE + tx; 674 | int y = by * BLOCK_SIZE + ty; 675 | 676 | if (y < _Rows && x < _Cols) 677 | { 678 | int idx = y * _Cols + x; 679 | _Y[idx] = log(_X[idx] + 1e-7) * _T[idx]; 680 | } 681 | } 682 | 683 | 684 | THREAD_VM 685 | void Accuracy( 686 | uint3 Tid : SV_DispatchThreadID, 687 | uint3 Gid : SV_GroupID, 688 | uint3 GTid : SV_GroupThreadID 689 | ) 690 | { 691 | int y = Tid.x; 692 | if (y >= _Rows) 693 | return; 694 | 695 | int ix = 0; 696 | float mx = 0; 697 | 698 | int offset = y * _Cols; 699 | 700 | int x = 0; 701 | for (x = 0; x < _Cols; x++) 702 | { 703 | float vx = _X[offset + x]; 704 | if (vx > mx) 705 | { 706 | ix = x; 707 | mx = vx; 708 | } 709 | } 710 | 711 | int it = 0; 712 | float mt = 0; 713 | for (x = 0; x < _Cols; x++) 714 | { 715 | float vt = _T[offset + x]; 716 | if (vt > mt) 717 | { 718 | it = x; 719 | mt = vt; 720 | } 721 | } 722 | 723 | _Y[y] = (ix == it); 724 | } 725 | 726 | 727 | 728 | 729 | 730 | THREAD 731 | void SGD( 732 | uint3 Tid : SV_DispatchThreadID, 733 | uint3 Gid : SV_GroupID, 734 | uint3 GTid : SV_GroupThreadID 735 | ) 736 | { 737 | int x = Tid.x; 738 | int y = Tid.y; 739 | if (y < _Rows && x < _Cols) 740 | { 741 | int idx = y * _Cols + x; 742 | _Y[idx] = _Y[idx] - _LearningRate * _X[idx]; 743 | } 744 | } 745 | 746 | THREAD 747 | void Momentum( 748 | uint3 Tid : SV_DispatchThreadID, 749 | uint3 Gid : SV_GroupID, 750 | uint3 GTid : SV_GroupThreadID 751 | ) 752 | { 753 | int x = Tid.x; 754 | int y = Tid.y; 755 | if (y < _Rows && x < _Cols) 756 | { 757 | int idx = y * _Cols + x; 758 | _X[idx] = _Momentum * _X[idx] - _LearningRate * _T[idx]; 759 | _Y[idx] = _Y[idx] + _X[idx]; 760 | } 761 | } 762 | 763 | THREAD 764 | void BNMomentum( 765 | uint3 Tid : SV_DispatchThreadID, 766 | uint3 Gid : SV_GroupID, 767 | uint3 GTid : SV_GroupThreadID 768 | ) 769 | { 770 | int x = Tid.x; 771 | int y = Tid.y; 772 | if (y < _Rows && x < _Cols) 773 | { 774 | int idx = y * _Cols + x; 775 | _Y[idx] = _Momentum * _Y[idx] + (1.0 - _Momentum) * _X[idx]; 776 | } 777 | } 778 | 779 | THREAD 780 | void BNXn( 781 | uint3 Tid : SV_DispatchThreadID, 782 | uint3 Gid : SV_GroupID, 783 | uint3 GTid : SV_GroupThreadID 784 | ) 785 | { 786 | int x = Tid.x; 787 | int y = Tid.y; 788 | if (y < _Rows && x < _Cols) 789 | { 790 | int idx = y * _Cols + x; 791 | _Y[idx] = _X[idx] / sqrt(_T[x] + EPSILON); 792 | } 793 | } 794 | 795 | 796 | THREAD 797 | void BNForward( 798 | uint3 Tid : SV_DispatchThreadID, 799 | uint3 Gid : SV_GroupID, 800 | uint3 GTid : SV_GroupThreadID 801 | ) 802 | { 803 | int x = Tid.x; 804 | int y = Tid.y; 805 | if (y < _Rows && x < _Cols) 806 | { 807 | int idx = y * _Cols + x; 808 | _Y[idx] = _Gamma[x] * _X[idx] + _Beta[x]; 809 | } 810 | } 811 | 812 | THREAD 813 | void BNDVar( 814 | uint3 Tid : SV_DispatchThreadID, 815 | uint3 Gid : SV_GroupID, 816 | uint3 GTid : SV_GroupThreadID 817 | ) 818 | { 819 | int x = Tid.x; 820 | int y = Tid.y; 821 | if (y < _Rows && x < _Cols) 822 | { 823 | int idx = y * _Cols + x; 824 | _Y[idx] = -0.5 * _X[idx] / _T[idx]; 825 | } 826 | } 827 | 828 | THREAD 829 | void BNDXc( 830 | uint3 Tid : SV_DispatchThreadID, 831 | uint3 Gid : SV_GroupID, 832 | uint3 GTid : SV_GroupThreadID 833 | ) 834 | { 835 | int x = Tid.x; 836 | int y = Tid.y; 837 | if (y < _Rows && x < _Cols) 838 | { 839 | int idx = y * _Cols + x; 840 | _Y[idx] = _Y[idx] + _Sigma * _X[idx] * _T[x]; 841 | } 842 | } 843 | 844 | THREAD 845 | void BNDX( 846 | uint3 Tid : SV_DispatchThreadID, 847 | uint3 Gid : SV_GroupID, 848 | uint3 GTid : SV_GroupThreadID 849 | ) 850 | { 851 | int x = Tid.x; 852 | int y = Tid.y; 853 | if (y < _Rows && x < _Cols) 854 | { 855 | int idx = y * _Cols + x; 856 | _Y[idx] = _X[idx] - _T[x] * _Sigma; 857 | } 858 | } -------------------------------------------------------------------------------- /Assets/UNN/Shaders/Compute/UNN.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bef4499de4c55f4409fb8b3587582e64 3 | timeCreated: 1531128513 4 | licenseType: Pro 5 | ComputeShaderImporter: 6 | externalObjects: {} 7 | currentAPIMask: 4 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36dcc877ff0c6cb4da3b00a75fc9f598 3 | folderAsset: yes 4 | timeCreated: 1531375116 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5eaf81e702eab99448155f56c448ab8a 3 | folderAsset: yes 4 | timeCreated: 1531375121 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/MNISTBatchNormalizationTest.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a97e8b3be37d2194c85e729f920e42d8 3 | timeCreated: 1531375147 4 | licenseType: Pro 5 | DefaultImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/MNISTTest.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca61b556f67134b4f9d63c6fdad50e38 3 | timeCreated: 1531375147 4 | licenseType: Pro 5 | DefaultImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e4c4b4ec2e766df4f86dbb036d1d6c59 3 | folderAsset: yes 4 | timeCreated: 1532585098 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Materials/DigitProb.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: DigitProb 10 | m_Shader: {fileID: 4800000, guid: 4f0a9ae43c026c24481145a06efe61bf, type: 3} 11 | m_ShaderKeywords: 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | m_Floats: 58 | - _BumpScale: 1 59 | - _ColorMask: 15 60 | - _Cutoff: 0.5 61 | - _DetailNormalMapScale: 1 62 | - _DstBlend: 0 63 | - _GlossMapScale: 1 64 | - _Glossiness: 0.5 65 | - _GlossyReflections: 1 66 | - _Metallic: 0 67 | - _Mode: 0 68 | - _OcclusionStrength: 1 69 | - _Parallax: 0.02 70 | - _SmoothnessTextureChannel: 0 71 | - _SpecularHighlights: 1 72 | - _SrcBlend: 1 73 | - _Stencil: 0 74 | - _StencilComp: 8 75 | - _StencilOp: 0 76 | - _StencilReadMask: 255 77 | - _StencilWriteMask: 255 78 | - _T: 1 79 | - _UVSec: 0 80 | - _UseUIAlphaClip: 0 81 | - _ZWrite: 1 82 | m_Colors: 83 | - _Color: {r: 0, g: 0.6275859, b: 1, a: 1} 84 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 85 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Materials/DigitProb.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 73e9d0532fbbdb5448cd7c49a1501a7a 3 | timeCreated: 1532585210 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | externalObjects: {} 7 | mainObjectFileID: 2100000 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Materials/MNISTDraw.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: MNISTDraw 10 | m_Shader: {fileID: 4800000, guid: d2095a3791686a045bbac6b9d0de6533, type: 3} 11 | m_ShaderKeywords: 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _Input: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MainTex: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _MetallicGlossMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _OcclusionMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | - _ParallaxMap: 58 | m_Texture: {fileID: 0} 59 | m_Scale: {x: 1, y: 1} 60 | m_Offset: {x: 0, y: 0} 61 | - _Source: 62 | m_Texture: {fileID: 0} 63 | m_Scale: {x: 1, y: 1} 64 | m_Offset: {x: 0, y: 0} 65 | m_Floats: 66 | - _Alpha: 0.8 67 | - _BumpScale: 1 68 | - _Cutoff: 0.5 69 | - _DetailNormalMapScale: 1 70 | - _DstBlend: 0 71 | - _GlossMapScale: 1 72 | - _Glossiness: 0.5 73 | - _GlossyReflections: 1 74 | - _Metallic: 0 75 | - _Mode: 0 76 | - _OcclusionStrength: 1 77 | - _Parallax: 0.02 78 | - _Size: 0.0593 79 | - _SmoothnessTextureChannel: 0 80 | - _SpecularHighlights: 1 81 | - _SrcBlend: 1 82 | - _UVSec: 0 83 | - _ZWrite: 1 84 | m_Colors: 85 | - _Color: {r: 1, g: 1, b: 1, a: 1} 86 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 87 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Materials/MNISTDraw.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7d12f7fa8aa2c664b8839160cae972fc 3 | timeCreated: 1531645863 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | externalObjects: {} 7 | mainObjectFileID: 2100000 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Materials/MNISTInput.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: MNISTInput 10 | m_Shader: {fileID: 4800000, guid: 794a979892f733943aa58ff0da0f6416, type: 3} 11 | m_ShaderKeywords: 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _Input: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MainTex: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _MetallicGlossMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _OcclusionMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | - _ParallaxMap: 58 | m_Texture: {fileID: 0} 59 | m_Scale: {x: 1, y: 1} 60 | m_Offset: {x: 0, y: 0} 61 | - _Source: 62 | m_Texture: {fileID: 0} 63 | m_Scale: {x: 1, y: 1} 64 | m_Offset: {x: 0, y: 0} 65 | m_Floats: 66 | - _Alpha: 0.8 67 | - _BumpScale: 1 68 | - _Cutoff: 0.5 69 | - _DetailNormalMapScale: 1 70 | - _DstBlend: 0 71 | - _GlossMapScale: 1 72 | - _Glossiness: 0.5 73 | - _GlossyReflections: 1 74 | - _Metallic: 0 75 | - _Mode: 0 76 | - _OcclusionStrength: 1 77 | - _Parallax: 0.02 78 | - _Size: 0.0593 79 | - _SmoothnessTextureChannel: 0 80 | - _SpecularHighlights: 1 81 | - _SrcBlend: 1 82 | - _UVSec: 0 83 | - _ZWrite: 1 84 | m_Colors: 85 | - _Color: {r: 1, g: 1, b: 1, a: 1} 86 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 87 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Materials/MNISTInput.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b98d87dc367de34bad6665bd408b2db 3 | timeCreated: 1531645863 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | externalObjects: {} 7 | mainObjectFileID: 2100000 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 303fe3a0d8824214b9181c6975471e6d 3 | folderAsset: yes 4 | timeCreated: 1532585071 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/Digit.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | using UnityEngine; 6 | 7 | namespace UNN.Test 8 | { 9 | 10 | public class Digit { 11 | 12 | public float[] Pixels { get { return pixels; } } 13 | public int Label { get { return label; } } 14 | 15 | 16 | protected float[] pixels; 17 | protected int label; 18 | 19 | public Digit(float[] pixels, int label) 20 | { 21 | this.pixels = pixels; 22 | this.label = label; 23 | } 24 | 25 | public float[] GetOneHotLabel() 26 | { 27 | const int n = 10; 28 | var labels = new float[n]; 29 | for(int i = 0; i < n; i++) 30 | { 31 | labels[i] = 0f; 32 | } 33 | labels[label] = 1f; 34 | return labels; 35 | } 36 | 37 | public Texture2D ToTexture(int rows, int cols) 38 | { 39 | var tex = new Texture2D(rows, cols); 40 | for(int y = 0; y < rows; y++) 41 | { 42 | for(int x = 0; x < cols; x++) 43 | { 44 | var v = pixels[y * cols + x]; 45 | tex.SetPixel(x, y, Color.white * v); 46 | } 47 | } 48 | tex.Apply(); 49 | return tex; 50 | } 51 | 52 | } 53 | 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/Digit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 11c54dbd5617fab49a460585b9557bea 3 | timeCreated: 1531377846 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/DigitDataset.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | using UnityEngine; 6 | using Random = UnityEngine.Random; 7 | 8 | namespace UNN.Test 9 | { 10 | 11 | public class DigitDataset { 12 | 13 | public Digit[] Digits { get { return digits; } } 14 | public int Count { get { return digits.Length; } } 15 | public int Rows { get { return rows; } } 16 | public int Columns { get { return columns; } } 17 | 18 | protected Digit[] digits; 19 | protected int rows, columns; 20 | 21 | public DigitDataset(Digit[] digits, int rows, int columns) 22 | { 23 | this.digits = digits; 24 | this.rows = rows; 25 | this.columns = columns; 26 | } 27 | 28 | public void GetAllSignals(out Signal input, out Signal answer) 29 | { 30 | GetSignals(digits.ToList(), out input, out answer); 31 | } 32 | 33 | public void GetSubSignals(int batchSize, out Signal input, out Signal answer) 34 | { 35 | var indices = Enumerable.Range(0, digits.Length).ToList(); 36 | var source = new List(); 37 | 38 | for(int iter = 0; iter < batchSize; iter++) 39 | { 40 | int idx = Random.Range(0, indices.Count); 41 | int i = indices[idx]; 42 | indices.RemoveAt(idx); 43 | 44 | var digit = digits[i]; 45 | source.Add(digit); 46 | } 47 | 48 | GetSignals(source, out input, out answer); 49 | } 50 | 51 | public void GetSignals(List source, out Signal input, out Signal answer) 52 | { 53 | int inputSize = rows * columns; 54 | const int outputSize = 10; 55 | 56 | float[,] pixels = new float[source.Count, inputSize]; 57 | float[,] labels = new float[source.Count, outputSize]; 58 | 59 | for(int y = 0; y < source.Count; y++) 60 | { 61 | var digit = source[y]; 62 | for(int x = 0; x < inputSize; x++) 63 | { 64 | pixels[y, x] = digit.Pixels[x]; 65 | } 66 | 67 | var onehot = digit.GetOneHotLabel(); 68 | for(int x = 0; x < outputSize; x++) 69 | { 70 | labels[y, x] = onehot[x]; 71 | } 72 | } 73 | 74 | input = new Signal(pixels); 75 | answer = new Signal(labels); 76 | } 77 | 78 | } 79 | 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/DigitDataset.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0b9d6150a5a70b4298b43c2911057de 3 | timeCreated: 1531378953 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/DigitProb.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | using UnityEngine; 5 | using UnityEngine.UI; 6 | 7 | namespace UNN.Test 8 | { 9 | 10 | [RequireComponent (typeof(RawImage))] 11 | public class DigitProb : MonoBehaviour { 12 | 13 | [SerializeField] protected Color color; 14 | [SerializeField, Range(0f, 1f)] protected float t = 1f; 15 | protected Material material; 16 | 17 | protected Coroutine co; 18 | 19 | protected void Start () { 20 | var img = GetComponent(); 21 | material = new Material(img.material); // clone 22 | img.material = material; 23 | } 24 | 25 | protected void Update () { 26 | material.SetFloat("_T", t); 27 | } 28 | 29 | public void SetProbability(float v) 30 | { 31 | v = Mathf.Clamp01(v); 32 | 33 | if(co != null) 34 | { 35 | StopCoroutine(co); 36 | } 37 | StartCoroutine(IAnimate(v, 0.25f)); 38 | } 39 | 40 | protected IEnumerator IAnimate(float v, float duration) 41 | { 42 | yield return 0; 43 | 44 | var from = t; 45 | 46 | var time = 0f; 47 | while(time < duration) 48 | { 49 | yield return 0; 50 | time += Time.deltaTime; 51 | 52 | var k = time / duration; 53 | t = Mathf.Lerp(from, v, k * (2f - k)); // easing with quad out 54 | } 55 | 56 | t = v; 57 | } 58 | 59 | protected void OnDestroy() 60 | { 61 | Destroy(material); 62 | } 63 | 64 | } 65 | 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/DigitProb.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f932bd662aedf4b47ba3ff83fab1f3cc 3 | timeCreated: 1532585157 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/MNISTBatchNormalizationNetwork.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UNN.Test 6 | { 7 | 8 | [System.Serializable] 9 | public class MNISTBatchNormalizationNetwork : Network 10 | { 11 | 12 | [SerializeField] protected int inputSize, hiddenSize, outputSize; 13 | 14 | [SerializeField] protected AffineLayer affine1; 15 | [SerializeField] protected BatchNormalizationLayer bn1; 16 | [SerializeField] protected ReLULayer relu1; 17 | 18 | [SerializeField] protected AffineLayer affine2; 19 | [SerializeField] protected BatchNormalizationLayer bn2; 20 | [SerializeField] protected ReLULayer relu2; 21 | 22 | [SerializeField] protected AffineLayer affine3; 23 | [SerializeField] protected SoftmaxLayer softmax; 24 | 25 | [SerializeField] protected MomentumOptimizer optimizer; 26 | 27 | public MNISTBatchNormalizationNetwork(int inputSize, int hiddenSize, int outputSize) : base() 28 | { 29 | this.inputSize = inputSize; 30 | this.hiddenSize = hiddenSize; 31 | this.outputSize = outputSize; 32 | 33 | affine1 = new AffineLayer(inputSize, hiddenSize, Mathf.Sqrt(2.0f / inputSize)); 34 | bn1 = new BatchNormalizationLayer(hiddenSize, hiddenSize); 35 | relu1 = new ReLULayer(); 36 | 37 | affine2 = new AffineLayer(hiddenSize, hiddenSize, Mathf.Sqrt(2.0f / hiddenSize)); 38 | bn2 = new BatchNormalizationLayer(hiddenSize, hiddenSize); 39 | relu2 = new ReLULayer(); 40 | 41 | affine3 = new AffineLayer(hiddenSize, outputSize, Mathf.Sqrt(2.0f / hiddenSize)); 42 | softmax = new SoftmaxLayer(); 43 | 44 | optimizer = new MomentumOptimizer(0.9f); 45 | } 46 | 47 | public override float Accuracy(ComputeShader compute, Signal input, Signal answer) 48 | { 49 | var output = Predict(compute, input, false); 50 | float acc = UNN.Accuracy.Calculate(compute, input, output, answer); 51 | output.Dispose(); 52 | return acc; 53 | } 54 | 55 | public override void Gradient(ComputeShader compute, Signal input, Signal answer) 56 | { 57 | Loss(compute, input, answer, true); 58 | 59 | var layers = new List() { 60 | affine1, bn1, relu1, 61 | affine2, bn2, relu2, 62 | affine3, 63 | softmax, 64 | }; 65 | layers.Reverse(); 66 | 67 | var signal = answer; 68 | layers.ForEach(layer => 69 | { 70 | var tmp = signal; 71 | signal = layer.Backward(compute, tmp); 72 | tmp.Dispose(); 73 | // if(signal.IsNaN()) signal.Log(layer.GetType().ToString()); 74 | }); 75 | signal.Dispose(); 76 | } 77 | 78 | public override void Learn(ComputeShader compute, float rate = 0.1f) 79 | { 80 | var layers = new List() { 81 | affine1, bn1, 82 | affine2, bn2, 83 | affine3, 84 | }; 85 | layers.ForEach(trLayer => trLayer.Learn(optimizer, compute, rate)); 86 | } 87 | 88 | public override float Loss(ComputeShader compute, Signal signal, Signal answer, bool train) 89 | { 90 | var predictSig = Predict(compute, signal, train); 91 | 92 | var softmaxSig = softmax.Forward(compute, predictSig, train); 93 | predictSig.Dispose(); 94 | 95 | return CrossEntropyError.Loss(compute, softmaxSig, answer); 96 | } 97 | 98 | public override Signal Predict(ComputeShader compute, Signal input, bool train) 99 | { 100 | var layers = new List() { 101 | affine1, bn1, relu1, 102 | affine2, bn2, relu2, 103 | affine3, 104 | }; 105 | 106 | layers.ForEach(layer => 107 | { 108 | // input.Log(layer.GetType().ToString()); 109 | var tmp = input; 110 | input = layer.Forward(compute, tmp, train); 111 | tmp.Dispose(); 112 | }); 113 | 114 | return input; 115 | } 116 | 117 | public override void Dispose() 118 | { 119 | affine1.Dispose(); 120 | bn1.Dispose(); 121 | relu1.Dispose(); 122 | 123 | affine2.Dispose(); 124 | bn2.Dispose(); 125 | relu2.Dispose(); 126 | 127 | affine3.Dispose(); 128 | softmax.Dispose(); 129 | 130 | optimizer.Dispose(); 131 | } 132 | 133 | } 134 | 135 | } 136 | 137 | 138 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/MNISTBatchNormalizationNetwork.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 96351b5e38754fe41947f852ee23a644 3 | timeCreated: 1532055458 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/MNISTBatchNormalizationTest.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | using UnityEngine; 6 | 7 | namespace UNN.Test 8 | { 9 | 10 | public class MNISTBatchNormalizationTest : MNISTTest { 11 | 12 | protected override void SetupNetwork() 13 | { 14 | var inputSize = trainDataset.Rows * trainDataset.Columns; 15 | 16 | path = Path.Combine(Application.persistentDataPath, filename); 17 | if(load && File.Exists(path)) 18 | { 19 | network = LoadMNISTBatchNormalizationNetwork(); 20 | if(network == null) { 21 | network = new MNISTBatchNormalizationNetwork(inputSize, 100, 10); 22 | } else 23 | { 24 | Debug.Log("load " + path); 25 | training = false; 26 | Measure(); 27 | } 28 | } else 29 | { 30 | network = new MNISTBatchNormalizationNetwork(inputSize, 100, 10); 31 | } 32 | } 33 | 34 | protected MNISTBatchNormalizationNetwork LoadMNISTBatchNormalizationNetwork() 35 | { 36 | var json = File.ReadAllText(path); 37 | var nw = JsonUtility.FromJson(json, typeof(MNISTBatchNormalizationNetwork)) as MNISTBatchNormalizationNetwork; 38 | return nw; 39 | } 40 | 41 | protected override void Update() 42 | { 43 | if(training && iter < iterations) 44 | { 45 | iter++; 46 | Signal input, answer; 47 | trainDataset.GetSubSignals(batchSize, out input, out answer); 48 | network.Gradient(compute, input, answer); 49 | network.Learn(compute, learningRate); 50 | 51 | input.Dispose(); 52 | answer.Dispose(); 53 | if(iter % measure == 0) 54 | { 55 | Signal testInput, testAnswer; 56 | testDataset.GetAllSignals(out testInput, out testAnswer); 57 | accuracy = network.Accuracy(compute, testInput, testAnswer); 58 | testInput.Dispose(); 59 | testAnswer.Dispose(); 60 | } 61 | } 62 | } 63 | 64 | } 65 | 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/MNISTBatchNormalizationTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: baf8ddd8c7ddec64aa6e813b95601857 3 | timeCreated: 1532055143 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/MNISTInput.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | using UnityEngine; 5 | using UnityEngine.EventSystems; 6 | using UnityEngine.UI; 7 | 8 | namespace UNN.Test 9 | { 10 | 11 | [RequireComponent (typeof(RawImage))] 12 | public class MNISTInput : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler 13 | { 14 | 15 | [SerializeField] protected MNISTTest mnist; 16 | [SerializeField] protected Material input, render; 17 | [SerializeField] protected ComputeShader converter; 18 | [SerializeField, Range(0.05f, 0.1f)] protected float size = 0.1f; 19 | 20 | [SerializeField] protected RenderTexture[] buffers; 21 | protected int read = 0; 22 | protected int write = 1; 23 | 24 | protected int lastLabel; 25 | 26 | protected RectTransform rectTransform; 27 | protected Vector2 rectSize; 28 | protected bool dragging; 29 | 30 | protected Signal signal; 31 | 32 | void Start () { 33 | rectTransform = GetComponent().rectTransform; 34 | rectSize = rectTransform.sizeDelta; 35 | 36 | const int resolution = 64; 37 | buffers = new RenderTexture[2]; 38 | buffers[0] = Create(resolution, resolution); 39 | buffers[1] = Create(resolution, resolution); 40 | 41 | render.SetTexture("_Input", buffers[0]); 42 | } 43 | 44 | protected void Swap() 45 | { 46 | var tmp = read; 47 | read = write; 48 | write = tmp; 49 | } 50 | 51 | protected void Evaluate() 52 | { 53 | const int rows = 28; 54 | const int columns = 28; 55 | 56 | var signal = new Signal(1, rows * columns); 57 | 58 | var kernel = converter.FindKernel("Convert"); 59 | converter.SetTexture(kernel, "_Input", buffers[read]); 60 | converter.SetBuffer(kernel, "_Digit", signal.Buffer); 61 | 62 | converter.SetInt("_Cols", columns); 63 | converter.SetInt("_Rows", rows); 64 | converter.SetVector("_TexelSize", new Vector2((1f / columns) * 0.5f, (1f / rows) * 0.5f)); 65 | 66 | uint tx, ty, tz; 67 | converter.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); 68 | converter.Dispatch(kernel, Mathf.FloorToInt(((int)columns - 1) / tx) + 1, Mathf.FloorToInt(((int)rows - 1) / ty) + 1, (int)tz); 69 | 70 | // signal.LogMNIST(); 71 | 72 | mnist.Evaluate(signal); 73 | signal.Dispose(); 74 | } 75 | 76 | 77 | protected RenderTexture Create(int width, int height) 78 | { 79 | var tex = new RenderTexture(width, height, 0); 80 | tex.filterMode = FilterMode.Bilinear; 81 | tex.enableRandomWrite = true; 82 | tex.Create(); 83 | return tex; 84 | } 85 | 86 | protected void OnDestroy() 87 | { 88 | buffers[0].Release(); 89 | buffers[1].Release(); 90 | } 91 | 92 | public void OnBeginDrag(PointerEventData eventData) 93 | { 94 | dragging = true; 95 | } 96 | 97 | public void OnDrag(PointerEventData eventData) 98 | { 99 | if(dragging) 100 | { 101 | Vector2 p; 102 | if(RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, null, out p)) 103 | { 104 | p.x = p.x / rectSize.x + 0.5f; 105 | p.y = p.y / rectSize.y + 0.5f; 106 | 107 | input.SetTexture("_Source", buffers[read]); 108 | input.SetVector("_Point", p); 109 | input.SetFloat("_Size", size); 110 | 111 | Graphics.Blit(null, buffers[write], input, 0); 112 | Swap(); 113 | 114 | Evaluate(); 115 | } 116 | } 117 | } 118 | 119 | public void OnEndDrag(PointerEventData eventData) 120 | { 121 | Evaluate(); 122 | 123 | // clear 124 | Graphics.Blit(null, buffers[write], input, 1); 125 | Swap(); 126 | 127 | dragging = false; 128 | } 129 | 130 | } 131 | 132 | } 133 | 134 | 135 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/MNISTInput.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92271c1585e50e4418615c7b2d4f3162 3 | timeCreated: 1531645510 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/MNISTNetwork.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | using UnityEngine; 7 | 8 | namespace UNN.Test 9 | { 10 | 11 | 12 | [System.Serializable] 13 | public class MNISTNetwork : Network 14 | { 15 | 16 | [SerializeField] protected int inputSize, hiddenSize, outputSize; 17 | 18 | [SerializeField] protected AffineLayer affine1; 19 | [SerializeField] protected ReLULayer relu; 20 | [SerializeField] protected AffineLayer affine2; 21 | [SerializeField] protected SoftmaxLayer softmax; 22 | 23 | [SerializeField] protected MomentumOptimizer optimizer; 24 | 25 | public MNISTNetwork(int inputSize, int hiddenSize, int outputSize) : base() 26 | { 27 | this.inputSize = inputSize; 28 | this.hiddenSize = hiddenSize; 29 | this.outputSize = outputSize; 30 | 31 | affine1 = new AffineLayer(inputSize, hiddenSize); 32 | relu = new ReLULayer(); 33 | affine2 = new AffineLayer(hiddenSize, outputSize); 34 | softmax = new SoftmaxLayer(); 35 | 36 | optimizer = new MomentumOptimizer(0.9f); 37 | } 38 | 39 | public override Signal Predict(ComputeShader compute, Signal input, bool train) 40 | { 41 | var layers = new List() { 42 | affine1, relu, affine2, 43 | }; 44 | 45 | layers.ForEach(layer => 46 | { 47 | var tmp = input; 48 | input = layer.Forward(compute, tmp, train); 49 | tmp.Dispose(); 50 | }); 51 | 52 | return input; 53 | } 54 | 55 | public override float Loss(ComputeShader compute, Signal signal, Signal answer, bool train) 56 | { 57 | var predictSig = Predict(compute, signal, train); 58 | 59 | var softmaxSig = softmax.Forward(compute, predictSig, train); 60 | predictSig.Dispose(); 61 | 62 | return CrossEntropyError.Loss(compute, softmaxSig, answer); 63 | } 64 | 65 | public override float Accuracy(ComputeShader compute, Signal input, Signal answer) 66 | { 67 | var output = Predict(compute, input, false); 68 | float acc = UNN.Accuracy.Calculate(compute, input, output, answer); 69 | output.Dispose(); 70 | return acc; 71 | } 72 | 73 | public override void Gradient(ComputeShader compute, Signal input, Signal answer) 74 | { 75 | Loss(compute, input, answer, true); 76 | 77 | var layers = new List() { 78 | affine1, relu, affine2, softmax 79 | }; 80 | layers.Reverse(); 81 | 82 | var signal = answer; 83 | layers.ForEach(layer => 84 | { 85 | var tmp = signal; 86 | signal = layer.Backward(compute, tmp); 87 | tmp.Dispose(); 88 | }); 89 | signal.Dispose(); 90 | } 91 | 92 | public override void Learn(ComputeShader compute, float rate = 0.1f) 93 | { 94 | affine1.Learn(optimizer, compute, rate); 95 | affine2.Learn(optimizer, compute, rate); 96 | } 97 | 98 | public override void Dispose() 99 | { 100 | affine1.Dispose(); 101 | relu.Dispose(); 102 | affine2.Dispose(); 103 | softmax.Dispose(); 104 | 105 | optimizer.Dispose(); 106 | } 107 | 108 | } 109 | 110 | } 111 | 112 | 113 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/MNISTNetwork.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f67879775fe6c447a3a0989070fb7d4 3 | timeCreated: 1531816392 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/MNISTTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | 7 | using UnityEngine; 8 | using Random = UnityEngine.Random; 9 | 10 | namespace UNN.Test 11 | { 12 | 13 | public class MNISTTest : MonoBehaviour { 14 | 15 | [SerializeField] protected ComputeShader compute; 16 | [SerializeField, Range(1000, 10000)] protected int iterations = 10000; 17 | [SerializeField, Range(8, 128)] protected int batchSize = 100; 18 | [SerializeField, Range(100, 500)] protected int measure = 500; 19 | [SerializeField, Range(0.01f, 0.1f)] protected float learningRate = 0.01f; 20 | [SerializeField, Range(1, 60)] protected int frame = 1; 21 | 22 | [SerializeField] protected string filename = "MNISTNetwork.json"; 23 | [SerializeField] protected bool load = true; 24 | 25 | [SerializeField] protected List probs; 26 | 27 | protected DigitDataset trainDataset, testDataset; 28 | protected List images; 29 | 30 | protected Vector2 scrollPosition = Vector2.zero; 31 | 32 | protected Network network; 33 | protected string path; 34 | 35 | [SerializeField] protected bool training; 36 | protected int iter = 0; 37 | protected float accuracy = 0f; 38 | protected int lastLabel; 39 | 40 | protected void Start() { 41 | var trainImagePath = Path.Combine(Path.Combine(Application.streamingAssetsPath, "MNIST"), "train-images.idx3-ubyte"); 42 | var trainLabelPath = Path.Combine(Path.Combine(Application.streamingAssetsPath, "MNIST"), "train-labels.idx1-ubyte"); 43 | var testImagePath = Path.Combine(Path.Combine(Application.streamingAssetsPath, "MNIST"), "t10k-images.idx3-ubyte"); 44 | var testLabelPath = Path.Combine(Path.Combine(Application.streamingAssetsPath, "MNIST"), "t10k-labels.idx1-ubyte"); 45 | 46 | trainDataset = LoadDataset(trainImagePath, trainLabelPath); 47 | testDataset = LoadDataset(testImagePath, testLabelPath); 48 | 49 | SetupNetwork(); 50 | 51 | // images = trainDataset.Digits.Take(128).Select(digit => digit.ToTexture(trainDataset.Rows, trainDataset.Columns)).ToList(); 52 | } 53 | 54 | protected virtual void SetupNetwork() 55 | { 56 | var inputSize = trainDataset.Rows * trainDataset.Columns; 57 | 58 | path = Path.Combine(Application.persistentDataPath, filename); 59 | if(load && File.Exists(path)) 60 | { 61 | network = LoadMNISTNetwork(); 62 | if(network == null) { 63 | network = new MNISTNetwork(inputSize, 50, 10); 64 | } else 65 | { 66 | Debug.Log("load " + path); 67 | training = false; 68 | Measure(); 69 | } 70 | } else 71 | { 72 | network = new MNISTNetwork(inputSize, 50, 10); 73 | } 74 | } 75 | 76 | protected virtual void Update() 77 | { 78 | if(training && (Time.frameCount % frame == 0) && iter < iterations) 79 | { 80 | iter++; 81 | Signal input, answer; 82 | trainDataset.GetSubSignals(batchSize, out input, out answer); 83 | network.Gradient(compute, input, answer); 84 | network.Learn(compute, learningRate); 85 | 86 | input.Dispose(); 87 | answer.Dispose(); 88 | if(iter % measure == 0) 89 | { 90 | Measure(); 91 | } 92 | } 93 | } 94 | 95 | protected void Measure() 96 | { 97 | Signal testInput, testAnswer; 98 | testDataset.GetAllSignals(out testInput, out testAnswer); 99 | accuracy = network.Accuracy(compute, testInput, testAnswer); 100 | testInput.Dispose(); 101 | testAnswer.Dispose(); 102 | } 103 | 104 | public void Evaluate(Signal input) 105 | { 106 | var output = network.Predict(compute, input, false); 107 | float[,] result = output.GetData(); 108 | output.Dispose(); 109 | 110 | // int rows = result.GetLength(0); 111 | int cols = result.GetLength(1); 112 | 113 | float max = 0f, sum = 0f; 114 | float[] exps = new float[cols]; 115 | 116 | for(int x = 0; x < cols; x++) 117 | { 118 | var v = result[0, x]; 119 | if(v > max) 120 | { 121 | max = v; 122 | lastLabel = x; 123 | } 124 | } 125 | 126 | for(int x = 0; x < cols; x++) 127 | { 128 | var v = result[0, x]; 129 | exps[x] = Mathf.Exp(v - max); 130 | sum += exps[x]; 131 | } 132 | 133 | for(int x = 0; x < cols; x++) 134 | { 135 | if(x < probs.Count) 136 | { 137 | probs[x].SetProbability(exps[x] / sum); 138 | } 139 | } 140 | 141 | } 142 | 143 | protected void SaveNetwork() 144 | { 145 | var json = JsonUtility.ToJson(network); 146 | File.WriteAllText(path, json); 147 | } 148 | 149 | protected MNISTNetwork LoadMNISTNetwork() 150 | { 151 | var json = File.ReadAllText(path); 152 | var network = JsonUtility.FromJson(json, typeof(MNISTNetwork)) as MNISTNetwork; 153 | return network; 154 | } 155 | 156 | protected DigitDataset LoadDataset(string imagePath, string labelPath, int limit = -1) 157 | { 158 | var labelsStream = new FileStream(labelPath, FileMode.Open); 159 | var imagesStream = new FileStream(imagePath, FileMode.Open); 160 | 161 | var labelsReader = new BinaryReader(labelsStream); 162 | var imagesReader = new BinaryReader(imagesStream); 163 | 164 | #pragma warning disable 0219 165 | int magic1 = ReadBigInt32(imagesReader); 166 | #pragma warning restore 0219 167 | 168 | int imagesCount = ReadBigInt32(imagesReader); 169 | int rows = ReadBigInt32(imagesReader); 170 | int cols = ReadBigInt32(imagesReader); 171 | 172 | #pragma warning disable 0219 173 | int magic2 = ReadBigInt32(labelsReader); 174 | #pragma warning restore 0219 175 | 176 | int labelsCount = ReadBigInt32(labelsReader); 177 | 178 | if(imagesCount != labelsCount) 179 | { 180 | Debug.LogWarning("the # of images and labels are not same."); 181 | } 182 | 183 | int count; 184 | if (limit <= 0) 185 | { 186 | count = imagesCount; 187 | } else 188 | { 189 | count = Mathf.Min(limit, imagesCount); 190 | } 191 | 192 | var digits = new Digit[count]; 193 | float inv = 1f / 255f; 194 | 195 | for (int i = 0; i < count; i++) 196 | { 197 | float[] pixels = new float[rows * cols]; 198 | for (int y = 0; y < rows; ++y) 199 | { 200 | for (int x = 0; x < cols; ++x) 201 | { 202 | byte b = imagesReader.ReadByte(); 203 | 204 | // invert y direction 205 | pixels[(rows - y - 1) * cols + x] = (int)b * inv; 206 | } 207 | } 208 | 209 | byte label = labelsReader.ReadByte(); 210 | 211 | var digit = new Digit(pixels, label); 212 | digits[i] = digit; 213 | } 214 | 215 | imagesStream.Close(); 216 | imagesReader.Close(); 217 | labelsStream.Close(); 218 | labelsReader.Close(); 219 | 220 | return new DigitDataset(digits, rows, cols); 221 | } 222 | 223 | // https://stackoverflow.com/questions/49407772/reading-mnist-database 224 | protected int ReadBigInt32(BinaryReader br) 225 | { 226 | var bytes = br.ReadBytes(sizeof(Int32)); 227 | if (BitConverter.IsLittleEndian) Array.Reverse(bytes); 228 | return BitConverter.ToInt32(bytes, 0); 229 | } 230 | 231 | protected void OnDestroy() 232 | { 233 | if(network != null) 234 | { 235 | network.Dispose(); 236 | network = null; 237 | } 238 | } 239 | 240 | protected void OnGUI() 241 | { 242 | if (trainDataset != null && images != null) 243 | { 244 | DrawMNISTView(); 245 | } 246 | 247 | using(new GUILayout.HorizontalScope()) 248 | { 249 | GUILayout.Space(20f); 250 | using(new GUILayout.VerticalScope()) 251 | { 252 | GUILayout.Space(20f); 253 | 254 | training = GUILayout.Toggle(training, "training"); 255 | GUILayout.Label("iterations : " + iter.ToString() + " / " + iterations.ToString()); 256 | 257 | GUILayout.Label("accuracy : " + accuracy.ToString("0.00")); 258 | GUILayout.Label("result : " + lastLabel); 259 | 260 | GUILayout.Space(10f); 261 | if(GUILayout.Button("Save")) 262 | { 263 | SaveNetwork(); 264 | } 265 | } 266 | } 267 | 268 | } 269 | 270 | protected void DrawMNISTView() 271 | { 272 | var n = images.Count; 273 | 274 | var cols = Mathf.CeilToInt(Screen.width / trainDataset.Columns); 275 | scrollPosition = GUI.BeginScrollView(new Rect(0, 0, Screen.width, Screen.height), scrollPosition, new Rect(0, 0, Screen.width, n / cols * trainDataset.Rows)); 276 | for(int i = 0; i < n; i++) 277 | { 278 | int x = i % cols; 279 | int y = i / cols; 280 | GUI.DrawTexture(new Rect(x * trainDataset.Columns, y * trainDataset.Rows, trainDataset.Columns, trainDataset.Rows), images[i]); 281 | // GUI.Label(new Rect(x * trainDataset.Columns, y * trainDataset.Rows, trainDataset.Columns, trainDataset.Rows), trainDataset.Digits[i].Label.ToString()); 282 | } 283 | 284 | GUI.EndScrollView(); 285 | } 286 | 287 | } 288 | 289 | } 290 | 291 | 292 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Scripts/MNISTTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be4f185b3ff9c984097e508816d1d9b2 3 | timeCreated: 1531375300 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e8327d81b0fdd6a4ab90f987a8e754c0 3 | folderAsset: yes 4 | timeCreated: 1532585121 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Shaders/DigitProb.shader: -------------------------------------------------------------------------------- 1 | Shader "UNN/Test/DigitProb" 2 | { 3 | Properties 4 | { 5 | _Color ("Tint", Color) = (1,1,1,1) 6 | _T ("T", Range(0.0, 1.0)) = 1.0 7 | 8 | _StencilComp ("Stencil Comparison", Float) = 8 9 | _Stencil ("Stencil ID", Float) = 0 10 | _StencilOp ("Stencil Operation", Float) = 0 11 | _StencilWriteMask ("Stencil Write Mask", Float) = 255 12 | _StencilReadMask ("Stencil Read Mask", Float) = 255 13 | 14 | _ColorMask ("Color Mask", Float) = 15 15 | 16 | [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0 17 | } 18 | 19 | SubShader 20 | { 21 | Tags { 22 | "Queue" = "Transparent" 23 | "IgnoreProjector" = "True" 24 | "RenderType" = "Transparent" 25 | "PreviewType" = "Plane" 26 | "CanUseSpriteAtlas" = "True" 27 | } 28 | 29 | Stencil { 30 | Ref [_Stencil] 31 | Comp [_StencilComp] 32 | Pass [_StencilOp] 33 | ReadMask [_StencilReadMask] 34 | WriteMask [_StencilWriteMask] 35 | } 36 | 37 | Cull Off 38 | Lighting Off 39 | ZWrite Off 40 | ZTest [unity_GUIZTestMode] 41 | Blend SrcAlpha OneMinusSrcAlpha 42 | ColorMask [_ColorMask] 43 | 44 | Pass { 45 | Name "Default" 46 | CGPROGRAM 47 | #pragma vertex vert 48 | #pragma fragment frag 49 | #pragma target 2.0 50 | 51 | #include "UnityCG.cginc" 52 | #include "UnityUI.cginc" 53 | 54 | #pragma multi_compile __ UNITY_UI_CLIP_RECT 55 | #pragma multi_compile __ UNITY_UI_ALPHACLIP 56 | 57 | struct appdata_t { 58 | float4 vertex : POSITION; 59 | float4 color : COLOR; 60 | float2 texcoord : TEXCOORD0; 61 | UNITY_VERTEX_INPUT_INSTANCE_ID 62 | }; 63 | 64 | struct v2f 65 | { 66 | float4 vertex : SV_POSITION; 67 | fixed4 color : COLOR; 68 | float2 texcoord : TEXCOORD0; 69 | float4 worldPosition : TEXCOORD1; 70 | UNITY_VERTEX_OUTPUT_STEREO 71 | }; 72 | 73 | fixed4 _Color; 74 | fixed _Alpha, _Opacity; 75 | fixed4 _TextureSampleAdd; 76 | float4 _ClipRect; 77 | 78 | v2f vert(appdata_t v) 79 | { 80 | v2f OUT; 81 | UNITY_SETUP_INSTANCE_ID(v); 82 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); 83 | OUT.worldPosition = v.vertex; 84 | OUT.vertex = UnityObjectToClipPos(OUT.worldPosition); 85 | 86 | OUT.texcoord = v.texcoord; 87 | 88 | OUT.color = v.color * _Color; 89 | return OUT; 90 | } 91 | 92 | sampler2D _MainTex; 93 | float _T; 94 | 95 | fixed4 frag(v2f IN) : SV_Target 96 | { 97 | clip(_T - IN.texcoord.y); 98 | 99 | half4 color = IN.color; 100 | 101 | #ifdef UNITY_UI_CLIP_RECT 102 | color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect); 103 | #endif 104 | 105 | #ifdef UNITY_UI_ALPHACLIP 106 | clip(color.a - 0.001); 107 | #endif 108 | 109 | return color; 110 | } 111 | 112 | ENDCG 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Shaders/DigitProb.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f0a9ae43c026c24481145a06efe61bf 3 | timeCreated: 1532587468 4 | licenseType: Pro 5 | ShaderImporter: 6 | externalObjects: {} 7 | defaultTextures: [] 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Shaders/MNISTDraw.shader: -------------------------------------------------------------------------------- 1 | Shader "UNN/Test/MNISTDraw" 2 | { 3 | 4 | Properties 5 | { 6 | _Source ("", 2D) = "" {} 7 | _Size ("Size", Float) = 0.1 8 | _Alpha ("Alpha", Range(0.0, 1.0)) = 0.1 9 | } 10 | 11 | CGINCLUDE 12 | 13 | struct appdata 14 | { 15 | float4 vertex : POSITION; 16 | float2 uv : TEXCOORD0; 17 | }; 18 | 19 | struct v2f 20 | { 21 | float2 uv : TEXCOORD0; 22 | float4 vertex : SV_POSITION; 23 | }; 24 | 25 | v2f vert(appdata v) 26 | { 27 | v2f o; 28 | o.vertex = UnityObjectToClipPos(v.vertex); 29 | o.uv = v.uv; 30 | return o; 31 | } 32 | 33 | sampler2D _Source; 34 | float2 _Point; 35 | float _Size, _Alpha; 36 | 37 | ENDCG 38 | 39 | SubShader 40 | { 41 | Cull Off ZWrite Off ZTest Always 42 | 43 | // paint 44 | Pass 45 | { 46 | CGPROGRAM 47 | #pragma vertex vert 48 | #pragma fragment frag 49 | 50 | #include "UnityCG.cginc" 51 | 52 | fixed4 frag(v2f i) : SV_Target 53 | { 54 | fixed4 col = tex2D(_Source, i.uv); 55 | float d = distance(_Point, i.uv); 56 | col.rgb += saturate(1.0 - d / _Size); 57 | col.rgb = saturate(col.rgb); 58 | col.a = _Alpha; 59 | return col; 60 | } 61 | 62 | ENDCG 63 | } 64 | 65 | // clear 66 | Pass 67 | { 68 | CGPROGRAM 69 | #pragma vertex vert 70 | #pragma fragment frag 71 | 72 | #include "UnityCG.cginc" 73 | 74 | fixed4 frag(v2f i) : SV_Target 75 | { 76 | return float4(0, 0, 0, _Alpha); 77 | } 78 | 79 | ENDCG 80 | } 81 | 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Shaders/MNISTDraw.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2095a3791686a045bbac6b9d0de6533 3 | timeCreated: 1531645872 4 | licenseType: Pro 5 | ShaderImporter: 6 | externalObjects: {} 7 | defaultTextures: [] 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Shaders/MNISTInput.compute: -------------------------------------------------------------------------------- 1 | #pragma kernel Convert 2 | #define THREAD [numthreads(8, 8, 1)] 3 | 4 | Texture2D _Input; 5 | SamplerState _PointClamp, _LinearClamp; 6 | 7 | RWStructuredBuffer _Digit; 8 | 9 | int _Rows, _Cols; 10 | float2 _TexelSize; 11 | 12 | THREAD 13 | void Convert (uint3 id : SV_DispatchThreadID) 14 | { 15 | int x = id.x; 16 | int y = id.y; 17 | if (x >= _Cols || y >= _Rows) 18 | return; 19 | 20 | // float u = (1.0 * x) / (_Cols - 1) + _TexelSize.x; 21 | // float v = (1.0 * y) / (_Rows - 1) + _TexelSize.y; 22 | 23 | float u = (1.0 * x) / (_Cols - 1); 24 | float v = (1.0 * y) / (_Rows - 1); 25 | float4 value = _Input.SampleLevel(_LinearClamp, float2(u, v), 0.0); 26 | _Digit[y * _Cols + x] = value.x; 27 | } 28 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Shaders/MNISTInput.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d3937aff4d6592140998df74f24d47e6 3 | timeCreated: 1531647446 4 | licenseType: Pro 5 | ComputeShaderImporter: 6 | externalObjects: {} 7 | currentAPIMask: 4 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Shaders/MNISTInput.shader: -------------------------------------------------------------------------------- 1 | Shader "UNN/Test/MNISTInput" 2 | { 3 | 4 | Properties 5 | { 6 | _Input ("Input", 2D) = "black" {} 7 | } 8 | 9 | CGINCLUDE 10 | 11 | struct appdata 12 | { 13 | float4 vertex : POSITION; 14 | float2 uv : TEXCOORD0; 15 | }; 16 | 17 | struct v2f 18 | { 19 | float2 uv : TEXCOORD0; 20 | float4 vertex : SV_POSITION; 21 | }; 22 | 23 | v2f vert(appdata v) 24 | { 25 | v2f o; 26 | o.vertex = UnityObjectToClipPos(v.vertex); 27 | o.uv = v.uv; 28 | return o; 29 | } 30 | 31 | ENDCG 32 | 33 | SubShader 34 | { 35 | Cull Off ZWrite Off ZTest Always 36 | 37 | Pass 38 | { 39 | CGPROGRAM 40 | #pragma vertex vert 41 | #pragma fragment frag 42 | 43 | #include "UnityCG.cginc" 44 | 45 | sampler2D _Input; 46 | 47 | fixed4 frag(v2f i) : SV_Target 48 | { 49 | fixed4 col = tex2D(_Input, i.uv); 50 | col.rgb = (1.0).xxx - col.rgb; 51 | return col; 52 | } 53 | 54 | ENDCG 55 | } 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Assets/UNN/Test/MNIST/Shaders/MNISTInput.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 794a979892f733943aa58ff0da0f6416 3 | timeCreated: 1531645872 4 | licenseType: Pro 5 | ShaderImporter: 6 | externalObjects: {} 7 | defaultTextures: [] 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Captures/MNIST.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattatz/UNN/676e1d4f313f1079baa57389ad1dea0eb0d75b57/Captures/MNIST.gif -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | m_Volume: 1 7 | Rolloff Scale: 1 8 | Doppler Factor: 1 9 | Default Speaker Mode: 2 10 | m_SampleRate: 0 11 | m_DSPBufferSize: 0 12 | m_VirtualVoiceCount: 512 13 | m_RealVoiceCount: 32 14 | m_SpatializerPlugin: 15 | m_AmbisonicDecoderPlugin: 16 | m_DisableAudio: 0 17 | m_VirtualizeEffects: 1 18 | -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 7 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0 18 | m_ClothInterCollisionStiffness: 0 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 1 23 | m_ClothInterCollisionSettingsToggle: 0 24 | m_ContactPairsMode: 0 25 | m_BroadphaseType: 0 26 | m_WorldBounds: 27 | m_Center: {x: 0, y: 0, z: 0} 28 | m_Extent: {x: 250, y: 250, z: 250} 29 | m_WorldSubdivisions: 8 30 | -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: [] 8 | -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 7 7 | m_ExternalVersionControlSupport: Hidden Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 2 10 | m_DefaultBehaviorMode: 0 11 | m_SpritePackerMode: 0 12 | m_SpritePackerPaddingPower: 1 13 | m_EtcTextureCompressorBehavior: 1 14 | m_EtcTextureFastCompressor: 1 15 | m_EtcTextureNormalCompressor: 2 16 | m_EtcTextureBestCompressor: 4 17 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp 18 | m_ProjectGenerationRootNamespace: 19 | m_UserGeneratedProjectSuffix: 20 | m_CollabEditorSettings: 21 | inProgressEnabled: 1 22 | -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 12 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_DeferredReflections: 11 | m_Mode: 1 12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} 13 | m_ScreenSpaceShadows: 14 | m_Mode: 1 15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} 16 | m_LegacyDeferred: 17 | m_Mode: 1 18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 19 | m_DepthNormals: 20 | m_Mode: 1 21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} 22 | m_MotionVectors: 23 | m_Mode: 1 24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} 25 | m_LightHalo: 26 | m_Mode: 1 27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} 28 | m_LensFlare: 29 | m_Mode: 1 30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} 31 | m_AlwaysIncludedShaders: 32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} 37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 38 | - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} 39 | - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} 40 | m_PreloadedShaders: [] 41 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, 42 | type: 0} 43 | m_CustomRenderPipeline: {fileID: 0} 44 | m_TransparencySortMode: 0 45 | m_TransparencySortAxis: {x: 0, y: 0, z: 1} 46 | m_DefaultRenderingPath: 1 47 | m_DefaultMobileRenderingPath: 1 48 | m_TierSettings: [] 49 | m_LightmapStripping: 0 50 | m_FogStripping: 0 51 | m_InstancingStripping: 0 52 | m_LightmapKeepPlain: 1 53 | m_LightmapKeepDirCombined: 1 54 | m_LightmapKeepDynamicPlain: 1 55 | m_LightmapKeepDynamicDirCombined: 1 56 | m_LightmapKeepShadowMask: 1 57 | m_LightmapKeepSubtractive: 1 58 | m_FogKeepLinear: 1 59 | m_FogKeepExp: 1 60 | m_FogKeepExp2: 1 61 | m_AlbedoSwatchInfos: [] 62 | m_LightsUseLinearIntensity: 0 63 | m_LightsUseColorTemperature: 0 64 | -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!13 &1 4 | InputManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Axes: 8 | - serializedVersion: 3 9 | m_Name: Horizontal 10 | descriptiveName: 11 | descriptiveNegativeName: 12 | negativeButton: left 13 | positiveButton: right 14 | altNegativeButton: a 15 | altPositiveButton: d 16 | gravity: 3 17 | dead: 0.001 18 | sensitivity: 3 19 | snap: 1 20 | invert: 0 21 | type: 0 22 | axis: 0 23 | joyNum: 0 24 | - serializedVersion: 3 25 | m_Name: Vertical 26 | descriptiveName: 27 | descriptiveNegativeName: 28 | negativeButton: down 29 | positiveButton: up 30 | altNegativeButton: s 31 | altPositiveButton: w 32 | gravity: 3 33 | dead: 0.001 34 | sensitivity: 3 35 | snap: 1 36 | invert: 0 37 | type: 0 38 | axis: 0 39 | joyNum: 0 40 | - serializedVersion: 3 41 | m_Name: Fire1 42 | descriptiveName: 43 | descriptiveNegativeName: 44 | negativeButton: 45 | positiveButton: left ctrl 46 | altNegativeButton: 47 | altPositiveButton: mouse 0 48 | gravity: 1000 49 | dead: 0.001 50 | sensitivity: 1000 51 | snap: 0 52 | invert: 0 53 | type: 0 54 | axis: 0 55 | joyNum: 0 56 | - serializedVersion: 3 57 | m_Name: Fire2 58 | descriptiveName: 59 | descriptiveNegativeName: 60 | negativeButton: 61 | positiveButton: left alt 62 | altNegativeButton: 63 | altPositiveButton: mouse 1 64 | gravity: 1000 65 | dead: 0.001 66 | sensitivity: 1000 67 | snap: 0 68 | invert: 0 69 | type: 0 70 | axis: 0 71 | joyNum: 0 72 | - serializedVersion: 3 73 | m_Name: Fire3 74 | descriptiveName: 75 | descriptiveNegativeName: 76 | negativeButton: 77 | positiveButton: left shift 78 | altNegativeButton: 79 | altPositiveButton: mouse 2 80 | gravity: 1000 81 | dead: 0.001 82 | sensitivity: 1000 83 | snap: 0 84 | invert: 0 85 | type: 0 86 | axis: 0 87 | joyNum: 0 88 | - serializedVersion: 3 89 | m_Name: Jump 90 | descriptiveName: 91 | descriptiveNegativeName: 92 | negativeButton: 93 | positiveButton: space 94 | altNegativeButton: 95 | altPositiveButton: 96 | gravity: 1000 97 | dead: 0.001 98 | sensitivity: 1000 99 | snap: 0 100 | invert: 0 101 | type: 0 102 | axis: 0 103 | joyNum: 0 104 | - serializedVersion: 3 105 | m_Name: Mouse X 106 | descriptiveName: 107 | descriptiveNegativeName: 108 | negativeButton: 109 | positiveButton: 110 | altNegativeButton: 111 | altPositiveButton: 112 | gravity: 0 113 | dead: 0 114 | sensitivity: 0.1 115 | snap: 0 116 | invert: 0 117 | type: 1 118 | axis: 0 119 | joyNum: 0 120 | - serializedVersion: 3 121 | m_Name: Mouse Y 122 | descriptiveName: 123 | descriptiveNegativeName: 124 | negativeButton: 125 | positiveButton: 126 | altNegativeButton: 127 | altPositiveButton: 128 | gravity: 0 129 | dead: 0 130 | sensitivity: 0.1 131 | snap: 0 132 | invert: 0 133 | type: 1 134 | axis: 1 135 | joyNum: 0 136 | - serializedVersion: 3 137 | m_Name: Mouse ScrollWheel 138 | descriptiveName: 139 | descriptiveNegativeName: 140 | negativeButton: 141 | positiveButton: 142 | altNegativeButton: 143 | altPositiveButton: 144 | gravity: 0 145 | dead: 0 146 | sensitivity: 0.1 147 | snap: 0 148 | invert: 0 149 | type: 1 150 | axis: 2 151 | joyNum: 0 152 | - serializedVersion: 3 153 | m_Name: Horizontal 154 | descriptiveName: 155 | descriptiveNegativeName: 156 | negativeButton: 157 | positiveButton: 158 | altNegativeButton: 159 | altPositiveButton: 160 | gravity: 0 161 | dead: 0.19 162 | sensitivity: 1 163 | snap: 0 164 | invert: 0 165 | type: 2 166 | axis: 0 167 | joyNum: 0 168 | - serializedVersion: 3 169 | m_Name: Vertical 170 | descriptiveName: 171 | descriptiveNegativeName: 172 | negativeButton: 173 | positiveButton: 174 | altNegativeButton: 175 | altPositiveButton: 176 | gravity: 0 177 | dead: 0.19 178 | sensitivity: 1 179 | snap: 0 180 | invert: 1 181 | type: 2 182 | axis: 1 183 | joyNum: 0 184 | - serializedVersion: 3 185 | m_Name: Fire1 186 | descriptiveName: 187 | descriptiveNegativeName: 188 | negativeButton: 189 | positiveButton: joystick button 0 190 | altNegativeButton: 191 | altPositiveButton: 192 | gravity: 1000 193 | dead: 0.001 194 | sensitivity: 1000 195 | snap: 0 196 | invert: 0 197 | type: 0 198 | axis: 0 199 | joyNum: 0 200 | - serializedVersion: 3 201 | m_Name: Fire2 202 | descriptiveName: 203 | descriptiveNegativeName: 204 | negativeButton: 205 | positiveButton: joystick button 1 206 | altNegativeButton: 207 | altPositiveButton: 208 | gravity: 1000 209 | dead: 0.001 210 | sensitivity: 1000 211 | snap: 0 212 | invert: 0 213 | type: 0 214 | axis: 0 215 | joyNum: 0 216 | - serializedVersion: 3 217 | m_Name: Fire3 218 | descriptiveName: 219 | descriptiveNegativeName: 220 | negativeButton: 221 | positiveButton: joystick button 2 222 | altNegativeButton: 223 | altPositiveButton: 224 | gravity: 1000 225 | dead: 0.001 226 | sensitivity: 1000 227 | snap: 0 228 | invert: 0 229 | type: 0 230 | axis: 0 231 | joyNum: 0 232 | - serializedVersion: 3 233 | m_Name: Jump 234 | descriptiveName: 235 | descriptiveNegativeName: 236 | negativeButton: 237 | positiveButton: joystick button 3 238 | altNegativeButton: 239 | altPositiveButton: 240 | gravity: 1000 241 | dead: 0.001 242 | sensitivity: 1000 243 | snap: 0 244 | invert: 0 245 | type: 0 246 | axis: 0 247 | joyNum: 0 248 | - serializedVersion: 3 249 | m_Name: Submit 250 | descriptiveName: 251 | descriptiveNegativeName: 252 | negativeButton: 253 | positiveButton: return 254 | altNegativeButton: 255 | altPositiveButton: joystick button 0 256 | gravity: 1000 257 | dead: 0.001 258 | sensitivity: 1000 259 | snap: 0 260 | invert: 0 261 | type: 0 262 | axis: 0 263 | joyNum: 0 264 | - serializedVersion: 3 265 | m_Name: Submit 266 | descriptiveName: 267 | descriptiveNegativeName: 268 | negativeButton: 269 | positiveButton: enter 270 | altNegativeButton: 271 | altPositiveButton: space 272 | gravity: 1000 273 | dead: 0.001 274 | sensitivity: 1000 275 | snap: 0 276 | invert: 0 277 | type: 0 278 | axis: 0 279 | joyNum: 0 280 | - serializedVersion: 3 281 | m_Name: Cancel 282 | descriptiveName: 283 | descriptiveNegativeName: 284 | negativeButton: 285 | positiveButton: escape 286 | altNegativeButton: 287 | altPositiveButton: joystick button 1 288 | gravity: 1000 289 | dead: 0.001 290 | sensitivity: 1000 291 | snap: 0 292 | invert: 0 293 | type: 0 294 | axis: 0 295 | joyNum: 0 296 | -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!149 &1 4 | NetworkManager: 5 | m_ObjectHideFlags: 0 6 | m_DebugLevel: 0 7 | m_Sendrate: 15 8 | m_AssetToPrefab: {} 9 | -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 3 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_AutoSimulation: 1 23 | m_QueriesHitTriggers: 1 24 | m_QueriesStartInColliders: 1 25 | m_ChangeStopsCallbacks: 0 26 | m_CallbacksOnDisable: 1 27 | m_AutoSyncTransforms: 1 28 | m_AlwaysShowColliders: 0 29 | m_ShowColliderSleep: 1 30 | m_ShowColliderContacts: 0 31 | m_ShowColliderAABB: 0 32 | m_ContactArrowScale: 0.2 33 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 34 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 35 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 36 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 37 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 38 | -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!129 &1 4 | PlayerSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 14 7 | productGUID: d1d3ab235979d7e4cb4545922679602d 8 | AndroidProfiler: 0 9 | AndroidFilterTouchesWhenObscured: 0 10 | defaultScreenOrientation: 4 11 | targetDevice: 2 12 | useOnDemandResources: 0 13 | accelerometerFrequency: 60 14 | companyName: DefaultCompany 15 | productName: UNN 16 | defaultCursor: {fileID: 0} 17 | cursorHotspot: {x: 0, y: 0} 18 | m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1} 19 | m_ShowUnitySplashScreen: 1 20 | m_ShowUnitySplashLogo: 1 21 | m_SplashScreenOverlayOpacity: 1 22 | m_SplashScreenAnimation: 1 23 | m_SplashScreenLogoStyle: 1 24 | m_SplashScreenDrawMode: 0 25 | m_SplashScreenBackgroundAnimationZoom: 1 26 | m_SplashScreenLogoAnimationZoom: 1 27 | m_SplashScreenBackgroundLandscapeAspect: 1 28 | m_SplashScreenBackgroundPortraitAspect: 1 29 | m_SplashScreenBackgroundLandscapeUvs: 30 | serializedVersion: 2 31 | x: 0 32 | y: 0 33 | width: 1 34 | height: 1 35 | m_SplashScreenBackgroundPortraitUvs: 36 | serializedVersion: 2 37 | x: 0 38 | y: 0 39 | width: 1 40 | height: 1 41 | m_SplashScreenLogos: [] 42 | m_VirtualRealitySplashScreen: {fileID: 0} 43 | m_HolographicTrackingLossScreen: {fileID: 0} 44 | defaultScreenWidth: 1024 45 | defaultScreenHeight: 768 46 | defaultScreenWidthWeb: 960 47 | defaultScreenHeightWeb: 600 48 | m_StereoRenderingPath: 0 49 | m_ActiveColorSpace: 0 50 | m_MTRendering: 1 51 | m_StackTraceTypes: 010000000100000001000000010000000100000001000000 52 | iosShowActivityIndicatorOnLoading: -1 53 | androidShowActivityIndicatorOnLoading: -1 54 | tizenShowActivityIndicatorOnLoading: -1 55 | iosAppInBackgroundBehavior: 0 56 | displayResolutionDialog: 1 57 | iosAllowHTTPDownload: 1 58 | allowedAutorotateToPortrait: 1 59 | allowedAutorotateToPortraitUpsideDown: 1 60 | allowedAutorotateToLandscapeRight: 1 61 | allowedAutorotateToLandscapeLeft: 1 62 | useOSAutorotation: 1 63 | use32BitDisplayBuffer: 1 64 | preserveFramebufferAlpha: 0 65 | disableDepthAndStencilBuffers: 0 66 | androidBlitType: 0 67 | defaultIsFullScreen: 1 68 | defaultIsNativeResolution: 1 69 | macRetinaSupport: 1 70 | runInBackground: 0 71 | captureSingleScreen: 0 72 | muteOtherAudioSources: 0 73 | Prepare IOS For Recording: 0 74 | Force IOS Speakers When Recording: 0 75 | deferSystemGesturesMode: 0 76 | hideHomeButton: 0 77 | submitAnalytics: 1 78 | usePlayerLog: 1 79 | bakeCollisionMeshes: 0 80 | forceSingleInstance: 0 81 | resizableWindow: 0 82 | useMacAppStoreValidation: 0 83 | macAppStoreCategory: public.app-category.games 84 | gpuSkinning: 0 85 | graphicsJobs: 0 86 | xboxPIXTextureCapture: 0 87 | xboxEnableAvatar: 0 88 | xboxEnableKinect: 0 89 | xboxEnableKinectAutoTracking: 0 90 | xboxEnableFitness: 0 91 | visibleInBackground: 1 92 | allowFullscreenSwitch: 1 93 | graphicsJobMode: 0 94 | macFullscreenMode: 2 95 | d3d11FullscreenMode: 1 96 | xboxSpeechDB: 0 97 | xboxEnableHeadOrientation: 0 98 | xboxEnableGuest: 0 99 | xboxEnablePIXSampling: 0 100 | metalFramebufferOnly: 0 101 | n3dsDisableStereoscopicView: 0 102 | n3dsEnableSharedListOpt: 1 103 | n3dsEnableVSync: 0 104 | xboxOneResolution: 0 105 | xboxOneSResolution: 0 106 | xboxOneXResolution: 3 107 | xboxOneMonoLoggingLevel: 0 108 | xboxOneLoggingLevel: 1 109 | xboxOneDisableEsram: 0 110 | xboxOnePresentImmediateThreshold: 0 111 | videoMemoryForVertexBuffers: 0 112 | psp2PowerMode: 0 113 | psp2AcquireBGM: 1 114 | wiiUTVResolution: 0 115 | wiiUGamePadMSAA: 1 116 | wiiUSupportsNunchuk: 0 117 | wiiUSupportsClassicController: 0 118 | wiiUSupportsBalanceBoard: 0 119 | wiiUSupportsMotionPlus: 0 120 | wiiUSupportsProController: 0 121 | wiiUAllowScreenCapture: 1 122 | wiiUControllerCount: 0 123 | m_SupportedAspectRatios: 124 | 4:3: 1 125 | 5:4: 1 126 | 16:10: 1 127 | 16:9: 1 128 | Others: 1 129 | bundleVersion: 1.0 130 | preloadedAssets: [] 131 | metroInputSource: 0 132 | wsaTransparentSwapchain: 0 133 | m_HolographicPauseOnTrackingLoss: 1 134 | xboxOneDisableKinectGpuReservation: 0 135 | xboxOneEnable7thCore: 0 136 | vrSettings: 137 | cardboard: 138 | depthFormat: 0 139 | enableTransitionView: 0 140 | daydream: 141 | depthFormat: 0 142 | useSustainedPerformanceMode: 0 143 | enableVideoLayer: 0 144 | useProtectedVideoMemory: 0 145 | minimumSupportedHeadTracking: 0 146 | maximumSupportedHeadTracking: 1 147 | hololens: 148 | depthFormat: 1 149 | depthBufferSharingEnabled: 0 150 | oculus: 151 | sharedDepthBuffer: 0 152 | dashSupport: 0 153 | protectGraphicsMemory: 0 154 | useHDRDisplay: 0 155 | m_ColorGamuts: 00000000 156 | targetPixelDensity: 30 157 | resolutionScalingMode: 0 158 | androidSupportedAspectRatio: 1 159 | androidMaxAspectRatio: 2.1 160 | applicationIdentifier: {} 161 | buildNumber: {} 162 | AndroidBundleVersionCode: 1 163 | AndroidMinSdkVersion: 16 164 | AndroidTargetSdkVersion: 0 165 | AndroidPreferredInstallLocation: 1 166 | aotOptions: 167 | stripEngineCode: 1 168 | iPhoneStrippingLevel: 0 169 | iPhoneScriptCallOptimization: 0 170 | ForceInternetPermission: 0 171 | ForceSDCardPermission: 0 172 | CreateWallpaper: 0 173 | APKExpansionFiles: 0 174 | keepLoadedShadersAlive: 0 175 | StripUnusedMeshComponents: 0 176 | VertexChannelCompressionMask: 177 | serializedVersion: 2 178 | m_Bits: 238 179 | iPhoneSdkVersion: 988 180 | iOSTargetOSVersionString: 7.0 181 | tvOSSdkVersion: 0 182 | tvOSRequireExtendedGameController: 0 183 | tvOSTargetOSVersionString: 9.0 184 | uIPrerenderedIcon: 0 185 | uIRequiresPersistentWiFi: 0 186 | uIRequiresFullScreen: 1 187 | uIStatusBarHidden: 1 188 | uIExitOnSuspend: 0 189 | uIStatusBarStyle: 0 190 | iPhoneSplashScreen: {fileID: 0} 191 | iPhoneHighResSplashScreen: {fileID: 0} 192 | iPhoneTallHighResSplashScreen: {fileID: 0} 193 | iPhone47inSplashScreen: {fileID: 0} 194 | iPhone55inPortraitSplashScreen: {fileID: 0} 195 | iPhone55inLandscapeSplashScreen: {fileID: 0} 196 | iPhone58inPortraitSplashScreen: {fileID: 0} 197 | iPhone58inLandscapeSplashScreen: {fileID: 0} 198 | iPadPortraitSplashScreen: {fileID: 0} 199 | iPadHighResPortraitSplashScreen: {fileID: 0} 200 | iPadLandscapeSplashScreen: {fileID: 0} 201 | iPadHighResLandscapeSplashScreen: {fileID: 0} 202 | appleTVSplashScreen: {fileID: 0} 203 | appleTVSplashScreen2x: {fileID: 0} 204 | tvOSSmallIconLayers: [] 205 | tvOSSmallIconLayers2x: [] 206 | tvOSLargeIconLayers: [] 207 | tvOSTopShelfImageLayers: [] 208 | tvOSTopShelfImageLayers2x: [] 209 | tvOSTopShelfImageWideLayers: [] 210 | tvOSTopShelfImageWideLayers2x: [] 211 | iOSLaunchScreenType: 0 212 | iOSLaunchScreenPortrait: {fileID: 0} 213 | iOSLaunchScreenLandscape: {fileID: 0} 214 | iOSLaunchScreenBackgroundColor: 215 | serializedVersion: 2 216 | rgba: 0 217 | iOSLaunchScreenFillPct: 100 218 | iOSLaunchScreenSize: 100 219 | iOSLaunchScreenCustomXibPath: 220 | iOSLaunchScreeniPadType: 0 221 | iOSLaunchScreeniPadImage: {fileID: 0} 222 | iOSLaunchScreeniPadBackgroundColor: 223 | serializedVersion: 2 224 | rgba: 0 225 | iOSLaunchScreeniPadFillPct: 100 226 | iOSLaunchScreeniPadSize: 100 227 | iOSLaunchScreeniPadCustomXibPath: 228 | iOSUseLaunchScreenStoryboard: 0 229 | iOSLaunchScreenCustomStoryboardPath: 230 | iOSDeviceRequirements: [] 231 | iOSURLSchemes: [] 232 | iOSBackgroundModes: 0 233 | iOSMetalForceHardShadows: 0 234 | metalEditorSupport: 1 235 | metalAPIValidation: 1 236 | iOSRenderExtraFrameOnPause: 0 237 | appleDeveloperTeamID: 238 | iOSManualSigningProvisioningProfileID: 239 | tvOSManualSigningProvisioningProfileID: 240 | appleEnableAutomaticSigning: 0 241 | clonedFromGUID: 00000000000000000000000000000000 242 | AndroidTargetDevice: 0 243 | AndroidSplashScreenScale: 0 244 | androidSplashScreen: {fileID: 0} 245 | AndroidKeystoreName: 246 | AndroidKeyaliasName: 247 | AndroidTVCompatibility: 1 248 | AndroidIsGame: 1 249 | AndroidEnableTango: 0 250 | androidEnableBanner: 1 251 | androidUseLowAccuracyLocation: 0 252 | m_AndroidBanners: 253 | - width: 320 254 | height: 180 255 | banner: {fileID: 0} 256 | androidGamepadSupportLevel: 0 257 | resolutionDialogBanner: {fileID: 0} 258 | m_BuildTargetIcons: [] 259 | m_BuildTargetBatching: [] 260 | m_BuildTargetGraphicsAPIs: [] 261 | m_BuildTargetVRSettings: [] 262 | m_BuildTargetEnableVuforiaSettings: [] 263 | openGLRequireES31: 0 264 | openGLRequireES31AEP: 0 265 | m_TemplateCustomTags: {} 266 | mobileMTRendering: 267 | Android: 1 268 | iPhone: 1 269 | tvOS: 1 270 | m_BuildTargetGroupLightmapEncodingQuality: [] 271 | wiiUTitleID: 0005000011000000 272 | wiiUGroupID: 00010000 273 | wiiUCommonSaveSize: 4096 274 | wiiUAccountSaveSize: 2048 275 | wiiUOlvAccessKey: 0 276 | wiiUTinCode: 0 277 | wiiUJoinGameId: 0 278 | wiiUJoinGameModeMask: 0000000000000000 279 | wiiUCommonBossSize: 0 280 | wiiUAccountBossSize: 0 281 | wiiUAddOnUniqueIDs: [] 282 | wiiUMainThreadStackSize: 3072 283 | wiiULoaderThreadStackSize: 1024 284 | wiiUSystemHeapSize: 128 285 | wiiUTVStartupScreen: {fileID: 0} 286 | wiiUGamePadStartupScreen: {fileID: 0} 287 | wiiUDrcBufferDisabled: 0 288 | wiiUProfilerLibPath: 289 | playModeTestRunnerEnabled: 0 290 | actionOnDotNetUnhandledException: 1 291 | enableInternalProfiler: 0 292 | logObjCUncaughtExceptions: 1 293 | enableCrashReportAPI: 0 294 | cameraUsageDescription: 295 | locationUsageDescription: 296 | microphoneUsageDescription: 297 | switchNetLibKey: 298 | switchSocketMemoryPoolSize: 6144 299 | switchSocketAllocatorPoolSize: 128 300 | switchSocketConcurrencyLimit: 14 301 | switchScreenResolutionBehavior: 2 302 | switchUseCPUProfiler: 0 303 | switchApplicationID: 0x01004b9000490000 304 | switchNSODependencies: 305 | switchTitleNames_0: 306 | switchTitleNames_1: 307 | switchTitleNames_2: 308 | switchTitleNames_3: 309 | switchTitleNames_4: 310 | switchTitleNames_5: 311 | switchTitleNames_6: 312 | switchTitleNames_7: 313 | switchTitleNames_8: 314 | switchTitleNames_9: 315 | switchTitleNames_10: 316 | switchTitleNames_11: 317 | switchTitleNames_12: 318 | switchTitleNames_13: 319 | switchTitleNames_14: 320 | switchPublisherNames_0: 321 | switchPublisherNames_1: 322 | switchPublisherNames_2: 323 | switchPublisherNames_3: 324 | switchPublisherNames_4: 325 | switchPublisherNames_5: 326 | switchPublisherNames_6: 327 | switchPublisherNames_7: 328 | switchPublisherNames_8: 329 | switchPublisherNames_9: 330 | switchPublisherNames_10: 331 | switchPublisherNames_11: 332 | switchPublisherNames_12: 333 | switchPublisherNames_13: 334 | switchPublisherNames_14: 335 | switchIcons_0: {fileID: 0} 336 | switchIcons_1: {fileID: 0} 337 | switchIcons_2: {fileID: 0} 338 | switchIcons_3: {fileID: 0} 339 | switchIcons_4: {fileID: 0} 340 | switchIcons_5: {fileID: 0} 341 | switchIcons_6: {fileID: 0} 342 | switchIcons_7: {fileID: 0} 343 | switchIcons_8: {fileID: 0} 344 | switchIcons_9: {fileID: 0} 345 | switchIcons_10: {fileID: 0} 346 | switchIcons_11: {fileID: 0} 347 | switchIcons_12: {fileID: 0} 348 | switchIcons_13: {fileID: 0} 349 | switchIcons_14: {fileID: 0} 350 | switchSmallIcons_0: {fileID: 0} 351 | switchSmallIcons_1: {fileID: 0} 352 | switchSmallIcons_2: {fileID: 0} 353 | switchSmallIcons_3: {fileID: 0} 354 | switchSmallIcons_4: {fileID: 0} 355 | switchSmallIcons_5: {fileID: 0} 356 | switchSmallIcons_6: {fileID: 0} 357 | switchSmallIcons_7: {fileID: 0} 358 | switchSmallIcons_8: {fileID: 0} 359 | switchSmallIcons_9: {fileID: 0} 360 | switchSmallIcons_10: {fileID: 0} 361 | switchSmallIcons_11: {fileID: 0} 362 | switchSmallIcons_12: {fileID: 0} 363 | switchSmallIcons_13: {fileID: 0} 364 | switchSmallIcons_14: {fileID: 0} 365 | switchManualHTML: 366 | switchAccessibleURLs: 367 | switchLegalInformation: 368 | switchMainThreadStackSize: 1048576 369 | switchPresenceGroupId: 370 | switchLogoHandling: 0 371 | switchReleaseVersion: 0 372 | switchDisplayVersion: 1.0.0 373 | switchStartupUserAccount: 0 374 | switchTouchScreenUsage: 0 375 | switchSupportedLanguagesMask: 0 376 | switchLogoType: 0 377 | switchApplicationErrorCodeCategory: 378 | switchUserAccountSaveDataSize: 0 379 | switchUserAccountSaveDataJournalSize: 0 380 | switchApplicationAttribute: 0 381 | switchCardSpecSize: -1 382 | switchCardSpecClock: -1 383 | switchRatingsMask: 0 384 | switchRatingsInt_0: 0 385 | switchRatingsInt_1: 0 386 | switchRatingsInt_2: 0 387 | switchRatingsInt_3: 0 388 | switchRatingsInt_4: 0 389 | switchRatingsInt_5: 0 390 | switchRatingsInt_6: 0 391 | switchRatingsInt_7: 0 392 | switchRatingsInt_8: 0 393 | switchRatingsInt_9: 0 394 | switchRatingsInt_10: 0 395 | switchRatingsInt_11: 0 396 | switchLocalCommunicationIds_0: 397 | switchLocalCommunicationIds_1: 398 | switchLocalCommunicationIds_2: 399 | switchLocalCommunicationIds_3: 400 | switchLocalCommunicationIds_4: 401 | switchLocalCommunicationIds_5: 402 | switchLocalCommunicationIds_6: 403 | switchLocalCommunicationIds_7: 404 | switchParentalControl: 0 405 | switchAllowsScreenshot: 1 406 | switchAllowsVideoCapturing: 1 407 | switchAllowsRuntimeAddOnContentInstall: 0 408 | switchDataLossConfirmation: 0 409 | switchSupportedNpadStyles: 3 410 | switchSocketConfigEnabled: 0 411 | switchTcpInitialSendBufferSize: 32 412 | switchTcpInitialReceiveBufferSize: 64 413 | switchTcpAutoSendBufferSizeMax: 256 414 | switchTcpAutoReceiveBufferSizeMax: 256 415 | switchUdpSendBufferSize: 9 416 | switchUdpReceiveBufferSize: 42 417 | switchSocketBufferEfficiency: 4 418 | switchSocketInitializeEnabled: 1 419 | switchNetworkInterfaceManagerInitializeEnabled: 1 420 | switchPlayerConnectionEnabled: 1 421 | ps4NPAgeRating: 12 422 | ps4NPTitleSecret: 423 | ps4NPTrophyPackPath: 424 | ps4ParentalLevel: 11 425 | ps4ContentID: ED1633-NPXX51362_00-0000000000000000 426 | ps4Category: 0 427 | ps4MasterVersion: 01.00 428 | ps4AppVersion: 01.00 429 | ps4AppType: 0 430 | ps4ParamSfxPath: 431 | ps4VideoOutPixelFormat: 0 432 | ps4VideoOutInitialWidth: 1920 433 | ps4VideoOutBaseModeInitialWidth: 1920 434 | ps4VideoOutReprojectionRate: 60 435 | ps4PronunciationXMLPath: 436 | ps4PronunciationSIGPath: 437 | ps4BackgroundImagePath: 438 | ps4StartupImagePath: 439 | ps4StartupImagesFolder: 440 | ps4IconImagesFolder: 441 | ps4SaveDataImagePath: 442 | ps4SdkOverride: 443 | ps4BGMPath: 444 | ps4ShareFilePath: 445 | ps4ShareOverlayImagePath: 446 | ps4PrivacyGuardImagePath: 447 | ps4NPtitleDatPath: 448 | ps4RemotePlayKeyAssignment: -1 449 | ps4RemotePlayKeyMappingDir: 450 | ps4PlayTogetherPlayerCount: 0 451 | ps4EnterButtonAssignment: 1 452 | ps4ApplicationParam1: 0 453 | ps4ApplicationParam2: 0 454 | ps4ApplicationParam3: 0 455 | ps4ApplicationParam4: 0 456 | ps4DownloadDataSize: 0 457 | ps4GarlicHeapSize: 2048 458 | ps4ProGarlicHeapSize: 2560 459 | ps4Passcode: frAQBc8Wsa1xVPfvJcrgRYwTiizs2trQ 460 | ps4pnSessions: 1 461 | ps4pnPresence: 1 462 | ps4pnFriends: 1 463 | ps4pnGameCustomData: 1 464 | playerPrefsSupport: 0 465 | restrictedAudioUsageRights: 0 466 | ps4UseResolutionFallback: 0 467 | ps4ReprojectionSupport: 0 468 | ps4UseAudio3dBackend: 0 469 | ps4SocialScreenEnabled: 0 470 | ps4ScriptOptimizationLevel: 0 471 | ps4Audio3dVirtualSpeakerCount: 14 472 | ps4attribCpuUsage: 0 473 | ps4PatchPkgPath: 474 | ps4PatchLatestPkgPath: 475 | ps4PatchChangeinfoPath: 476 | ps4PatchDayOne: 0 477 | ps4attribUserManagement: 0 478 | ps4attribMoveSupport: 0 479 | ps4attrib3DSupport: 0 480 | ps4attribShareSupport: 0 481 | ps4attribExclusiveVR: 0 482 | ps4disableAutoHideSplash: 0 483 | ps4videoRecordingFeaturesUsed: 0 484 | ps4contentSearchFeaturesUsed: 0 485 | ps4attribEyeToEyeDistanceSettingVR: 0 486 | ps4IncludedModules: [] 487 | monoEnv: 488 | psp2Splashimage: {fileID: 0} 489 | psp2NPTrophyPackPath: 490 | psp2NPSupportGBMorGJP: 0 491 | psp2NPAgeRating: 12 492 | psp2NPTitleDatPath: 493 | psp2NPCommsID: 494 | psp2NPCommunicationsID: 495 | psp2NPCommsPassphrase: 496 | psp2NPCommsSig: 497 | psp2ParamSfxPath: 498 | psp2ManualPath: 499 | psp2LiveAreaGatePath: 500 | psp2LiveAreaBackroundPath: 501 | psp2LiveAreaPath: 502 | psp2LiveAreaTrialPath: 503 | psp2PatchChangeInfoPath: 504 | psp2PatchOriginalPackage: 505 | psp2PackagePassword: F69AzBlax3CF3EDNhm3soLBPh71Yexui 506 | psp2KeystoneFile: 507 | psp2MemoryExpansionMode: 0 508 | psp2DRMType: 0 509 | psp2StorageType: 0 510 | psp2MediaCapacity: 0 511 | psp2DLCConfigPath: 512 | psp2ThumbnailPath: 513 | psp2BackgroundPath: 514 | psp2SoundPath: 515 | psp2TrophyCommId: 516 | psp2TrophyPackagePath: 517 | psp2PackagedResourcesPath: 518 | psp2SaveDataQuota: 10240 519 | psp2ParentalLevel: 1 520 | psp2ShortTitle: Not Set 521 | psp2ContentID: IV0000-ABCD12345_00-0123456789ABCDEF 522 | psp2Category: 0 523 | psp2MasterVersion: 01.00 524 | psp2AppVersion: 01.00 525 | psp2TVBootMode: 0 526 | psp2EnterButtonAssignment: 2 527 | psp2TVDisableEmu: 0 528 | psp2AllowTwitterDialog: 1 529 | psp2Upgradable: 0 530 | psp2HealthWarning: 0 531 | psp2UseLibLocation: 0 532 | psp2InfoBarOnStartup: 0 533 | psp2InfoBarColor: 0 534 | psp2ScriptOptimizationLevel: 0 535 | psmSplashimage: {fileID: 0} 536 | splashScreenBackgroundSourceLandscape: {fileID: 0} 537 | splashScreenBackgroundSourcePortrait: {fileID: 0} 538 | spritePackerPolicy: 539 | webGLMemorySize: 256 540 | webGLExceptionSupport: 1 541 | webGLNameFilesAsHashes: 0 542 | webGLDataCaching: 0 543 | webGLDebugSymbols: 0 544 | webGLEmscriptenArgs: 545 | webGLModulesDirectory: 546 | webGLTemplate: APPLICATION:Default 547 | webGLAnalyzeBuildSize: 0 548 | webGLUseEmbeddedResources: 0 549 | webGLUseWasm: 0 550 | webGLCompressionFormat: 1 551 | scriptingDefineSymbols: {} 552 | platformArchitecture: {} 553 | scriptingBackend: {} 554 | incrementalIl2cppBuild: {} 555 | additionalIl2CppArgs: 556 | scriptingRuntimeVersion: 0 557 | apiCompatibilityLevelPerPlatform: {} 558 | m_RenderingPath: 1 559 | m_MobileRenderingPath: 1 560 | metroPackageName: UNN 561 | metroPackageVersion: 562 | metroCertificatePath: 563 | metroCertificatePassword: 564 | metroCertificateSubject: 565 | metroCertificateIssuer: 566 | metroCertificateNotAfter: 0000000000000000 567 | metroApplicationDescription: UNN 568 | wsaImages: {} 569 | metroTileShortName: 570 | metroCommandLineArgsFile: 571 | metroTileShowName: 0 572 | metroMediumTileShowName: 0 573 | metroLargeTileShowName: 0 574 | metroWideTileShowName: 0 575 | metroDefaultTileSize: 1 576 | metroTileForegroundText: 2 577 | metroTileBackgroundColor: {r: 0.13333334, g: 0.17254902, b: 0.21568628, a: 0} 578 | metroSplashScreenBackgroundColor: {r: 0.12941177, g: 0.17254902, b: 0.21568628, 579 | a: 1} 580 | metroSplashScreenUseBackgroundColor: 0 581 | platformCapabilities: {} 582 | metroFTAName: 583 | metroFTAFileTypes: [] 584 | metroProtocolName: 585 | metroCompilationOverrides: 1 586 | tizenProductDescription: 587 | tizenProductURL: 588 | tizenSigningProfileName: 589 | tizenGPSPermissions: 0 590 | tizenMicrophonePermissions: 0 591 | tizenDeploymentTarget: 592 | tizenDeploymentTargetType: -1 593 | tizenMinOSVersion: 1 594 | n3dsUseExtSaveData: 0 595 | n3dsCompressStaticMem: 1 596 | n3dsExtSaveDataNumber: 0x12345 597 | n3dsStackSize: 131072 598 | n3dsTargetPlatform: 2 599 | n3dsRegion: 7 600 | n3dsMediaSize: 0 601 | n3dsLogoStyle: 3 602 | n3dsTitle: GameName 603 | n3dsProductCode: 604 | n3dsApplicationId: 0xFF3FF 605 | XboxOneProductId: 606 | XboxOneUpdateKey: 607 | XboxOneSandboxId: 608 | XboxOneContentId: 609 | XboxOneTitleId: 610 | XboxOneSCId: 611 | XboxOneGameOsOverridePath: 612 | XboxOnePackagingOverridePath: 613 | XboxOneAppManifestOverridePath: 614 | XboxOnePackageEncryption: 0 615 | XboxOnePackageUpdateGranularity: 2 616 | XboxOneDescription: 617 | XboxOneLanguage: 618 | - enus 619 | XboxOneCapability: [] 620 | XboxOneGameRating: {} 621 | XboxOneIsContentPackage: 0 622 | XboxOneEnableGPUVariability: 0 623 | XboxOneSockets: {} 624 | XboxOneSplashScreen: {fileID: 0} 625 | XboxOneAllowedProductIds: [] 626 | XboxOnePersistentLocalStorageSize: 0 627 | xboxOneScriptCompiler: 0 628 | vrEditorSettings: 629 | daydream: 630 | daydreamIconForeground: {fileID: 0} 631 | daydreamIconBackground: {fileID: 0} 632 | cloudServicesEnabled: {} 633 | facebookSdkVersion: 7.9.4 634 | apiCompatibilityLevel: 2 635 | cloudProjectId: f1acc171-c0b4-4d20-b0d6-48f01b4ed688 636 | projectName: UNN 637 | organizationId: masatatsu-nakamura 638 | cloudEnabled: 0 639 | enableNativePlatformBackendsForNewInputSystem: 0 640 | disableOldInputManagerSupport: 0 641 | -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2017.3.1f1 2 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!47 &1 4 | QualitySettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 5 7 | m_CurrentQuality: 5 8 | m_QualitySettings: 9 | - serializedVersion: 2 10 | name: Very Low 11 | pixelLightCount: 0 12 | shadows: 0 13 | shadowResolution: 0 14 | shadowProjection: 1 15 | shadowCascades: 1 16 | shadowDistance: 15 17 | shadowNearPlaneOffset: 3 18 | shadowCascade2Split: 0.33333334 19 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 20 | shadowmaskMode: 0 21 | blendWeights: 1 22 | textureQuality: 1 23 | anisotropicTextures: 0 24 | antiAliasing: 0 25 | softParticles: 0 26 | softVegetation: 0 27 | realtimeReflectionProbes: 0 28 | billboardsFaceCameraPosition: 0 29 | vSyncCount: 0 30 | lodBias: 0.3 31 | maximumLODLevel: 0 32 | particleRaycastBudget: 4 33 | asyncUploadTimeSlice: 2 34 | asyncUploadBufferSize: 4 35 | resolutionScalingFixedDPIFactor: 1 36 | excludedTargetPlatforms: [] 37 | - serializedVersion: 2 38 | name: Low 39 | pixelLightCount: 0 40 | shadows: 0 41 | shadowResolution: 0 42 | shadowProjection: 1 43 | shadowCascades: 1 44 | shadowDistance: 20 45 | shadowNearPlaneOffset: 3 46 | shadowCascade2Split: 0.33333334 47 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 48 | shadowmaskMode: 0 49 | blendWeights: 2 50 | textureQuality: 0 51 | anisotropicTextures: 0 52 | antiAliasing: 0 53 | softParticles: 0 54 | softVegetation: 0 55 | realtimeReflectionProbes: 0 56 | billboardsFaceCameraPosition: 0 57 | vSyncCount: 0 58 | lodBias: 0.4 59 | maximumLODLevel: 0 60 | particleRaycastBudget: 16 61 | asyncUploadTimeSlice: 2 62 | asyncUploadBufferSize: 4 63 | resolutionScalingFixedDPIFactor: 1 64 | excludedTargetPlatforms: [] 65 | - serializedVersion: 2 66 | name: Medium 67 | pixelLightCount: 1 68 | shadows: 1 69 | shadowResolution: 0 70 | shadowProjection: 1 71 | shadowCascades: 1 72 | shadowDistance: 20 73 | shadowNearPlaneOffset: 3 74 | shadowCascade2Split: 0.33333334 75 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 76 | shadowmaskMode: 0 77 | blendWeights: 2 78 | textureQuality: 0 79 | anisotropicTextures: 1 80 | antiAliasing: 0 81 | softParticles: 0 82 | softVegetation: 0 83 | realtimeReflectionProbes: 0 84 | billboardsFaceCameraPosition: 0 85 | vSyncCount: 1 86 | lodBias: 0.7 87 | maximumLODLevel: 0 88 | particleRaycastBudget: 64 89 | asyncUploadTimeSlice: 2 90 | asyncUploadBufferSize: 4 91 | resolutionScalingFixedDPIFactor: 1 92 | excludedTargetPlatforms: [] 93 | - serializedVersion: 2 94 | name: High 95 | pixelLightCount: 2 96 | shadows: 2 97 | shadowResolution: 1 98 | shadowProjection: 1 99 | shadowCascades: 2 100 | shadowDistance: 40 101 | shadowNearPlaneOffset: 3 102 | shadowCascade2Split: 0.33333334 103 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 104 | shadowmaskMode: 1 105 | blendWeights: 2 106 | textureQuality: 0 107 | anisotropicTextures: 1 108 | antiAliasing: 0 109 | softParticles: 0 110 | softVegetation: 1 111 | realtimeReflectionProbes: 1 112 | billboardsFaceCameraPosition: 1 113 | vSyncCount: 1 114 | lodBias: 1 115 | maximumLODLevel: 0 116 | particleRaycastBudget: 256 117 | asyncUploadTimeSlice: 2 118 | asyncUploadBufferSize: 4 119 | resolutionScalingFixedDPIFactor: 1 120 | excludedTargetPlatforms: [] 121 | - serializedVersion: 2 122 | name: Very High 123 | pixelLightCount: 3 124 | shadows: 2 125 | shadowResolution: 2 126 | shadowProjection: 1 127 | shadowCascades: 2 128 | shadowDistance: 70 129 | shadowNearPlaneOffset: 3 130 | shadowCascade2Split: 0.33333334 131 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 132 | shadowmaskMode: 1 133 | blendWeights: 4 134 | textureQuality: 0 135 | anisotropicTextures: 2 136 | antiAliasing: 2 137 | softParticles: 1 138 | softVegetation: 1 139 | realtimeReflectionProbes: 1 140 | billboardsFaceCameraPosition: 1 141 | vSyncCount: 1 142 | lodBias: 1.5 143 | maximumLODLevel: 0 144 | particleRaycastBudget: 1024 145 | asyncUploadTimeSlice: 2 146 | asyncUploadBufferSize: 4 147 | resolutionScalingFixedDPIFactor: 1 148 | excludedTargetPlatforms: [] 149 | - serializedVersion: 2 150 | name: Ultra 151 | pixelLightCount: 4 152 | shadows: 2 153 | shadowResolution: 2 154 | shadowProjection: 1 155 | shadowCascades: 4 156 | shadowDistance: 150 157 | shadowNearPlaneOffset: 3 158 | shadowCascade2Split: 0.33333334 159 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 160 | shadowmaskMode: 1 161 | blendWeights: 4 162 | textureQuality: 0 163 | anisotropicTextures: 2 164 | antiAliasing: 2 165 | softParticles: 1 166 | softVegetation: 1 167 | realtimeReflectionProbes: 1 168 | billboardsFaceCameraPosition: 1 169 | vSyncCount: 1 170 | lodBias: 2 171 | maximumLODLevel: 0 172 | particleRaycastBudget: 4096 173 | asyncUploadTimeSlice: 2 174 | asyncUploadBufferSize: 4 175 | resolutionScalingFixedDPIFactor: 1 176 | excludedTargetPlatforms: [] 177 | m_PerPlatformDefaultQuality: 178 | Android: 2 179 | Nintendo 3DS: 5 180 | Nintendo Switch: 5 181 | PS4: 5 182 | PSM: 5 183 | PSP2: 2 184 | Standalone: 5 185 | Tizen: 2 186 | WebGL: 3 187 | WiiU: 5 188 | Windows Store Apps: 5 189 | XboxOne: 5 190 | iPhone: 2 191 | tvOS: 2 192 | -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 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 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.33333334 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | m_Enabled: 0 7 | m_TestMode: 0 8 | m_TestEventUrl: 9 | m_TestConfigUrl: 10 | m_TestInitMode: 0 11 | CrashReportingSettings: 12 | m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes 13 | m_NativeEventUrl: https://perf-events.cloud.unity3d.com/symbolicate 14 | m_Enabled: 0 15 | m_CaptureEditorExceptions: 1 16 | UnityPurchasingSettings: 17 | m_Enabled: 0 18 | m_TestMode: 0 19 | UnityAnalyticsSettings: 20 | m_Enabled: 1 21 | m_InitializeOnStartup: 1 22 | m_TestMode: 0 23 | m_TestEventUrl: 24 | m_TestConfigUrl: 25 | UnityAdsSettings: 26 | m_Enabled: 0 27 | m_InitializeOnStartup: 1 28 | m_TestMode: 0 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | UNN (Unity Neural Network) 2 | ===================== 3 | 4 | GPU-based neural network implmentation for Unity. 5 | 6 | ![MNIST](https://raw.githubusercontent.com/mattatz/UNN/master/Captures/MNIST.gif) 7 | 8 | ## Usage 9 | 10 | (To be written) 11 | 12 | ### Build the model 13 | 14 | ### Train the model 15 | 16 | ### Evaluate the model 17 | 18 | ### Run the model 19 | 20 | ### Save & Restore 21 | 22 | ## Resourses 23 | 24 | - oreilly-japan/deep-learning-from-scratch - https://github.com/oreilly-japan/deep-learning-from-scratch 25 | - mattatz/GPUMatrixMultiplicationTest - https://github.com/mattatz/GPUMatrixMultiplicationTest 26 | - THE MNIST DATABASE - http://yann.lecun.com/exdb/mnist/ 27 | - Reading the MNIST Data Set with C# - https://jamesmccaffrey.wordpress.com/2013/11/23/reading-the-mnist-data-set-with-c/ 28 | 29 | ## Compatibility 30 | 31 | tested on Unity 2017.3.1f, Windows 10 (GTX 1060). 32 | -------------------------------------------------------------------------------- /UnityPackageManager/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | } 4 | } 5 | --------------------------------------------------------------------------------