protected override float Outputs(OutputVector result, Floatarray v) { result.Clear(); if (v.Rank() == 1) { v.Reshape(csize, csize, 0, 0); } // byte array input StdInput vinput = new StdInput(v); byte[] buffer = vinput.GetDataBuffer(); // char classifier compute outputs if (CharClass.AsciiTarget) { // net output 0..~ (lower - winner) CharClass.ComputeOutputs(buffer, vinput.Length, vinput.Height, vinput.Width, result); } else { // net output 0..1; (higher - winner) CharClass.ComputeOutputsRaw(buffer, vinput.Length, vinput.Height, vinput.Width, result); } // junk classifier if (PGetb("junk") && !DisableJunk && !JunkClass.IsEmpty) { OutputVector jv = new OutputVector(); if (JunkClass.AsciiTarget) { JunkClass.ComputeOutputs(buffer, vinput.Length, vinput.Height, vinput.Width, jv); result[jc()] = jv.Value(1); } else { //result.Normalize(); result.Normalize2(); JunkClass.ComputeOutputsRaw(buffer, vinput.Length, vinput.Height, vinput.Width, jv); jv.Normalize2(); for (int i = 0; i < result.nKeys(); i++) { result.Values[i] *= jv.Value(0); } result[jc()] = jv.Value(1); } } return(0.0f); }
private void DoTestRecognize(LenetClassifier classifier) { OutputVector ov = new OutputVector(); Floatarray v = new Floatarray(); Bytearray ba = new Bytearray(1, 1); ImgIo.read_image_gray(ba, testPngFileName); NarrayUtil.Sub(255, ba); v.Copy(ba); v /= 255.0; classifier.XOutputs(ov, v); Console.WriteLine("Featured output class '{0}', score '{1}'", (char)ov.Key(ov.BestIndex), ov.Value(ov.BestIndex)); }
protected override float Outputs(OutputVector result, Floatarray v) { result.Clear(); if (v.Rank() == 1) v.Reshape(csize, csize, 0, 0); // byte array input StdInput vinput = new StdInput(v); byte[] buffer = vinput.GetDataBuffer(); // char classifier compute outputs if (CharClass.AsciiTarget) // net output 0..~ (lower - winner) CharClass.ComputeOutputs(buffer, vinput.Length, vinput.Height, vinput.Width, result); else // net output 0..1; (higher - winner) CharClass.ComputeOutputsRaw(buffer, vinput.Length, vinput.Height, vinput.Width, result); // junk classifier if (PGetb("junk") && !DisableJunk && !JunkClass.IsEmpty) { OutputVector jv = new OutputVector(); if (JunkClass.AsciiTarget) { JunkClass.ComputeOutputs(buffer, vinput.Length, vinput.Height, vinput.Width, jv); result[jc()] = jv.Value(1); } else { //result.Normalize(); result.Normalize2(); JunkClass.ComputeOutputsRaw(buffer, vinput.Length, vinput.Height, vinput.Width, jv); jv.Normalize2(); for (int i = 0; i < result.nKeys(); i++) result.Values[i] *= jv.Value(0); result[jc()] = jv.Value(1); } } return 0.0f; }