Exemplo n.º 1
0
    private void Awake()
    {
        Application.runInBackground = true;
        _rng = new Rng(1234);

        DataManager.Load();

        _tex            = new Texture2D(DataManager.Train.Rows, DataManager.Train.Cols, TextureFormat.ARGB32, false, true); // Lol
        _tex.filterMode = FilterMode.Point;

        var def = new NetDefinition(
            DataManager.Train.ImgDims,
            new LayerDefinition(30, LayerType.Deterministic, ActivationType.Sigmoid),
            new LayerDefinition(10, LayerType.Deterministic, ActivationType.Sigmoid));

        _net            = NetBuilder.Build(def);
        _gradientBucket = NetBuilder.Build(def);

        NetUtils.RandomGaussian(_net, ref _rng);

        _renderer.SetTarget(_net);

        // const int testImg = 7291;
        // _label = Mnist.Test.Labels[testImg];
        // Mnist.ToTexture(Mnist.Test, testImg, _tex);
    }
Exemplo n.º 2
0
    private static void AddGradients(NNClassic.Network net, NNClassic.Network gradients)
    {
        UnityEngine.Profiling.Profiler.BeginSample("AddGradients");

        var lCount = gradients.Layers.Count;

        for (int l = 1; l < lCount; l++)
        {
            var dCdZGradients = gradients.Layers[l].DCDZ;
            var dCdZNet       = net.Layers[l].DCDZ;
            var nCount        = gradients.Layers[l].NeuronCount;

            for (int n = 0; n < nCount; n++)
            {
                dCdZGradients[n] += dCdZNet[n];

                var dCdWGradients = gradients.Layers[l].DCDW;
                var dCdWNet       = net.Layers[l].DCDW;
                var wCount        = gradients.Layers[l - 1].NeuronCount;

                for (int w = 0; w < wCount; w++)
                {
                    dCdWGradients[n, w] += dCdWNet[n, w];
                }
            }
        }

        UnityEngine.Profiling.Profiler.EndSample();
    }
Exemplo n.º 3
0
 private static void CopyInputs(NNClassic.Network net, int imgIdx)
 {
     for (int p = 0; p < DataManager.Test.ImgDims; p++)
     {
         net.Input[p] = DataManager.Test.Images[imgIdx, p];
     }
 }
Exemplo n.º 4
0
    private static void ZeroGradients(NNClassic.Network bucket)
    {
        UnityEngine.Profiling.Profiler.BeginSample("Zero");

        for (int l = 1; l < bucket.Layers.Count; l++)
        {
            for (int n = 0; n < bucket.Layers[l].NeuronCount; n++)
            {
                bucket.Layers[l].DCDZ[n] = 0f;

                for (int w = 0; w < bucket.Layers[l - 1].NeuronCount; w++)
                {
                    bucket.Layers[l].DCDW[n, w] = 0f;
                }
            }
        }

        UnityEngine.Profiling.Profiler.EndSample();
    }