public void Redraw( ) { var img = input.Get2DImageFrom4DArray(0, 0); Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height); var gr = Graphics.FromImage(bmp); gr.Clear(Color.White); int ww = int.Parse(textBox1.Text); for (int i = 0; i < img.Shape[0]; i++) { for (int j = 0; j < img.Shape[1]; j++) { gr.DrawRectangle(Pens.Black, j * ww, i * ww, ww, ww); gr.DrawString(Math.Round(img.Get2D(i, j), 3) + "", new Font("Consolas", 10), Brushes.Black, j * ww, i * ww); } } pictureBox1.Image = bmp; MaxPool2d pool = new MaxPool2d(2, 2); var res = pool.Forward(input); var img2 = res.Get2DImageFrom4DArray(0, 0); Bitmap bmp2 = new Bitmap(pictureBox2.Width, pictureBox2.Height); var gr2 = Graphics.FromImage(bmp2); gr2.Clear(Color.White); for (int i = 0; i < img2.Shape[0]; i++) { for (int j = 0; j < img2.Shape[1]; j++) { gr2.DrawRectangle(Pens.Black, j * ww, i * ww, ww, ww); gr2.DrawString(Math.Round(img2.Get2D(i, j), 3) + "", new Font("Consolas", 10), Brushes.Black, j * ww, i * ww); } } pictureBox2.Image = bmp2; }
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); }
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); }