Exemplo n.º 1
0
        public override InternalArray Forward(InternalArray ar)
        {
            results.Clear();
            results.Add(new LogInfo(null, ar.Clone(), "input"));
            ar.QIntData = new short[ar.Data.Length];
            for (int i = 0; i < ar.QIntData.Length; i++)
            {
                ar.QIntData[i] = (short)(ar.Data[i] * 256);
            }
            ar.Data = null;
            ar      = conv1.Forward(ar);
            results.Add(new LogInfo(conv1, ar.Clone()));


            ar = bn1.Forward(ar);
            results.Add(new LogInfo(bn1, ar.Clone()));

            ar = Relu(ar);
            results.Add(new LogInfo(null, ar.Clone(), "relu1"));

            ar = pool1.Forward(ar);
            results.Add(new LogInfo(pool1, ar.Clone()));


            ar = conv2.Forward(ar);
            results.Add(new LogInfo(conv2, ar.Clone(), "BinConv2D conv2"));


            ar = bn2.Forward(ar);
            results.Add(new LogInfo(bn2, ar.Clone()));


            ar = Relu(ar);
            results.Add(new LogInfo(null, ar.Clone(), "relu2"));
            ar = pool2.Forward(ar);
            results.Add(new LogInfo(pool2, ar.Clone()));

            var ar2 = new InternalArray(new int[] { 1, 4 * 4 * 50 });

            if (ar.QIntData != null)
            {
                ar2.QIntData = new short[ar2.Data.Length];
                ar2.Data     = null;
                for (int i = 0; i < ar.QIntData.Length; i++)
                {
                    ar2.QIntData[i] = ar.QIntData[i];
                }
            }
            else
            {
                for (int i = 0; i < ar.Data.Length; i++)
                {
                    ar2.Data[i] = ar.Data[i];
                }
            }

            results.Add(new LogInfo(null, ar2.Clone(), "view"));


            ar = fc1.Forward(ar2);
            results.Add(new LogInfo(fc1, ar.Clone(), "BinLinear fc1"));

            ar = bn3.Forward(ar);
            results.Add(new LogInfo(bn3, ar.Clone()));

            ar = Relu(ar);
            results.Add(new LogInfo(null, ar.Clone(), "relu3"));
            //input 500
            ar = fc2.Forward(ar);
            results.Add(new LogInfo(fc2, ar.Clone()));


            //output 10
            //output size should be [1,10]
            results.Add(new LogInfo(null, ar.Clone(), "output"));
            return(ar);
        }
Exemplo n.º 2
0
        public override InternalArray Forward(InternalArray ar)
        {
            results.Clear();
            results.Add(new LogInfo(null, ar.Clone(), "input"));
            ar = conv1.Forward(ar);
            results.Add(new LogInfo(conv1, ar.Clone()));


            ar = bn1.Forward(ar);
            results.Add(new LogInfo(bn1, ar.Clone()));

            ar = Relu(ar);
            results.Add(new LogInfo(null, ar.Clone(), "relu1"));

            ar = pool1.Forward(ar);
            results.Add(new LogInfo(pool1, ar.Clone()));

            if (ar.Data.Any(z => float.IsInfinity(z) || float.IsNaN(z)))
            {
            }
            ar = conv2.Forward(ar);
            results.Add(new LogInfo(conv2, ar.Clone(), "BinConv2D conv2"));


            if (ar.Data.Any(z => float.IsInfinity(z) || float.IsNaN(z)))
            {
            }
            ar = bn2.Forward(ar);
            results.Add(new LogInfo(bn2, ar.Clone()));


            ar = Relu(ar);
            results.Add(new LogInfo(null, ar.Clone(), "relu2"));
            ar = pool2.Forward(ar);
            results.Add(new LogInfo(pool2, ar.Clone()));

            var ar2 = new InternalArray(new int[] { 1, 4 * 4 * 50 });

            for (int i = 0; i < ar.Data.Length; i++)
            {
                ar2.Data[i] = ar.Data[i];
            }
            results.Add(new LogInfo(null, ar.Clone(), "view"));


            ar = fc1.Forward(ar2);
            results.Add(new LogInfo(fc1, ar.Clone(), "BinLinear fc1"));

            ar = bn3.Forward(ar);
            results.Add(new LogInfo(bn3, ar.Clone()));

            ar = Relu(ar);
            results.Add(new LogInfo(null, ar.Clone(), "relu3"));
            //input 500
            ar = fc2.Forward(ar);
            results.Add(new LogInfo(fc1, ar.Clone()));


            //output 10
            //output size should be [1,10]
            results.Add(new LogInfo(null, ar.Clone(), "output"));
            return(ar);
        }