예제 #1
0
            public static LabelWithConfidence LabelWithConfidence(NeuralNet model, NNInstrumentation instr, double[] datum, bool crop)
            {
                Vector <double> datum_v = DenseVector.OfArray(datum);

                if (crop)
                {
                    datum_v = model.CropMaybe(datum_v);
                }

                double[] outs = model.EvaluateNNConcretePostCrop(datum_v, instr);

//                Console.WriteLine("Outs = {0}", DenseVector.OfArray(outs));


                Tuple <double, int> max    = UMath.Max(outs);
                Tuple <double, int> secmax = UMath.MaxExcluding(max.Item2, outs);

                UMath.SoftMax(outs);

                var result = new LabelWithConfidence
                {
                    datum              = datum,
                    actualLabel        = max.Item2,
                    secBestLabel       = secmax.Item2,
                    softMaxValue       = outs[max.Item2],
                    diffFromSecondBest = Math.Abs(outs[max.Item2] - outs[secmax.Item2])
                };

                return(result);
            }
예제 #2
0
            public static double[] RunWithSoftmax(NeuralNet model, double[] datum, bool crop)
            {
                Vector <double> datum_v = DenseVector.OfArray(datum);

                if (crop)
                {
                    datum_v = model.CropMaybe(datum_v);
                }

                double[] outs = model.EvaluateNNConcretePostCrop(datum_v, null);

                UMath.SoftMax(outs);

                return(outs);
            }